[asterisk-commits] mmichelson: branch mmichelson/trunk-digiumphones r363686 - in /team/mmichelso...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 25 14:12:35 CDT 2012


Author: mmichelson
Date: Wed Apr 25 14:12:33 2012
New Revision: 363686

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=363686
Log:
Remove AST_CONTROL_CUSTOM frame type and add a public function to send a SIP INFO request.

In 1.8-digiumphones and 10-digiumphones, an AST_CONTROL_CUSTOM frame type was created in order
to send a channel driver-specific indication. In addition, functions were added in order to
encode SIP INFO data into a frame and decode data from a frame.

The code in question had an odd mix of generic behavior and very SIP-specific behavior. Since this
was added with the primary purpose of being able to send SIP INFO requests to a phone, it seemed
like the generic elements should be eliminated in preference of a more direct method of sending
a SIP INFO.

With this change, a new file, sip_api.h has been added with a single function, ast_sipinfo_send().
The function is defined in chan_sip.c. This means that any modules that use ast_sipinfo_send() will
need to load after chan_sip.so has been loaded.

Several files have been removed since they are no longer useful.


Added:
    team/mmichelson/trunk-digiumphones/channels/chan_sip.exports.in   (with props)
    team/mmichelson/trunk-digiumphones/include/asterisk/sip_api.h   (with props)
Removed:
    team/mmichelson/trunk-digiumphones/include/asterisk/custom_control_frame.h
    team/mmichelson/trunk-digiumphones/main/custom_control_frame.c
    team/mmichelson/trunk-digiumphones/tests/test_custom_control.c
Modified:
    team/mmichelson/trunk-digiumphones/channels/chan_sip.c
    team/mmichelson/trunk-digiumphones/funcs/func_frame_trace.c
    team/mmichelson/trunk-digiumphones/include/asterisk/frame.h
    team/mmichelson/trunk-digiumphones/main/channel.c

Modified: team/mmichelson/trunk-digiumphones/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/channels/chan_sip.c?view=diff&rev=363686&r1=363685&r2=363686
==============================================================================
--- team/mmichelson/trunk-digiumphones/channels/chan_sip.c (original)
+++ team/mmichelson/trunk-digiumphones/channels/chan_sip.c Wed Apr 25 14:12:33 2012
@@ -230,6 +230,7 @@
    affect the speed of the program at all. They can be considered to be documentation.
 */
 /* #define  REF_DEBUG 1 */
+
 #include "asterisk/lock.h"
 #include "asterisk/config.h"
 #include "asterisk/module.h"
@@ -278,7 +279,7 @@
 #include "sip/include/dialog.h"
 #include "sip/include/dialplan_functions.h"
 #include "sip/include/security_events.h"
-
+#include "asterisk/sip_api.h"
 
 /*** DOCUMENTATION
 	<application name="SIPDtmfMode" language="en_US">
@@ -6944,34 +6945,37 @@
 	return 0;
 }
 
-/* XXX Candidate for moving into its own file */
-/*!
- * \brief Sends AST_CUSTOM_FRAME of type sip info.
- *
- * \note pvt is expected to be locked before entering this function.
- */
-static int sip_handle_custom_info(struct sip_pvt *pvt, struct ast_custom_payload *pl)
-{
-	struct ast_variable *headers = NULL;
-	char *content_type = NULL;
-	char *content = NULL;
-	char *useragent_filter = NULL;
+int ast_sipinfo_send(
+		struct ast_channel *chan,
+		struct ast_variable *headers,
+		const char *content_type,
+		const char *content,
+		const char *useragent_filter)
+{
+	struct sip_pvt *p;
 	struct ast_variable *var;
 	struct sip_request req;
 	int res = -1;
 
-	if (ast_custom_payload_sipinfo_decode(pl, &headers, &content_type, &content, &useragent_filter)) {
-		goto custom_info_cleanup;
-	}
+	ast_channel_lock(chan);
+
+	if (ast_channel_tech(chan) != &sip_tech) {
+		ast_log(LOG_WARNING, "Attempted to send a custom INFO on a non-SIP channel %s\n", ast_channel_name(chan));
+		ast_channel_unlock(chan);
+		return res;
+	}
+
+	p = ast_channel_tech_pvt(chan);
+	sip_pvt_lock(p);
 
 	if (!(ast_strlen_zero(useragent_filter))) {
-		int match = (strstr(pvt->useragent, useragent_filter)) ? 1 : 0;
+		int match = (strstr(p->useragent, useragent_filter)) ? 1 : 0;
 		if (!match) {
-			goto custom_info_cleanup;
-		}
-	}
-
-	reqprep(&req, pvt, SIP_INFO, 0, 1);
+			goto cleanup;
+		}
+	}
+
+	reqprep(&req, p, SIP_INFO, 0, 1);
 	for (var = headers; var; var = var->next) {
 		add_header(&req, var->name, var->value);
 	}
