[svn-commits] jrose: trunk r415659 - in /trunk: ./ main/message.c res/res_pjsip_notify.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 10 11:06:16 CDT 2014


Author: jrose
Date: Tue Jun 10 11:06:12 2014
New Revision: 415659

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=415659
Log:
PJSIP: PJSIPNotify - Strip content-length headers and add documentation

Documentation for how to add custom headers/content to notifies created
with the PJSIPNotify manager action was a little sparse and it also
wasn't vetting application of Content-length headers like its chan_sip
equivalent was (so two Content-length headers could be applied... and
PJSIP determines the content length anyway, so it just opens people up
for error). This patch also flips the variable order so that the
variables are interpreted in the same order as they are put in the AMI
action.

Review: https://reviewboard.asterisk.org/r/3587/
........

Merged revisions 415658 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/main/message.c
    trunk/res/res_pjsip_notify.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/main/message.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/message.c?view=diff&rev=415659&r1=415658&r2=415659
==============================================================================
--- trunk/main/message.c (original)
+++ trunk/main/message.c Tue Jun 10 11:06:12 2014
@@ -1217,7 +1217,7 @@
 		return -1;
 	}
 
-	data = astman_get_variables(m);
+	data = astman_get_variables_order(m, ORDER_NATURAL);
 	for (vars = data; vars; vars = vars->next) {
 		ast_msg_set_var_outbound(msg, vars->name, vars->value);
 	}

Modified: trunk/res/res_pjsip_notify.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_notify.c?view=diff&rev=415659&r1=415658&r2=415659
==============================================================================
--- trunk/res/res_pjsip_notify.c (original)
+++ trunk/res/res_pjsip_notify.c Tue Jun 10 11:06:12 2014
@@ -44,10 +44,17 @@
 			<parameter name="Endpoint" required="true">
 				<para>The endpoint to which to send the NOTIFY.</para>
 			</parameter>
+			<parameter name="Variable" required="true">
+				<para>Appends variables as headers/content to the NOTIFY. If the variable is
+				named <literal>Content</literal>, then the value will compose the body
+				of the message if another variable sets <literal>Content-Type</literal>.
+				<replaceable>name</replaceable>=<replaceable>value</replaceable></para>
+			</parameter>
 		</syntax>
 		<description>
-			<para>Send a NOTIFY to an endpoint.</para>
-			<para>Parameters will be placed into the notify as SIP headers.</para>
+			<para>Sends a NOTIFY to an endpoint.</para>
+			<para>All parameters for this event must be specified in the body of this request
+			via multiple <literal>Variable: name=value</literal> sequences.</para>
 		</description>
 	</manager>
 	<configInfo name="res_pjsip_notify" language="en_US">
@@ -452,6 +459,10 @@
 	struct ast_variable *i;
 
 	for (i = vars; i; i = i->next) {
+		if (!strcasecmp(i->name, "Content-Length")) {
+			ast_log(LOG_NOTICE, "It is not necessary to specify Content-Length, ignoring.\n");
+			continue;
+		}
 		build_notify(tdata, i->name, i->value,
 			     &content_type, &content);
 	}
@@ -699,10 +710,11 @@
 static int manager_notify(struct mansession *s, const struct message *m)
 {
 	const char *endpoint_name = astman_get_header(m, "Endpoint");
-	struct ast_variable *vars = astman_get_variables(m);
+	struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);
 
 	if (ast_strlen_zero(endpoint_name)) {
 		astman_send_error(s, m, "PJSIPNotify requires an endpoint name");
+		ast_variables_destroy(vars);
 		return 0;
 	}
 
@@ -710,22 +722,29 @@
 		endpoint_name += 4;
 	}
 
+	if (!strncasecmp(endpoint_name, "pjsip/", 6)) {
+		endpoint_name += 6;
+	}
+
 	switch (push_notify(endpoint_name, vars, notify_ami_data_create)) {
 	case INVALID_ENDPOINT:
+		ast_variables_destroy(vars);
 		astman_send_error_va(s, m, "Unable to retrieve endpoint %s\n",
 			endpoint_name);
-		return 0;
+		break;
 	case ALLOC_ERROR:
+		ast_variables_destroy(vars);
 		astman_send_error(s, m, "Unable to allocate NOTIFY task data\n");
-		return 0;
+		break;
 	case TASK_PUSH_ERROR:
+		/* Don't need to destroy vars since it is handled by cleanup in push_notify */
 		astman_send_error(s, m, "Unable to push NOTIFY task\n");
-		return 0;
-	default:
 		break;
-	}
-
-	astman_send_ack(s, m, "NOTIFY sent");
+	case SUCCESS:
+		astman_send_ack(s, m, "NOTIFY sent");
+		break;
+	}
+
 	return 0;
 }
 




More information about the svn-commits mailing list