glob() static private method

static private glob ( byte pattern, byte name ) : bool
pattern byte
name byte
return bool
Esempio n. 1
0
 internal Proxy getProxy(String host)
 {
     if (proxies == null)
     {
         return(null);
     }
     byte[] _host = System.Text.Encoding.Default.GetBytes(host);
     lock (proxies)
     {
         for (int i = 0; i < proxies.Count; i += 2)
         {
             if (Util.glob(((byte[])proxies[i]), _host))
             {
                 return((Proxy)(proxies[i + 1]));
             }
         }
     }
     return(null);
 }
Esempio n. 2
0
        private ArrayList glob_local(String _path)
        {
            //System.out.println("glob_local: "+_path);
            ArrayList v = new ArrayList();

            byte[] path = Encoding.UTF8.GetBytes(_path);
            int    i    = path.Length - 1;

            while (i >= 0)
            {
                if (path[i] == '*' || path[i] == '?')
                {
                    break;
                }
                i--;
            }
            if (i < 0)
            {
                v.Add(_path); return(v);
            }
            while (i >= 0)
            {
                if (path[i] == file_separatorc)
                {
                    break;
                }
                i--;
            }
            if (i < 0)
            {
                v.Add(_path); return(v);
            }
            byte[] dir;
            if (i == 0)
            {
                dir = new byte[] { (byte)file_separatorc };
            }
            else
            {
                dir = new byte[i];
                System.Array.Copy(path, 0, dir, 0, i);
            }
            byte[] pattern = new byte[path.Length - i - 1];
            System.Array.Copy(path, i + 1, pattern, 0, pattern.Length);
            //System.out.println("dir: "+Encoding.UTF8.GetString(dir)+" pattern: "+Encoding.UTF8.GetString(pattern));
            try
            {
                var children = System.IO.Directory.GetFileSystemEntries(dir.GetString(Encoding.UTF8));
                foreach (var child in children)
                {
                    //System.out.println("children: "+children[j]);
                    if (Util.glob(pattern, Encoding.UTF8.GetBytes(child)))
                    {
                        v.Add(Encoding.UTF8.GetString(dir) + file_separator + child);
                    }
                }
            }
            catch (Exception)
            {
            }
            return(v);
        }
Esempio n. 3
0
        private ArrayList glob_remote(String _path)
        {
            //System.err.println("glob_remote: "+_path);
            ArrayList v = new ArrayList();

            byte[] path = Encoding.UTF8.GetBytes(_path);
            if (!IsPattern(path))
            {
                v.Add(Util.unquote(_path)); return(v);
            }
            int i = path.Length - 1;

            while (i >= 0)
            {
                if (path[i] == '/')
                {
                    break;
                }
                i--;
            }
            if (i < 0)
            {
                v.Add(Util.unquote(_path)); return(v);
            }
            byte[] dir;
            if (i == 0)
            {
                dir = new byte[] { (byte)'/' };
            }
            else
            {
                dir = new byte[i];
                System.Array.Copy(path, 0, dir, 0, i);
            }
            //System.err.println("dir: "+Encoding.UTF8.GetString(dir));
            byte[] pattern = new byte[path.Length - i - 1];
            System.Array.Copy(path, i + 1, pattern, 0, pattern.Length);
            //System.err.println("file: "+Encoding.UTF8.GetString(pattern));

            sendOPENDIR(dir);

            Header _header = new Header();

            _header = ReadHeader(buf, _header);
            int length = _header.length;
            int type   = _header.type;

            buf.Rewind();
            fill(buf.buffer, 0, length);

            if (type != SSH_FXP_STATUS && type != SSH_FXP_HANDLE)
            {
                throw new SftpException(SSH_FX_FAILURE, "");
            }
            if (type == SSH_FXP_STATUS)
            {
                i = buf.ReadInt();
                throwStatusError(buf, i);
            }

            byte[] handle = buf.ReadString();         // filename

            while (true)
            {
                sendREADDIR(handle);
                _header = ReadHeader(buf, _header);
                length  = _header.length;
                type    = _header.type;

                if (type != SSH_FXP_STATUS && type != SSH_FXP_NAME)
                {
                    throw new SftpException(SSH_FX_FAILURE, "");
                }
                if (type == SSH_FXP_STATUS)
                {
                    buf.Rewind();
                    fill(buf.buffer, 0, length);
                    break;
                }

                buf.Rewind();
                fill(buf.buffer, 0, 4); length -= 4;
                int count = buf.ReadInt();

                byte[] str;
                //int flags;

                buf.Reset();
                while (count > 0)
                {
                    if (length > 0)
                    {
                        buf.Shift();
                        int j = (buf.buffer.Length > (buf.index + length)) ? length : (buf.buffer.Length - buf.index);
                        i = io.ins.read(buf.buffer, buf.index, j);
                        if (i <= 0)
                        {
                            break;
                        }
                        buf.index += i;
                        length    -= i;
                    }

                    byte[] filename = buf.ReadString();
                    //System.err.println("filename: "+Encoding.UTF8.GetString(filename));
                    str = buf.ReadString();
                    SftpATTRS attrs = SftpATTRS.getATTR(buf);

                    if (Util.glob(pattern, filename))
                    {
                        v.Add(Encoding.UTF8.GetString(dir) + "/" + Encoding.UTF8.GetString(filename));
                    }
                    count--;
                }
            }
            if (_sendCLOSE(handle, _header))
            {
                return(v);
            }
            return(null);
        }