Esempio n. 1
0
        internal override string[] ExportObject(IpObject obj)
        {
            var ret = new List <string>(base.ExportObject(obj));

            if (!obj.Pairs.ContainsKey("from"))
            {
                ret.Add("from");
                ret.Add("all");
            }
            return(ret.ToArray());
        }
Esempio n. 2
0
        internal virtual String[] ExportObject(IpObject obj)
        {
            var ret = new List <string>(obj.Singles);

            foreach (var kv in obj.Pairs)
            {
                ret.Add(kv.Key);
                ret.Add(kv.Value);
            }
            return(ret.ToArray());
        }
Esempio n. 3
0
        protected virtual IpObject ParseObject(String str, String firstKey, char[] firstTrimChars = null)
        {
            IpObject ret = new IpObject();

            String[] strs = str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            if (strs.Length == 0)
            {
                return(null);
            }
            int i = 0;

            for (; i < strs.Length; i++)
            {
                var k = strs[i];
                if (IsSingle(k))
                {
                    ret.Singles.Add(k);
                }
                else
                {
                    break;
                }
            }
            if (firstKey != null)
            {
                var v = strs[i];
                if (firstTrimChars != null)
                {
                    v = v.TrimEnd(firstTrimChars);
                }
                ret.Pairs.Add(firstKey, v);
                i++;
            }
            for (; i < strs.Length; i++)
            {
                var k = strs[i];
                if (IsSingle(k))
                {
                    ret.Singles.Add(k);
                }
                else if (i + 1 != strs.Length)
                {
                    ret.Pairs.Add(k, strs[i + 1]);
                    i++;
                }
                else
                {
                    //Console.WriteLine("{0} {1}",ret.Singles.Count,string.Join(", ",ret.Pairs.Select((a)=>a.Key + ":" + a.Value)));
                    throw new IpTablesNetException(String.Format("Insufficient values to parse: {0}", k));
                }
            }
            return(ret);
        }
        internal override String[] ExportObject(IpObject obj)
        {
            List <String> ret = new List <string>();

            if (obj.Pairs.ContainsKey("to"))
            {
                ret.Add(obj.Pairs["to"]);
            }
            foreach (var kv in obj.Pairs)
            {
                if (kv.Key == "to")
                {
                    continue;
                }
                ret.Add(kv.Key);
                ret.Add(kv.Value);
            }
            ret.AddRange(obj.Singles);
            return(ret.ToArray());
        }
Esempio n. 5
0
 public virtual void Delete(IpObject obj)
 {
     Delete(ExportObject(obj));
 }
Esempio n. 6
0
 public virtual void Add(IpObject obj)
 {
     Add(ExportObject(obj));
 }