[svn-commits] russell: branch russell/iax2_osp r61699 - in /team/russell/iax2_osp: channels...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Apr 20 13:46:26 MST 2007


Author: russell
Date: Fri Apr 20 15:46:26 2007
New Revision: 61699

URL: http://svn.digium.com/view/asterisk?view=rev&rev=61699
Log:
Remove the IAXCHANINFO function and put the ability to get and set the osptoken
in the func_channel callback for chan_iax2.

Modified:
    team/russell/iax2_osp/channels/chan_iax2.c
    team/russell/iax2_osp/funcs/func_channel.c

Modified: team/russell/iax2_osp/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax2_osp/channels/chan_iax2.c?view=diff&rev=61699&r1=61698&r2=61699
==============================================================================
--- team/russell/iax2_osp/channels/chan_iax2.c (original)
+++ team/russell/iax2_osp/channels/chan_iax2.c Fri Apr 20 15:46:26 2007
@@ -853,6 +853,9 @@
 static void destroy_user(struct iax2_user *user);
 static void prune_peers(void);
 
+static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen);
+static int acf_channel_write(struct ast_channel *chan, const char *function, char *data, const char *value);
+
 static const struct ast_channel_tech iax2_tech = {
 	.type = "IAX2",
 	.description = tdesc,
@@ -876,6 +879,8 @@
 	.bridge = iax2_bridge,
 	.transfer = iax2_transfer,
 	.fixup = iax2_fixup,
+	.func_channel_read = acf_channel_read,
+	.func_channel_write = acf_channel_write,
 };
 
 static void insert_idle_thread(struct iax2_thread *thread)
@@ -3018,7 +3023,7 @@
 	}
 
 	/* Check if there is an OSP token set by IAXCHANINFO function */
-	osp_token_ptr = pbx_builtin_getvar_helper(c, "~IAX2~osptoken");
+	osp_token_ptr = iaxs[callno]->osptoken;
 	if (!ast_strlen_zero(osp_token_ptr)) {
 		if ((osp_token_length = strlen(osp_token_ptr)) <= IAX_MAX_OSPTOKEN_SIZE) {
 			osp_block_index = 0;
@@ -3031,13 +3036,10 @@
 				osp_token_ptr += osp_block_length;
 				osp_token_length -= osp_block_length;
 			} 
-		} else {
+		} else
 			ast_log(LOG_WARNING, "OSP token is too long\n");
-		}
-	} else {
-		if (option_debug && iaxdebug)
-			ast_log(LOG_DEBUG, "OSP token is undefined\n");
-	}
+	} else if (option_debug && iaxdebug)
+		ast_log(LOG_DEBUG, "OSP token is undefined\n");
 
 	/* send the command using the appropriate socket for this peer */
 	iaxs[callno]->sockfd = cai.sockfd;
@@ -9885,69 +9887,61 @@
 	"\n"
 };
 
