[asterisk-addons-commits] dcb: trunk r449 - /trunk/chan_mobile.c

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Tue Sep 18 01:29:03 CDT 2007


Author: dcb
Date: Tue Sep 18 01:29:02 2007
New Revision: 449

URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=449
Log:
Changes to use AST_STANDARD_APP_ARGS fixes issue 10744

Modified:
    trunk/chan_mobile.c

Modified: trunk/chan_mobile.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/chan_mobile.c?view=diff&rev=449&r1=448&r2=449
==============================================================================
--- trunk/chan_mobile.c (original)
+++ trunk/chan_mobile.c Tue Sep 18 01:29:02 2007
@@ -67,6 +67,7 @@
 #include <asterisk/devicestate.h>
 #include <asterisk/causes.h>
 #include <asterisk/dsp.h>
+#include <asterisk/app.h>
 #include <asterisk/manager.h>
 
 #define AST_MODULE "chan_mobile"
@@ -361,23 +362,29 @@
 {
 
 	struct mbl_pvt *pvt;
-	char *args = NULL, *device = NULL, *variable = NULL;
+	char *parse;
 	int stat;
 	char status[2];
 
-	if (!data)
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(device);
+		AST_APP_ARG(variable);
+	);
+
+	if (ast_strlen_zero(data))
 		return -1;
 
-	args = ast_strdupa((char *)data);
-	device = strsep(&args, "|");
-	if (ast_strlen_zero(device))
+	parse = ast_strdupa(data);
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (ast_strlen_zero(args.device) || ast_strlen_zero(args.variable))
 		return -1;
-	variable = args;
 
 	stat = 1;
 
 	AST_LIST_TRAVERSE(&devices, pvt, entry) {
-		if (!strcmp(pvt->id, device))
+		if (!strcmp(pvt->id, args.device))
 			break;
 	}
 
@@ -389,7 +396,7 @@
 	}
 
 	sprintf(status, "%d", stat);
-	pbx_builtin_setvar_helper(ast, variable, status);
+	pbx_builtin_setvar_helper(ast, args.variable, status);
 
 	return 0;
 
@@ -399,58 +406,63 @@
 {
 
 	struct mbl_pvt *pvt;
-	char *args = NULL, *device = NULL, *dest = NULL, *message = NULL;
-
-	if (!data)
+	char *parse;
+
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(device);
+		AST_APP_ARG(dest);
+		AST_APP_ARG(message);
+	);
+
+	if (ast_strlen_zero(data))
 		return -1;
 
-	args = ast_strdupa((char *)data);
-	device = strsep(&args, "|");
-	if (!ast_strlen_zero(device)) {
-		dest = strsep(&args, "|");
-		if (!ast_strlen_zero(dest)) {
-			message = args;
-			if (ast_strlen_zero(message)) {
-				ast_log(LOG_ERROR,"NULL Message to be sent -- SMS will not be sent.\n");
-				return -1;
-			}
-		} else {
-			ast_log(LOG_ERROR,"NULL destination for message -- SMS will not be sent.\n");
-			return -1;
-		}
-		
-	} else {
+	parse = ast_strdupa(data);
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (ast_strlen_zero(args.device)) {
 		ast_log(LOG_ERROR,"NULL device for message -- SMS will not be sent.\n");
 		return -1;
 	}
-	
+
+	if (ast_strlen_zero(args.dest)) {
+		ast_log(LOG_ERROR,"NULL destination for message -- SMS will not be sent.\n");
+		return -1;
+	}
+
+	if (ast_strlen_zero(args.message)) {
+		ast_log(LOG_ERROR,"NULL Message to be sent -- SMS will not be sent.\n");
+		return -1;
+	}
+
 	AST_LIST_TRAVERSE(&devices, pvt, entry) {
-		if (!strcmp(pvt->id, device))
+		if (!strcmp(pvt->id, args.device))
 			break;
 	}
 
 	if (!pvt) {
-		ast_log(LOG_ERROR,"Bluetooth device %s wasn't found in the list -- SMS will not be sent.\n",device);
+		ast_log(LOG_ERROR,"Bluetooth device %s wasn't found in the list -- SMS will not be sent.\n", args.device);
 		return -1;
 	}
 	
 	if (!pvt->connected) {
-		ast_log(LOG_ERROR,"Bluetooth device %s wasn't connected -- SMS will not be sent.\n",device);
+		ast_log(LOG_ERROR,"Bluetooth device %s wasn't connected -- SMS will not be sent.\n", args.device);
 		return -1;
 	}
 	
 	if (!pvt->has_sms) {
-		ast_log(LOG_ERROR,"Bluetooth device %s doesn't handle SMS -- SMS will not be sent.\n",device);
+		ast_log(LOG_ERROR,"Bluetooth device %s doesn't handle SMS -- SMS will not be sent.\n", args.device);
 		return -1;
 	}
 	
 	if (pvt->state != MBL_STATE_IDLE) {
-		ast_log(LOG_ERROR,"Bluetooth device %s isn't IDLE -- SMS will not be sent.\n",device);
+		ast_log(LOG_ERROR,"Bluetooth device %s isn't IDLE -- SMS will not be sent.\n", args.device);
 		return -1;
 	}
 	
-	ast_copy_string(pvt->dial_number, dest, sizeof(pvt->dial_number));
-	ast_copy_string(pvt->sms_txt, message, sizeof(pvt->sms_txt));
+	ast_copy_string(pvt->dial_number, args.dest, sizeof(pvt->dial_number));
+	ast_copy_string(pvt->sms_txt, args.message, sizeof(pvt->sms_txt));
 	pvt->state = MBL_STATE_OUTSMS;
 
 	return 0;




More information about the asterisk-addons-commits mailing list