public ModuleEntry GetModule(String module, bool target = false, bool polyfill = true) { if (!_modules.ContainsKey(module)) { if (polyfill) { IEnumerable <ModuleEntry> pm = _modules.Select(a => a.Value).Where(a => a.Polyfill); if (pm.Count() != 0) { ModuleEntry moduleEntry = pm.FirstOrDefault(); moduleEntry.Name = module; return(moduleEntry); } } throw new IpTablesNetException(String.Format("The factory could not find module: {0}", module)); } ModuleEntry m = _modules[module]; if (m.IsTarget == target) { return(m); } throw new IpTablesNetException(String.Format("The factory could not find a module of the correct type: {0}", module)); }
public ModuleFactory() { foreach (var mFunc in AllModules) { ModuleEntry m = mFunc(); _modules.Add(m.Name, m); } }
/// <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 + "\""); }
protected internal static ModuleEntry GetModuleEntryInternal(String moduleName, Type moduleType, Func <IEnumerable <String> > options, bool preloaded = false) { var entry = new ModuleEntry { Name = moduleName, Module = moduleType, Options = options(), Preloaded = preloaded, IsTarget = false }; return(entry); }
public ModuleEntry?GetModuleOrDefault(String module, bool target = false) { if (!_modules.ContainsKey(module)) { return(null); } ModuleEntry m = _modules[module]; if (m.IsTarget == target) { return(m); } return(null); }
protected internal static ModuleEntry GetTargetModuleEntryInternal(String moduleName, Type moduleType, Func <IEnumerable <String> > options, bool preloaded = false) { var entry = new ModuleEntry { Name = moduleName, Module = moduleType, Options = options(), Preloaded = preloaded, IsTarget = true }; Debug.Assert(entry.Options != null, "Options null for " + moduleName); return(entry); }
protected internal static ModuleEntry GetTargetModuleEntryInternal(String moduleName, Type moduleType, Func<IEnumerable<String>> options, bool preloaded = false) { var entry = new ModuleEntry { Name = moduleName, Module = moduleType, Options = options(), Preloaded = preloaded, IsTarget = true }; Debug.Assert(entry.Options != null, "Options null for "+moduleName); return entry; }
public void RegisterModule(ModuleEntry entry) { _modules.Add(entry.Name, entry); }
/// <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 + "\""); }