[asterisk-commits] russell: trunk r412102 - /trunk/res/res_monitor.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 10 20:13:06 CDT 2014


Author: russell
Date: Thu Apr 10 20:12:54 2014
New Revision: 412102

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=412102
Log:
monitor: use app options parsing helper code

This app is pretty ancient, so it was never converted to use the
option parsing helper code.  I'd like to add an option to this app
that takes an argument, and that's a pain to do when not using this
helper, so start by doing this conversion.

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

Modified:
    trunk/res/res_monitor.c

Modified: trunk/res/res_monitor.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_monitor.c?view=diff&rev=412102&r1=412101&r2=412102
==============================================================================
--- trunk/res/res_monitor.c (original)
+++ trunk/res/res_monitor.c Thu Apr 10 20:12:54 2014
@@ -639,7 +639,20 @@
 	return 0;
 }
 
- 
+enum {
+	MON_FLAG_BRIDGED =  (1 << 0),
+	MON_FLAG_MIX =      (1 << 1),
+	MON_FLAG_DROP_IN =  (1 << 2),
+	MON_FLAG_DROP_OUT = (1 << 3),
+};
+
+AST_APP_OPTIONS(monitor_opts, {
+	AST_APP_OPTION('b', MON_FLAG_BRIDGED),
+	AST_APP_OPTION('m', MON_FLAG_MIX),
+	AST_APP_OPTION('i', MON_FLAG_DROP_IN),
+	AST_APP_OPTION('o', MON_FLAG_DROP_OUT),
+});
+
 /*!
  * \brief Start monitor
  * \param chan
@@ -656,9 +669,9 @@
 	char tmp[256];
 	int stream_action = X_REC_IN | X_REC_OUT;
 	int joinfiles = 0;
-	int waitforbridge = 0;
 	int res = 0;
 	char *parse;
+	struct ast_flags flags = { 0 };
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(format);
 		AST_APP_ARG(fname_base);
@@ -675,14 +688,17 @@
 	AST_STANDARD_APP_ARGS(args, parse);
 
 	if (!ast_strlen_zero(args.options)) {
-		if (strchr(args.options, 'm'))
+		ast_app_parse_options(monitor_opts, &flags, NULL, args.options);
+
+		if (ast_test_flag(&flags, MON_FLAG_MIX)) {
 			stream_action |= X_JOIN;
-		if (strchr(args.options, 'b'))
-			waitforbridge = 1;
-		if (strchr(args.options, 'i'))
+		}
+		if (ast_test_flag(&flags, MON_FLAG_DROP_IN)) {
 			stream_action &= ~X_REC_IN;
-		if (strchr(args.options, 'o'))
+		}
+		if (ast_test_flag(&flags, MON_FLAG_DROP_OUT)) {
 			stream_action &= ~X_REC_OUT;
+		}
 	}
 
 	arg = strchr(args.format, ':');
@@ -698,7 +714,7 @@
 		ast_cdr_setuserfield(ast_channel_name(chan), tmp);
 		ast_channel_unlock(chan);
 	}
-	if (waitforbridge) {
+	if (ast_test_flag(&flags, MON_FLAG_BRIDGED)) {
 		/* We must remove the "b" option if listed.  In principle none of
 		   the following could give NULL results, but we check just to
 		   be pedantic. Reconstructing with checks for 'm' option does not




More information about the asterisk-commits mailing list