[asterisk-commits] kharwell: branch 12 r404663 - in /branches/12: ./ channels/ configs/ include/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 2 13:06:36 CST 2014


Author: kharwell
Date: Thu Jan  2 13:06:28 2014
New Revision: 404663

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404663
Log:
res_pjsip: add 'set_var' support on endpoints

Added a new 'set_var' option for ast_sip_endpoint(s).  For each variable
specified that variable gets set upon creation of a pjsip channel involving
the endpoint.

(closes issue ASTERISK-22868)
Reported by: Joshua Colp
Review: https://reviewboard.asterisk.org/r/3095/

Modified:
    branches/12/CHANGES
    branches/12/channels/chan_pjsip.c
    branches/12/configs/pjsip.conf.sample
    branches/12/include/asterisk/res_pjsip.h
    branches/12/res/res_pjsip.c
    branches/12/res/res_pjsip/pjsip_configuration.c

Modified: branches/12/CHANGES
URL: http://svnview.digium.com/svn/asterisk/branches/12/CHANGES?view=diff&rev=404663&r1=404662&r2=404663
==============================================================================
--- branches/12/CHANGES (original)
+++ branches/12/CHANGES Thu Jan  2 13:06:28 2014
@@ -1116,6 +1116,9 @@
    various SIP functionality in Asterisk. The majority of configuration for
    these modules is performed in pjsip.conf. Other modules may use their
    own configuration files.
+
+ * Added 'set_var' option for an endpoint. For each variable specified that
+   variable gets set upon creation of a channel involving the endpoint.
 
 res_rtp_asterisk
 ------------------

Modified: branches/12/channels/chan_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_pjsip.c?view=diff&rev=404663&r1=404662&r2=404663
==============================================================================
--- branches/12/channels/chan_pjsip.c (original)
+++ branches/12/channels/chan_pjsip.c Thu Jan  2 13:06:28 2014
@@ -346,6 +346,7 @@
 	struct ast_format fmt;
 	RAII_VAR(struct chan_pjsip_pvt *, pvt, NULL, ao2_cleanup);
 	struct ast_sip_channel_pvt *channel;
+	struct ast_variable *var;
 
 	if (!(pvt = ao2_alloc(sizeof(*pvt), chan_pjsip_pvt_dtor))) {
 		return NULL;
@@ -364,6 +365,11 @@
 		return NULL;
 	}
 
+	for (var = session->endpoint->channel_vars; var; var = var->next) {
+		char buf[512];
+		pbx_builtin_setvar_helper(chan, var->name, ast_get_encoded_str(
+						  var->value, buf, sizeof(buf)));
+	}
 
 	ast_channel_stage_snapshot(chan);
 

Modified: branches/12/configs/pjsip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/branches/12/configs/pjsip.conf.sample?view=diff&rev=404663&r1=404662&r2=404663
==============================================================================
--- branches/12/configs/pjsip.conf.sample (original)
+++ branches/12/configs/pjsip.conf.sample Thu Jan  2 13:06:28 2014
@@ -539,7 +539,8 @@
                 ; other party or both (default: "")
 ;srtp_tag_32=no ; Determines whether 32 byte tags should be used instead of 80
                 ; byte tags (default: "no")
-
+;set_var=       ; Variable set on a channel involving the endpoint. For multiple
+		; channel variables specify multiple 'set_var'(s)
 
 ;==========================AUTH SECTION OPTIONS=========================
 ;[auth]

Modified: branches/12/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/res_pjsip.h?view=diff&rev=404663&r1=404662&r2=404663
==============================================================================
--- branches/12/include/asterisk/res_pjsip.h (original)
+++ branches/12/include/asterisk/res_pjsip.h Thu Jan  2 13:06:28 2014
@@ -592,6 +592,8 @@
 	unsigned int allowtransfer;
 	/*! Method used when handling redirects */
 	enum ast_sip_session_redirect redirect_method;
+	/*! Variables set on channel creation */
+	struct ast_variable *channel_vars;
 };
 
 /*!

Modified: branches/12/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip.c?view=diff&rev=404663&r1=404662&r2=404663
==============================================================================
--- branches/12/res/res_pjsip.c (original)
+++ branches/12/res/res_pjsip.c Thu Jan  2 13:06:28 2014
@@ -663,6 +663,14 @@
 					<description><para>
 						This option only applies if <replaceable>media_encryption</replaceable> is
 						set to <literal>sdes</literal> or <literal>dtls</literal>.
+					</para></description>
+				</configOption>
+				<configOption name="set_var">
+					<synopsis>Variable set on a channel involving the endpoint.</synopsis>
+					<description><para>
+					        When a new channel is created using the endpoint set the specified
+						variable(s) on that channel. For multiple channel variables specify
+						multiple 'set_var'(s).
 					</para></description>
 				</configOption>
 			</configObject>

Modified: branches/12/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_configuration.c?view=diff&rev=404663&r1=404662&r2=404663
==============================================================================
--- branches/12/res/res_pjsip/pjsip_configuration.c (original)
+++ branches/12/res/res_pjsip/pjsip_configuration.c Thu Jan  2 13:06:28 2014
@@ -758,6 +758,43 @@
 		*buf = ast_strdup(ast_t38_ec_modes_map[
 					  endpoint->media.t38.error_correction]);
 	}
+	return 0;
+}
+
+static int set_var_handler(const struct aco_option *opt,
+	struct ast_variable *var, void *obj)
+{
+	struct ast_sip_endpoint *endpoint = obj;
+	struct ast_variable *new_var;
+	char *name = ast_strdupa(var->value), *val = strchr(name, '=');
+
+	if (!val) {
+		return -1;
+	}
+
+	*val++ = '\0';
+	if (!(new_var = ast_variable_new(name, val, ""))) {
+		return -1;
+	}
+
+	new_var->next = endpoint->channel_vars;
+	endpoint->channel_vars = new_var;
+
+	return 0;
+}
+
+static int set_var_to_str(const void *obj, const intptr_t *args, char **buf)
+{
+	struct ast_str *str = ast_str_create(MAX_OBJECT_FIELD);
+	const struct ast_sip_endpoint *endpoint = obj;
+	struct ast_variable *var;
+
+	for (var = endpoint->channel_vars; var; var = var->next) {
+		ast_str_append(&str, 0, "%s=%s,", var->name, var->value);
+	}
+
+	*buf = ast_strdup(ast_str_truncate(str, -1));
+	ast_free(str);
 	return 0;
 }
 
@@ -1483,6 +1520,7 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_setup", "", dtls_handler, dtlssetup_to_str, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "srtp_tag_32", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.srtp_tag_32));
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "redirect_method", "user", redirect_handler, NULL, 0, 0);
+	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "set_var", "", set_var_handler, set_var_to_str, 0, 0);
 
 	if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");
@@ -1588,6 +1626,7 @@
 	endpoint->pickup.named_callgroups = ast_unref_namedgroups(endpoint->pickup.named_callgroups);
 	endpoint->pickup.named_pickupgroups = ast_unref_namedgroups(endpoint->pickup.named_pickupgroups);
 	ao2_cleanup(endpoint->persistent);
+	ast_variables_destroy(endpoint->channel_vars);
 }
 
 static int init_subscription_configuration(struct ast_sip_endpoint_subscription_configuration *subscription)




More information about the asterisk-commits mailing list