From f7e9c15c7babadc23bd6deeb340925e6eb2a6776 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 4 Aug 2012 12:07:35 +0200 Subject: m_config: always reject setting global options in per-file mode Now the command line parser sets the m_config object into file local mode, so that m_config can check for this condition. Makes trying to set global options from a profile fail. Note: global options can be considered read-only by m_config, so maybe there should be an additional check for this. Reusing the file- local check is more practical for now, though. --- m_config.c | 6 ++++++ parser-mpcmd.c | 13 +++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/m_config.c b/m_config.c index f2f621d0fa..b1c732fb71 100644 --- a/m_config.c +++ b/m_config.c @@ -413,6 +413,12 @@ static int m_config_parse_option(struct m_config *config, void *optstruct, BSTR_P(name)); return M_OPT_INVALID; } + if (config->file_local_mode && (co->opt->flags & M_OPT_GLOBAL)) { + mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, + "The %.*s option is global and can't be set per-file.\n", + BSTR_P(name)); + return M_OPT_INVALID; + } // During command line preparse set only pre-parse options // Otherwise only set pre-parse option if they were not already set. if (((config->mode == M_COMMAND_LINE_PRE_PARSE) && diff --git a/parser-mpcmd.c b/parser-mpcmd.c index 33d3deabbf..d84ec16432 100644 --- a/parser-mpcmd.c +++ b/parser-mpcmd.c @@ -97,6 +97,7 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, struct playlist_param *local_params = 0; assert(config != NULL); + assert(!config->file_local_mode); assert(argv != NULL); assert(argc >= 1); @@ -122,6 +123,8 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, goto err_out; } mode = LOCAL; + // Needed for option checking. + m_config_enter_file_local(config); assert(!local_start); local_start = files->last; continue; @@ -149,6 +152,7 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, } local_params_count = 0; mode = GLOBAL; + m_config_leave_file_local(config); local_start = NULL; continue; } @@ -173,12 +177,6 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, BSTR_P(opt)); goto print_err; } - if (mode == LOCAL && (mp_opt->flags & M_OPT_GLOBAL)) { - mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, - "Option --%.*s is global and can't be set per-file\n", - BSTR_P(opt)); - goto print_err; - } // Handle some special arguments outside option parser. // --loop when it applies to a group of files (per-file is option) if (bstrcasecmp0(opt, "shuffle") == 0) { @@ -280,6 +278,7 @@ bool m_config_parse_mp_command_line(m_config_t *config, struct playlist *files, playlist_shuffle(files); talloc_free(local_params); + assert(!config->file_local_mode); return true; print_err: @@ -288,6 +287,8 @@ print_err: BSTR_P(orig_opt)); err_out: talloc_free(local_params); + if (config->file_local_mode) + m_config_leave_file_local(config); return false; } -- cgit v1.2.3