[svn-commits] file: branch group/dns_pjsip r433991 - in /team/group/dns_pjsip: include/aste...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Apr 4 10:40:14 CDT 2015


Author: file
Date: Sat Apr  4 10:40:03 2015
New Revision: 433991

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=433991
Log:
Replace the internal PJSIP resolver implementation at a lower level.

Unfortunately there's no easy way to cover all cases where resolution occurs
without a change to PJSIP. I've made such a change which allows the resolution
process to be taken over by an external implementation. This change has been
sent to Teluu for inclusion and I will work with them to ensure it is.

As a result though... no changes are required elsewhere to perform resolution
using the new DNS work. It's just happening.

This also fixes a bug with resolution of an IP address where the addresses
structure was filled with garbage.

Modified:
    team/group/dns_pjsip/include/asterisk/res_pjsip.h
    team/group/dns_pjsip/res/res_pjsip.c
    team/group/dns_pjsip/res/res_pjsip/include/res_pjsip_private.h
    team/group/dns_pjsip/res/res_pjsip/pjsip_resolver.c
    team/group/dns_pjsip/res/res_pjsip_session.c

Modified: team/group/dns_pjsip/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_pjsip/include/asterisk/res_pjsip.h?view=diff&rev=433991&r1=433990&r2=433991
==============================================================================
--- team/group/dns_pjsip/include/asterisk/res_pjsip.h (original)
+++ team/group/dns_pjsip/include/asterisk/res_pjsip.h Sat Apr  4 10:40:03 2015
@@ -1954,26 +1954,4 @@
  */
 unsigned int ast_sip_get_keep_alive_interval(void);
 
-/*!
- * \brief Callback which is invoked upon completion of the resolution process
- *
- * \param data The user specific data
- * \param addresses The resolved target addresses
- */
-typedef void (*ast_sip_resolve_callback)(void *data, pjsip_server_addresses *addresses);
-
-/*!
- * \brief Perform DNS resolution according to RFC3263 and invoke a callback upon completion
- *
- * \param target The target we are looking up
- * \param callback The callback to invoke upon completion
- * \param data User specific data (must be ao2 allocated)
- *
- * \retval 0 success
- * \retval -1 failure
- *
- * \note This function bumps the reference count of user data, it does not steal
- */
-int ast_sip_resolve(const pjsip_host_info *target, ast_sip_resolve_callback callback, void *user_data);
-
 #endif /* _RES_PJSIP_H */

Modified: team/group/dns_pjsip/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_pjsip/res/res_pjsip.c?view=diff&rev=433991&r1=433990&r2=433991
==============================================================================
--- team/group/dns_pjsip/res/res_pjsip.c (original)
+++ team/group/dns_pjsip/res/res_pjsip.c Sat Apr  4 10:40:03 2015
@@ -2978,73 +2978,17 @@
 	return 0;
 }
 
-struct sip_send_request_data {
-	struct pjsip_dialog *dlg;
-	struct ast_sip_endpoint *endpoint;
-	void *token;
-	void (*callback)(void *token, pjsip_event *e);
-	pjsip_tx_data *tdata;
-};
-
-static void sip_send_request_data_destroy(void *data)
-{
-	struct sip_send_request_data *send_request_data = data;
-
-	if (send_request_data->dlg) {
-		pjsip_dlg_dec_session(send_request_data->dlg, &supplement_module);
-	}
-
-	ao2_cleanup(send_request_data->endpoint);
-	ao2_cleanup(send_request_data->token);
-}
-
-static void sip_send_request_resolve_cb(void *data, pjsip_server_addresses *addresses)
-{
-	struct sip_send_request_data *send_request_data = data;
-
-	memcpy(&(send_request_data->tdata->dest_info.addr), addresses, sizeof(send_request_data->tdata->dest_info.addr));
-
-	if (send_request_data->dlg) {
-		send_in_dialog_request(send_request_data->tdata, send_request_data->dlg);
-	} else {
-		send_out_of_dialog_request(send_request_data->tdata, send_request_data->endpoint,
-			send_request_data->token, send_request_data->callback);
-	}
-}
-
 int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg,
 	struct ast_sip_endpoint *endpoint, void *token,
 	void (*callback)(void *token, pjsip_event *e))
 {
-	pjsip_host_info target;
-	struct sip_send_request_data *send_request_data;
-	int res;
-
 	ast_assert(tdata->msg->type == PJSIP_REQUEST_MSG);
 
-	if (pjsip_get_request_dest(tdata, &target) != PJ_SUCCESS) {
-		return -1;
-	}
-
-	send_request_data = ao2_alloc_options(sizeof(*send_request_data), sip_send_request_data_destroy,
-		AO2_ALLOC_OPT_LOCK_NOLOCK);
-	if (!send_request_data) {
-		return -1;
-	}
-
 	if (dlg) {
-		send_request_data->dlg = dlg;
-		pjsip_dlg_inc_session(dlg, &supplement_module);
-	}
-	send_request_data->endpoint = ao2_bump(endpoint);
-	send_request_data->token = ao2_bump(token);
-	send_request_data->callback = callback;
-	send_request_data->tdata = tdata;
-
-	res = ast_sip_resolve(&target, sip_send_request_resolve_cb, send_request_data);
-	ao2_ref(send_request_data, -1);
-
-	return res;
+		return send_in_dialog_request(tdata, dlg);
+	} else {
+		return send_out_of_dialog_request(tdata, endpoint, token, callback);
+	}
 }
 
 int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy)
