<commit_before>﻿using System;
using SystemInteract;
using IPTables.Net.Iptables.Helpers;
using IPTables.Net.Netfilter;

namespace IPTables.Net.Iptables.Adapter.Client
{
    internal class IPTablesBinaryAdapterClient : IpTablesAdapterClientBase, IIPTablesAdapterClient
    {
        private readonly NetfilterSystem _system;

        public IPTablesBinaryAdapterClient(NetfilterSystem system)
        {
            _system = system;
        }

        public override void DeleteRule(String table, String chainName, int position)
        {
            String command = "-D " + chainName + " " + position;
            if (!String.IsNullOrEmpty(table) && table != "filter")
            {
                command += " -t " + table;
            }

            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void DeleteRule(IpTablesRule rule)
        {
            String command = rule.GetActionCommand("-D");
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void InsertRule(IpTablesRule rule)
        {
            String command = rule.GetActionCommand("-I");
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void ReplaceRule(IpTablesRule rule)
        {
            String command = rule.GetActionCommand("-R");
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void AddRule(IpTablesRule rule)
        {
            String command = rule.GetActionCommand();
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override bool HasChain(string table, string chainName)
        {
            throw new NotImplementedException();
        }

        public override void AddChain(string table, string chainName)
        {
            String command = String.Format("-t {0} -N {1}", table, chainName);
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void DeleteChain(string table, string chainName, bool flush = false)
        {
            String arguments;
            if (flush)
            {
                arguments = String.Format("-t {0} -F {1} -X {1}", table, chainName);
            }
            else
            {
                arguments = String.Format("-t {0} -X {1}", table, chainName);
            }<commit_msg>Added HasChain method to Iptables binary adapter<commit_after>﻿using System;
using SystemInteract;
using IPTables.Net.Exceptions;
using IPTables.Net.Iptables.Helpers;
using IPTables.Net.Netfilter;

namespace IPTables.Net.Iptables.Adapter.Client
{
    internal class IPTablesBinaryAdapterClient : IpTablesAdapterClientBase, IIPTablesAdapterClient
    {
        private readonly NetfilterSystem _system;

        public IPTablesBinaryAdapterClient(NetfilterSystem system)
        {
            _system = system;
        }

        public override void DeleteRule(String table, String chainName, int position)
        {
            String command = "-D " + chainName + " " + position;
            if (!String.IsNullOrEmpty(table) && table != "filter")
            {
                command += " -t " + table;
            }

            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void DeleteRule(IpTablesRule rule)
        {
            String command = rule.GetActionCommand("-D");
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void InsertRule(IpTablesRule rule)
        {
            String command = rule.GetActionCommand("-I");
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void ReplaceRule(IpTablesRule rule)
        {
            String command = rule.GetActionCommand("-R");
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void AddRule(IpTablesRule rule)
        {
            String command = rule.GetActionCommand();
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override bool HasChain(string table, string chainName)
        {
            String command = String.Format("-L {0} -t {1}", chainName, table);
            try
            {
                ExecutionHelper.ExecuteIptables(_system, command);
                return true;
            }
            catch (IpTablesNetException)
            {
                return false;
            }
        }

        public override void AddChain(string table, string chainName)
        {
            String command = String.Format("-t {0} -N {1}", table, chainName);
            ExecutionHelper.ExecuteIptables(_system, command);
        }

        public override void DeleteChain(string table, string chainName, bool flush = false)
        {
            String arguments;
            if (flush)
            {
                arguments = String.Format("-t {0} -F {1} -X {1}", table, chainName);
            }
            else
            {
                arguments = String.Format("-t {0} -X {1}", table, chainName);
            }
{'fraction_non_alphanumeric': 0.08911471565370334, 'fraction_numerical': 0.003126832128200117, 'mean_word_length': 1.9245714285714286, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2143533', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1264, 'n_words': 312}