Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
monitor: use app options parsing helper code
Browse files Browse the repository at this point in the history
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: http://svn.asterisk.org/svn/asterisk/trunk@412102 f38db490-d61c-443f-a65b-d21fe96a405b
  • Loading branch information
russellb committed Apr 11, 2014
1 parent 143b8de commit 25be99d
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions res/res_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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, ':');
Expand All @@ -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
Expand Down

0 comments on commit 25be99d

Please sign in to comment.