@@ -3431,7 +3375,6 @@
 {
 	ast_res_pjsip_reload_configuration();
 	ast_res_pjsip_init_options_handling(1);
-	ast_sip_initialize_dns();
 	return 0;
 }
 
@@ -3498,7 +3441,7 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	ast_sip_initialize_dns();
+	ast_sip_initialize_resolver();
 
 	pjsip_tsx_layer_init_module(ast_pjsip_endpoint);
 	pjsip_ua_init_module(ast_pjsip_endpoint, NULL);

Modified: team/group/dns_pjsip/res/res_pjsip/include/res_pjsip_private.h
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_pjsip/res/res_pjsip/include/res_pjsip_private.h?view=diff&rev=433991&r1=433990&r2=433991
==============================================================================
--- team/group/dns_pjsip/res/res_pjsip/include/res_pjsip_private.h (original)
+++ team/group/dns_pjsip/res/res_pjsip/include/res_pjsip_private.h Sat Apr  4 10:40:03 2015
@@ -232,6 +232,12 @@
 
 /*!
  * \internal
+ * \brief Initialize our own resolver support
+ */
+void ast_sip_initialize_resolver(void);
+
+/*!
+ * \internal
  * \brief Initialize global configuration
  *
  * \retval 0 Success

Modified: team/group/dns_pjsip/res/res_pjsip/pjsip_resolver.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_pjsip/res/res_pjsip/pjsip_resolver.c?view=diff&rev=433991&r1=433990&r2=433991
==============================================================================
--- team/group/dns_pjsip/res/res_pjsip/pjsip_resolver.c (original)
+++ team/group/dns_pjsip/res/res_pjsip/pjsip_resolver.c Sat Apr  4 10:40:03 2015
@@ -52,9 +52,9 @@
 	/*! \brief Active queries */
 	struct ast_dns_query_set *queries;
 	/*! \brief Callback to invoke upon completion */
-	ast_sip_resolve_callback callback;
+	pjsip_resolver_callback *callback;
 	/*! \brief User provided data */
-	void *user_data;
+	void *token;
 };
 
 /*! \brief Destructor for resolution data */
@@ -65,7 +65,6 @@
 	AST_VECTOR_FREE(&resolve->resolving);
 	AST_VECTOR_FREE(&resolve->resolved);
 	ao2_cleanup(resolve->queries);
-	ao2_cleanup(resolve->user_data);
 }
 
 /*! \brief Perform resolution but keep transport and port information */
@@ -126,7 +125,7 @@
 	}
 
 	ast_debug(2, "[%p] Invoking user callback with '%d' addresses\n", resolve, addresses.count);
-	resolve->callback(resolve->user_data, &addresses);
+	resolve->callback(PJ_SUCCESS, resolve->token, &addresses);
 
 	ao2_ref(resolve, -1);
 
@@ -232,7 +231,8 @@
 	return 0;
 }
 
