Пример #1
0
        /// <summary>
        /// Consume arguments
        /// </summary>
        /// <param name="position">Rhe position to parse</param>
        /// <param name="not"></param>
        /// <param name="version"></param>
        /// <returns>number of arguments consumed</returns>
        public int FeedToSkip(int position, bool not, int version)
        {
            Position = position;
            String option = GetCurrentArg();

            if (option == "-m")
            {
                LoadParserModule(GetNextArg(), version);
                return(1);
            }
            if (option == "-A")
            {
                _chainName = GetNextArg();
                return(1);
            }
            if (option == "-t")
            {
                _tableName = GetNextArg();
                return(1);
            }
            if (option == "-j")
            {
                LoadParserModule(GetNextArg(), version, true);
            }

            //All the preloaded modules are indexed here
            ModuleEntry mQuick;

            if (ModuleRegistry.PreloadOptions.TryGetValue(option, out mQuick))
            {
                IIpTablesModule module = _ipRule.GetModuleForParseInternal(mQuick.Name, mQuick.Activator, version);
                return(module.Feed(this, not));
            }

            //Search each module, do it verbosely from the most recently added
            for (int index = _parsers.Count - 1; index >= 0; index--)
            {
                ModuleEntry m = _parsers[index];
                if (m.Options.Contains(option))
                {
                    IIpTablesModule module = _ipRule.GetModuleForParseInternal(m.Name, m.Activator, version);
                    return(module.Feed(this, not));
                }
            }

            if (_polyfill != null)
            {
                IIpTablesModule module = _ipRule.GetModuleForParseInternal(_polyfill.Value.Name, _polyfill.Value.Activator, version);
                return(module.Feed(this, not));
            }

            throw new IpTablesNetException("Unknown option: \"" + option + "\"");
        }
Пример #2
0
        /// <summary>
        /// Consume arguments
        /// </summary>
        /// <param name="position">Rhe position to parse</param>
        /// <param name="not"></param>
        /// <param name="version"></param>
        /// <returns>number of arguments consumed</returns>
        public int FeedToSkip(int position, bool not, int version)
        {
            Position = position;
            String option = GetCurrentArg();

            if (option == "-m")
            {
                LoadParserModule(GetNextArg(), version);
                return(1);
            }
            if (option == "-A" || option == "-D" || option == "-R" || option == "-I")
            {
                _ipCommand.ChainName = GetNextArg();
                _ipCommand.Type      = IpTablesCommand.GetCommandType(option);
                if (option == "-D" || option == "-R" || option == "-I")
                {
                    var  nextArg = GetNextArg(2);
                    uint offset;
                    if (uint.TryParse(nextArg, out offset))
                    {
                        if (offset == 0)
                        {
                            throw new Exception("Invalid offset");
                        }
                        _ipCommand.Offset = ((int)offset - 1);
                        return(2);
                    }
                    else
                    {
                        _ipCommand.Offset = -1;
                    }
                }
                return(1);
            }
            if (option == "-t")
            {
                _ipCommand.Table = GetNextArg();
                return(1);
            }
            if (option == "-j")
            {
                LoadParserModule(GetNextArg(), version, true);
            }

            //All the preloaded modules are indexed here
            ModuleEntry mQuick;

            if (ModuleRegistry.PreloadOptions.TryGetValue(option, out mQuick))
            {
                IIpTablesModule module = _ipCommand.Rule.GetModuleForParseInternal(mQuick.Name, mQuick.Activator, version);
                return(module.Feed(this, not));
            }

            //Search each module, do it verbosely from the most recently added
            for (int index = _parsers.Count - 1; index >= 0; index--)
            {
                ModuleEntry m = _parsers[index];
                if (m.Options.Contains(option))
                {
                    IIpTablesModule module = _ipCommand.Rule.GetModuleForParseInternal(m.Name, m.Activator, version);
                    return(module.Feed(this, not));
                }
            }

            if (_polyfill != null)
            {
                IIpTablesModule module = _ipCommand.Rule.GetModuleForParseInternal(_polyfill.Value.Name, _polyfill.Value.Activator, version);
                return(module.Feed(this, not));
            }

            throw new IpTablesNetException("Unknown option: \"" + option + "\"");
        }