[asterisk-commits] file: branch file/pimp_sip_location r381819 - in /team/file/pimp_sip_location...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 20 08:37:11 CST 2013


Author: file
Date: Wed Feb 20 08:37:07 2013
New Revision: 381819

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381819
Log:
Resurrect request user overwriting and add a dialplan function which calls all contacts on an AOR.

Modified:
    team/file/pimp_sip_location/channels/chan_gulp.c
    team/file/pimp_sip_location/res/res_sip_session.c

Modified: team/file/pimp_sip_location/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_location/channels/chan_gulp.c?view=diff&rev=381819&r1=381818&r2=381819
==============================================================================
--- team/file/pimp_sip_location/channels/chan_gulp.c (original)
+++ team/file/pimp_sip_location/channels/chan_gulp.c Wed Feb 20 08:37:07 2013
@@ -56,6 +56,28 @@
 
 #include "asterisk/res_sip.h"
 #include "asterisk/res_sip_session.h"
+
+/*** DOCUMENTATION
+	<function name="GULP_DIAL_CONTACTS" language="en_US">
+		<synopsis>
+			Return a dial string for dialing all contacts on an AOR.
+		</synopsis>
+		<syntax>
+			<parameter name="endpoint" required="true">
+				<para>Name of the endpoint</para>
+			</parameter>
+			<parameter name="aor" required="false">
+				<para>Name of an AOR to use, if not specified the configured AORs on the endpoint are used</para>
+			</parameter>
+			<parameter name="request_user" required="false">
+				<para>Optional request user to use in the request URI</para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>Returns a properly formatted dial string for dialing all contacts on an AOR.</para>
+		</description>
+	</function>
+ ***/
 
 static const char desc[] = "Gulp SIP Channel";
 static const char channel_type[] = "Gulp";
@@ -105,6 +127,90 @@
 	.session_end = gulp_session_end,
 	.incoming_request = gulp_incoming_request,
 	.incoming_response = gulp_incoming_response,
+};
+
+/*! \brief Dialplan function for constructing a dial string for calling all contacts */
+static int gulp_dial_contacts(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
+{
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(endpoint_name);
+		AST_APP_ARG(aor_name);
+		AST_APP_ARG(request_user);
+	);
+	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+	const char *aor_name;
+	char *rest;
+	RAII_VAR(struct ast_str *, dial, NULL, ast_free_ptr);
+
+	AST_STANDARD_APP_ARGS(args, data);
+
+	if (ast_strlen_zero(args.endpoint_name)) {
+		ast_log(LOG_WARNING, "An endpoint name must be specified when using the '%s' dialplan function\n", cmd);
+		return -1;
+	} else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", args.endpoint_name))) {
+		ast_log(LOG_WARNING, "Specified endpoint '%s' was not found\n", args.endpoint_name);
+		return -1;
+	}
+
+	aor_name = S_OR(args.aor_name, endpoint->aors);
+
+	if (ast_strlen_zero(aor_name)) {
+		ast_log(LOG_WARNING, "No AOR has been provided and no AORs are configured on endpoint '%s'\n", args.endpoint_name);
+		return -1;
+	} else if (!(dial = ast_str_create(len))) {
+		ast_log(LOG_WARNING, "Could not get enough buffer space for dialing contacts\n");
+		return -1;
+	} else if (!(rest = ast_strdupa(aor_name))) {
+		ast_log(LOG_WARNING, "Could not duplicate provided AORs\n");
+		return -1;
+	}
+
+	while ((aor_name = strsep(&rest, ","))) {
+		struct ast_sip_aor *aor = ast_sip_location_retrieve_aor(aor_name);
+		struct ao2_container *contacts;
+		struct ao2_iterator it_contacts;
+		struct ast_sip_contact *contact;
+
+		if (!aor) {
+			/* If the AOR provided is not found skip it, there may be more */
+			continue;
+		} else if (!(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
+			/* No contacts are available, skip it a well */
+			ao2_cleanup(aor);
+			continue;
+		} else if (!ao2_container_count(contacts)) {
+			/* We were given a container but no contacts are in it... */
+			ao2_cleanup(contacts);
+			ao2_cleanup(aor);
+			continue;
+		}
+
+		it_contacts = ao2_iterator_init(contacts, 0);
+		for (; (contact = ao2_iterator_next(&it_contacts)); ao2_ref(contact, -1)) {
+			ast_str_append(&dial, -1, "Gulp/");
+
+			if (!ast_strlen_zero(args.request_user)) {
+				ast_str_append(&dial, -1, "%s@", args.request_user);
+			}
+			ast_str_append(&dial, -1, "%s/%s&", args.endpoint_name, contact->uri);
+		}
+		ao2_iterator_destroy(&it_contacts);
+
+		ao2_cleanup(contacts);
+		ao2_cleanup(aor);
+	}
+
+	/* Trim the '&' at the end off */
+	ast_str_truncate(dial, ast_str_strlen(dial) - 1);
+
+	ast_copy_string(buf, ast_str_buffer(dial), len);
+
+	return 0;
+}
+
+static struct ast_custom_function gulp_dial_contacts_function = {
+	.name = "GULP_DIAL_CONTACTS",
+	.read = gulp_dial_contacts,
 };
 
 /*! \brief Function called by RTP engine to get local audio RTP peer */