-int ast_sip_resolve(const pjsip_host_info *target, ast_sip_resolve_callback callback, void *user_data)
+static void sip_resolve(pjsip_resolver_t *resolver, pj_pool_t *pool, const pjsip_host_info *target,
+	void *token, pjsip_resolver_callback *cb)
 {
 	int ip_addr_ver;
 	pjsip_transport_type_e type = target->type;
@@ -269,7 +269,10 @@
 
 	/* If it's already an address call the callback immediately */
 	if (ip_addr_ver) {
-		pjsip_server_addresses addresses;
+		pjsip_server_addresses addresses = {
+			.entry[0].type = PJSIP_TRANSPORT_UDP,
+			.count = 1,
+		};
 
 		if (ip_addr_ver == 4) {
 			pj_sockaddr_init(pj_AF_INET(), &addresses.entry[0].addr, NULL, 0);
@@ -277,28 +280,29 @@
 		} else {
 			pj_sockaddr_init(pj_AF_INET6(), &addresses.entry[0].addr, NULL, 0);
 			pj_inet_pton(pj_AF_INET6(), &target->addr.host, &addresses.entry[0].addr.ipv6.sin6_addr);
-			type = (pjsip_transport_type_e)((int)type + PJSIP_TRANSPORT_IPV6);
-		}
-		addresses.count++;
+			addresses.entry[0].type = (pjsip_transport_type_e)((int)addresses.entry[0].type + PJSIP_TRANSPORT_IPV6);
+		}
 
 		ast_debug(2, "Target '%s' is an IP address, skipping resolution\n", host);
 
-		callback(user_data, &addresses);
-
-		return 0;
+		cb(PJ_SUCCESS, token, &addresses);
+
+		return;
 	}
 
 	resolve = ao2_alloc_options(sizeof(*resolve), sip_resolve_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
 	if (!resolve) {
-		return -1;
-	}
-
-	resolve->callback = callback;
-	resolve->user_data = ao2_bump(user_data);
+		cb(PJ_EINVAL, token, NULL);
+		return;
+	}
+
+	resolve->callback = cb;
+	resolve->token = token;
 
 	if (AST_VECTOR_INIT(&resolve->resolving, 2) || AST_VECTOR_INIT(&resolve->resolved, 2)) {
 		ao2_ref(resolve, -1);
-		return -1;
+		cb(PJ_EINVAL, token, NULL);
+		return;
 	}
 
 	ast_debug(2, "[%p] Created resolution tracking for target '%s'\n", resolve, host);
@@ -324,13 +328,24 @@
 
 	if (res) {
 		ao2_ref(resolve, -1);
-		return -1;
+		cb(PJ_EINVAL, token, NULL);
+		return;
 	}
 
 	ast_debug(2, "[%p] Starting initial resolution using parallel queries for target '%s'\n", resolve, host);
 	ast_dns_query_set_resolve_async(resolve->queries, sip_resolve_callback, resolve);
 
 	ao2_ref(resolve, -1);
-
+}
+
+static int sip_replace_resolver(void *data)
+{
+	pjsip_endpt_set_resolver_implementation(ast_sip_get_pjsip_endpoint(), sip_resolve);
 	return 0;
+}
+
+void ast_sip_initialize_resolver(void)
+{
+	/* Replace the existing PJSIP resolver with our own implementation */
+	ast_sip_push_task_synchronous(NULL, sip_replace_resolver, NULL);
 }

Modified: team/group/dns_pjsip/res/res_pjsip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/dns_pjsip/res/res_pjsip_session.c?view=diff&rev=433991&r1=433990&r2=433991
==============================================================================
--- team/group/dns_pjsip/res/res_pjsip_session.c (original)
+++ team/group/dns_pjsip/res/res_pjsip_session.c Sat Apr  4 10:40:03 2015
@@ -1050,15 +1050,10 @@
 	.on_rx_request = session_reinvite_on_rx_request,
 };
 
-static void sip_session_resolve_cb(void *data, pjsip_server_addresses *addresses)
-{
-}
-
 void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip_tx_data *tdata,
 		ast_sip_session_response_cb on_response)
 {
 	pjsip_inv_session *inv_session = session->inv_session;
-	pjsip_host_info target;
 
 	if (inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
 		/* Don't try to do anything with a hung-up call */
@@ -1082,9 +1077,6 @@
 	}
 
 	handle_outgoing_request(session, tdata);
-
-	pjsip_get_request_dest(tdata, &target);
-	ast_sip_resolve(&target, sip_session_resolve_cb, NULL);
 
 	pjsip_inv_send_msg(session->inv_session, tdata);
 	return;




More information about the svn-commits mailing list