@@ -6980,18 +6984,13 @@
 		add_content(&req, content);
 	}
 
-	res = send_request(pvt, &req, XMIT_RELIABLE, pvt->ocseq);
-
-custom_info_cleanup:
-
-	ast_free(content);
-	ast_free(content_type);
-	ast_free(useragent_filter);
-	ast_variables_destroy(headers);
-
+	res = send_request(p, &req, XMIT_RELIABLE, p->ocseq);
+
+cleanup:
+	sip_pvt_unlock(p);
+	ast_channel_unlock(chan);
 	return res;
 }
-
 /*! \brief Play indication to user
  * With SIP a lot of indications is sent as messages, letting the device play
    the indication - busy signal, congestion etc
@@ -7120,11 +7119,6 @@
 		break;
 	case AST_CONTROL_REDIRECTING:
 		update_redirecting(p, data, datalen);
-		break;
-	case AST_CONTROL_CUSTOM:
-		if (datalen && ast_custom_payload_type((struct ast_custom_payload *) data) == AST_CUSTOM_SIP_INFO) {
-			sip_handle_custom_info(p, (struct ast_custom_payload *) data);
-		}
 		break;
 	case AST_CONTROL_AOC:
 		{
@@ -30779,7 +30773,6 @@
 static int sip_sendcustominfo(struct ast_channel *chan, const char *data)
 {
 	char *info_data, *useragent;
-	struct ast_custom_payload *pl = NULL;
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "You must provide data to be sent\n");
@@ -30789,13 +30782,10 @@
 	useragent = ast_strdupa(data);
 	info_data = strsep(&useragent, ",");
 
-	if (!(pl = ast_custom_payload_sipinfo_encode(NULL, "text/plain", info_data, useragent))) {
+	if (ast_sipinfo_send(chan, NULL, "text/plain", info_data, useragent)) {
 		ast_log(LOG_WARNING, "Failed to create payload for custom SIP INFO\n");
 		return 0;
 	}
-
-	ast_indicate_data(chan, AST_CONTROL_CUSTOM, pl, ast_custom_payload_len(pl));
-	ast_free(pl);
 	return 0;
 }
 #endif
@@ -32005,7 +31995,7 @@
 	return 0;
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Session Initiation Protocol (SIP)",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Session Initiation Protocol (SIP)",
 		.load = load_module,
 		.unload = unload_module,
 		.reload = reload,

Added: team/mmichelson/trunk-digiumphones/channels/chan_sip.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/channels/chan_sip.exports.in?view=auto&rev=363686
==============================================================================
--- team/mmichelson/trunk-digiumphones/channels/chan_sip.exports.in (added)
+++ team/mmichelson/trunk-digiumphones/channels/chan_sip.exports.in Wed Apr 25 14:12:33 2012
@@ -1,0 +1,6 @@
+{
+	global:
+		LINKER_SYMBOL_PREFIX*ast_sipinfo_send;
+	local:
+		*;
+};

Propchange: team/mmichelson/trunk-digiumphones/channels/chan_sip.exports.in
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mmichelson/trunk-digiumphones/channels/chan_sip.exports.in
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mmichelson/trunk-digiumphones/channels/chan_sip.exports.in
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/mmichelson/trunk-digiumphones/funcs/func_frame_trace.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/funcs/func_frame_trace.c?view=diff&rev=363686&r1=363685&r2=363686
==============================================================================
--- team/mmichelson/trunk-digiumphones/funcs/func_frame_trace.c (original)
+++ team/mmichelson/trunk-digiumphones/funcs/func_frame_trace.c Wed Apr 25 14:12:33 2012
@@ -321,9 +321,6 @@
 		case AST_CONTROL_END_OF_Q:
 			ast_verbose("SubClass: END_OF_Q\n");
 			break;
-		case AST_CONTROL_CUSTOM:
-			ast_verbose("Subclass: Custom");
-			break;
 		case AST_CONTROL_UPDATE_RTP_PEER:
 			ast_verbose("SubClass: UPDATE_RTP_PEER\n");
 			break;

Modified: team/mmichelson/trunk-digiumphones/include/asterisk/frame.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/include/asterisk/frame.h?view=diff&rev=363686&r1=363685&r2=363686
==============================================================================
--- team/mmichelson/trunk-digiumphones/include/asterisk/frame.h (original)
+++ team/mmichelson/trunk-digiumphones/include/asterisk/frame.h Wed Apr 25 14:12:33 2012
@@ -263,8 +263,6 @@
 	AST_CONTROL_READ_ACTION = 27,	/*!< Tell ast_read to take a specific action */
 	AST_CONTROL_AOC = 28,			/*!< Advice of Charge with encoded generic AOC payload */
 	AST_CONTROL_END_OF_Q = 29,		/*!< Indicate that this position was the end of the channel queue for a softhangup. */
