diff options
author | Russell Bryant <russell@russellbryant.com> | 2014-04-11 01:12:54 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2014-04-11 01:12:54 +0000 |
commit | af95d8c1d26e3bfa9fb668729adbafe2fe34d906 (patch) | |
tree | 9977dd5f15098e39783c6093ecafeb0def647f50 /res/res_monitor.c | |
parent | 0c1342bd2bc70138aed865efe8289d27c54580dc (diff) |
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/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@412102 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_monitor.c')
-rw-r--r-- | res/res_monitor.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/res/res_monitor.c b/res/res_monitor.c index b5225010e..2eafcb238 100644 --- a/res/res_monitor.c +++ b/res/res_monitor.c @@ -639,7 +639,20 @@ int AST_OPTIONAL_API_NAME(ast_monitor_change_fname)(struct ast_channel *chan, co 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 @@ static int start_monitor_exec(struct ast_channel *chan, const char *data) 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 @@ static int start_monitor_exec(struct ast_channel *chan, const char *data) 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 @@ static int start_monitor_exec(struct ast_channel *chan, const char *data) 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 |