-/*! \brief ${IAXCHANINFO()} Dialplan function - reads iax channel data */
-static int function_iaxchaninfo_read(struct ast_channel *chan, const char *cmd, char *varname, char *buf, size_t len)
-{
-	unsigned short callno;
-	struct chan_iax2_pvt* pvt;
-
-	*buf = 0;
-
-	if (!varname) {
-		ast_log(LOG_WARNING, "This function requires a parameter name.\n");
+static int acf_channel_write(struct ast_channel *chan, const char *function, char *args, const char *value)
+{
+	struct chan_iax2_pvt *pvt;
+	unsigned int callno;
+	int res = 0;
+
+	if (!chan || chan->tech != &iax2_tech) {
+		ast_log(LOG_ERROR, "This function requires a valid IAX2 channel\n");
 		return -1;
 	}
 
-	ast_channel_lock(chan);
-	if (chan->tech != &iax2_tech) {
-		ast_log(LOG_WARNING, "This function can only be used on IAX channels.\n");
-		ast_channel_unlock(chan);
+	callno = PTR_TO_CALLNO(chan->tech_pvt);
+	ast_mutex_lock(&iaxsl[callno]);
+	if (!(pvt = iaxs[callno])) {
+		ast_mutex_unlock(&iaxsl[callno]);
 		return -1;
 	}
 
-	callno = PTR_TO_CALLNO(chan->tech_pvt);	
-	pvt = iaxs[callno];
-
-	if (!strcasecmp(varname, "osptoken")) {
-		ast_copy_string(buf, pvt->osptoken, len);
-	} else {
-		ast_channel_unlock(chan);
+	if (!strcasecmp(args, "osptoken"))
+		ast_string_field_set(pvt, osptoken, value);
+	else
+		res = -1;
+
+	ast_mutex_unlock(&iaxsl[callno]);
+
+	return res;
+}
+
+static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *args, char *buf, size_t buflen)
+{
+	struct chan_iax2_pvt *pvt;
+	unsigned int callno;
+	int res = 0;
+
+	if (!chan || chan->tech != &iax2_tech) {
+		ast_log(LOG_ERROR, "This function requires a valid IAX2 channel\n");
 		return -1;
 	}
-	ast_channel_unlock(chan);
-
-	return 0;
-}
-
-static int function_iaxchaninfo_write(struct ast_channel *chan, const char *cmd, char *varname, const char *value)
-{
-	char tmp[IAX_MAX_OSPBUFF_SIZE];
-
-	if (!varname) {
-		ast_log(LOG_WARNING, "This function requires a parameter name.\n");
+
+	callno = PTR_TO_CALLNO(chan->tech_pvt);
+	ast_mutex_lock(&iaxsl[callno]);
+	if (!(pvt = iaxs[callno])) {
+		ast_mutex_unlock(&iaxsl[callno]);
 		return -1;
 	}
 
-	if (!strcasecmp(varname, "osptoken")) {
-		snprintf(tmp, sizeof(tmp), "_~IAX2~%s", varname);
-		pbx_builtin_setvar_helper(chan, tmp, value);
-	} else {
-		return -1;
-	}
-
-	return 0;
-}
-
-/*! \brief Structure to declare a dialplan function: IAXCHANINFO */
-static struct ast_custom_function iaxchaninfo_function = {
-	.name = "IAXCHANINFO",
-	.synopsis = "Get/set the specified IAX parameter for the current channel",
-	.syntax = "IAXCHANINFO(item)",
-	.read = function_iaxchaninfo_read,
-	.write = function_iaxchaninfo_write,
-	.desc = "Valid items are:\n"
-	"- osptoken		The OSP token from the source or to the destination. Read and write.\n"
-};
+	if (!strcasecmp(args, "osptoken"))
+		ast_copy_string(buf, pvt->osptoken, buflen);
+	else
+		res = -1;
+
+	ast_mutex_unlock(&iaxsl[callno]);
+
+	return res;
+}
 
 /*! \brief Part of the device state notification system ---*/
 static int iax2_devicestate(void *data) 
@@ -10284,7 +10278,6 @@
 
 static int unload_module(void)
 {
-	ast_custom_function_unregister(&iaxchaninfo_function);
 	ast_custom_function_unregister(&iaxpeer_function);
 	ast_custom_function_unregister(&iaxvar_function);
 	return __unload_module();
@@ -10301,7 +10294,6 @@
 	
 	ast_custom_function_register(&iaxpeer_function);
 	ast_custom_function_register(&iaxvar_function);
-	ast_custom_function_register(&iaxchaninfo_function);
 
 	iax_set_output(iax_debug_output);
 	iax_set_error(iax_error_output);

Modified: team/russell/iax2_osp/funcs/func_channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax2_osp/funcs/func_channel.c?view=diff&rev=61699&r1=61698&r2=61699
==============================================================================
--- team/russell/iax2_osp/funcs/func_channel.c (original)
+++ team/russell/iax2_osp/funcs/func_channel.c Fri Apr 20 15:46:26 2007
@@ -182,6 +182,9 @@
 		"    rtt                   Round trip time\n"
 		"    all                   All statistics (in a form suited to logging, but not for parsing)\n"
 		"\n"
+		"chan_iax2 provides the following additional options:\n"
+		"R/W    osptoken           Get or set the OSP token information for a call\n"
+		"\n"
 		"Additional items may be available from the channel driver providing\n"
 		"the channel; see its documentation for details.\n"
 		"\n"



More information about the svn-commits mailing list