-	/* XXX WTF? Why 200? XXX */
-	AST_CONTROL_CUSTOM = 200,		/*!< Indicate a custom channel driver specific payload.  Look in custom_control_frame.h for how to define and use this frame. */
 	AST_CONTROL_INCOMPLETE = 30,	/*!< Indication that the extension dialed is incomplete */
 	AST_CONTROL_MCID = 31,			/*!< Indicate that the caller is being malicious. */
 	AST_CONTROL_UPDATE_RTP_PEER = 32, /*!< Interrupt the bridge and have it update the peer */

Added: team/mmichelson/trunk-digiumphones/include/asterisk/sip_api.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/include/asterisk/sip_api.h?view=auto&rev=363686
==============================================================================
--- team/mmichelson/trunk-digiumphones/include/asterisk/sip_api.h (added)
+++ team/mmichelson/trunk-digiumphones/include/asterisk/sip_api.h Wed Apr 25 14:12:33 2012
@@ -1,0 +1,51 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifndef __ASTERISK_SIP_H
+#define __ASTERISK_SIP_H
+
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+#include "asterisk/optional_api.h"
+#include "asterisk/config.h"
+
+/*!
+ * \brief Send a customized SIP INFO request
+ *
+ * \param headers The headers to add to the INFO request
+ * \param content_type The content type header to add
+ * \param conten The body of the INFO request
+ * \param useragent_filter If non-NULL, only send the INFO if the
+ * recipient's User-Agent contains useragent_filter as a substring
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+int ast_sipinfo_send(struct ast_channel *chan,
+		struct ast_variable *headers,
+		const char *content_type,
+		const char *content,
+		const char *useragent_filter);
+
+#if defined(__cplusplus) || defined(c_plusplus)
+}
+#endif
+
+#endif /* __ASTERISK_SIP_H */

Propchange: team/mmichelson/trunk-digiumphones/include/asterisk/sip_api.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mmichelson/trunk-digiumphones/include/asterisk/sip_api.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mmichelson/trunk-digiumphones/include/asterisk/sip_api.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/mmichelson/trunk-digiumphones/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/main/channel.c?view=diff&rev=363686&r1=363685&r2=363686
==============================================================================
--- team/mmichelson/trunk-digiumphones/main/channel.c (original)
+++ team/mmichelson/trunk-digiumphones/main/channel.c Wed Apr 25 14:12:33 2012
@@ -4165,7 +4165,6 @@
 	case AST_CONTROL_CC:
 	case AST_CONTROL_READ_ACTION:
 	case AST_CONTROL_AOC:
-	case AST_CONTROL_CUSTOM:
 	case AST_CONTROL_END_OF_Q:
 	case AST_CONTROL_MCID:
 	case AST_CONTROL_UPDATE_RTP_PEER:
@@ -4355,7 +4354,6 @@
 	case AST_CONTROL_CC:
 	case AST_CONTROL_READ_ACTION:
 	case AST_CONTROL_AOC:
-	case AST_CONTROL_CUSTOM:
 	case AST_CONTROL_END_OF_Q:
 	case AST_CONTROL_MCID:
 	case AST_CONTROL_UPDATE_RTP_PEER:




More information about the asterisk-commits mailing list