@@ -923,6 +1029,11 @@
 		goto end;
 	}
 
+	if (ast_custom_function_register(&gulp_dial_contacts_function)) {
+		ast_log(LOG_ERROR, "Unable to register GULP_DIAL_CONTACTS dialplan function\n");
+		goto end;
+	}
+
 	if (ast_sip_session_register_supplement(&gulp_supplement)) {
 		ast_log(LOG_ERROR, "Unable to register Gulp supplement\n");
 		goto end;
@@ -931,6 +1042,8 @@
 	return 0;
 
 end:
+	ast_custom_function_unregister(&gulp_dial_contacts_function);
+	ast_channel_unregister(&gulp_tech);
 	ast_rtp_glue_unregister(&gulp_rtp_glue);
 
 	return AST_MODULE_LOAD_FAILURE;
@@ -946,6 +1059,7 @@
 static int unload_module(void)
 {
 	ast_sip_session_unregister_supplement(&gulp_supplement);
+	ast_custom_function_unregister(&gulp_dial_contacts_function);
 	ast_channel_unregister(&gulp_tech);
 	ast_rtp_glue_unregister(&gulp_rtp_glue);
 

Modified: team/file/pimp_sip_location/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_location/res/res_sip_session.c?view=diff&rev=381819&r1=381818&r2=381819
==============================================================================
--- team/file/pimp_sip_location/res/res_sip_session.c (original)
+++ team/file/pimp_sip_location/res/res_sip_session.c Wed Feb 20 08:37:07 2013
@@ -554,14 +554,14 @@
 	return session;
 }
 
-static int sip_session_create_leg(const struct ast_sip_endpoint *endpoint, struct ast_sip_session *session, const char *uri, pjsip_timer_setting *timer)
+static int sip_session_create_leg(const struct ast_sip_endpoint *endpoint, struct ast_sip_session *session, const char *uri, pjsip_timer_setting *timer, const char *request_user)
 {
 	pjsip_dialog *dlg;
 	struct pjsip_inv_session *inv_session;
 	pjmedia_sdp_session *offer;
 	RAII_VAR(struct sip_session_leg *, leg, NULL, ao2_cleanup);
 
-	if (!(dlg = ast_sip_create_dialog(endpoint, uri, NULL))) {
+	if (!(dlg = ast_sip_create_dialog(endpoint, uri, request_user))) {
 		return -1;
 	}
 
@@ -593,7 +593,7 @@
 }
 
 /*! \brief Internal function which adds an AOR with container of contacts as outgoing legs on a session */
-static int sip_session_leg_add_aor(struct ast_sip_endpoint *endpoint, struct ast_sip_session *session, pjsip_timer_setting *timer, const char *aor_name)
+static int sip_session_leg_add_aor(struct ast_sip_endpoint *endpoint, struct ast_sip_session *session, pjsip_timer_setting *timer, const char *aor_name, const char *request_user)
 {
 	RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
 	RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
@@ -609,7 +609,7 @@
 
 	it_contacts = ao2_iterator_init(contacts, 0);
 	for (; (contact = ao2_iterator_next(&it_contacts)); ao2_ref(contact, -1)) {
-		sip_session_create_leg(endpoint, session, contact->uri, timer);
+		sip_session_create_leg(endpoint, session, contact->uri, timer, request_user);
 	}
 	ao2_iterator_destroy(&it_contacts);
 
@@ -644,8 +644,8 @@
 
 	while ((aor_name = strsep(&rest, ","))) {
 		/* If adding based on AOR fails try adding it straight up as a URI */
-		if (sip_session_leg_add_aor(endpoint, session, &timer, aor_name)) {
-			sip_session_create_leg(endpoint, session, aor_name, &timer);
+		if (sip_session_leg_add_aor(endpoint, session, &timer, aor_name, request_user)) {
+			sip_session_create_leg(endpoint, session, aor_name, &timer, request_user);
 		}
 	}
 




More information about the asterisk-commits mailing list