Ejemplo n.º 1
0
            private IodineObject connect(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                IodineString  ipAddrStr = args [0] as IodineString;
                IodineInteger portObj   = args [1] as IodineInteger;
                IPAddress     ipAddr;
                int           port = (int)portObj.Value;

                EndPoint endPoint = null;

                if (!IPAddress.TryParse(ipAddrStr.ToString(), out ipAddr))
                {
                    endPoint = new IPEndPoint(DnsLookUp(ipAddrStr.ToString()), port);
                }
                else
                {
                    endPoint = new IPEndPoint(ipAddr, port);
                }

                try {
                    Socket.Connect(endPoint);
                    stream = new NetworkStream(this.Socket);
                } catch (Exception ex) {
                    vm.RaiseException("Could not connect to socket! (Reason: {0})", ex.Message);
                    return(null);
                }

                return(null);
            }
Ejemplo n.º 2
0
            private IodineObject UploadFile(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
                IodineString uri  = args [0] as IodineString;
                IodineString file = args [1] as IodineString;

                byte[] result = client.UploadFile(uri.ToString(), file.ToString());
                return(new IodineBytes(result));
            }
Ejemplo n.º 3
0
            private IodineObject Bind(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                if (args.Length < 2)
                {
                    vm.RaiseException(new IodineArgumentException(2));
                    return(null);
                }

                IodineString  ipAddrStr = args [0] as IodineString;
                IodineInteger portObj   = args [1] as IodineInteger;

                if (ipAddrStr == null)
                {
                    vm.RaiseException(new IodineTypeException("Str"));
                    return(null);
                }
                else if (portObj == null)
                {
                    vm.RaiseException(new IodineTypeException("Int"));
                    return(null);
                }

                IPAddress ipAddr;

                int      port     = (int)portObj.Value;
                EndPoint endPoint = null;

                if (!IPAddress.TryParse(ipAddrStr.ToString(), out ipAddr))
                {
                    endPoint = new IPEndPoint(DnsLookUp(ipAddrStr.ToString()), port);
                }
                else
                {
                    endPoint = new IPEndPoint(ipAddr, port);
                }

                try {
                    Socket.Bind(endPoint);
                } catch {
                    vm.RaiseException("Could not bind to socket!");
                    return(null);
                }
                return(null);
            }
Ejemplo n.º 4
0
            private IodineObject connectSsl(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                IodineString  ipAddrStr = args [0] as IodineString;
                IodineInteger portObj   = args [1] as IodineInteger;
                IPAddress     ipAddr;
                int           port = (int)portObj.Value;

                EndPoint endPoint = null;

                if (!IPAddress.TryParse(ipAddrStr.ToString(), out ipAddr))
                {
                    endPoint = new IPEndPoint(DnsLookUp(ipAddrStr.ToString()), port);
                }
                else
                {
                    endPoint = new IPEndPoint(ipAddr, port);
                }

                try {
                    Socket.Connect(endPoint);
                } catch {
                    vm.RaiseException("Could not connect to socket!");
                    return(null);
                }

                try {
                    stream = new SslStream(new NetworkStream(Socket), false, ValidateServerCertificate, null);
                } catch (Exception e) {
                    vm.RaiseException(e.Message);
                    return(null);
                }

                try {
                    ((SslStream)stream).AuthenticateAsClient(host);
                } catch (Exception e) {
                    vm.RaiseException(e.Message);
                    return(null);
                }

                return(null);
            }
Ejemplo n.º 5
0
            private IodineObject DownloadFile(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
                IodineString uri  = args [0] as IodineString;
                IodineString file = args [1] as IodineString;

                try {
                    client.DownloadFile(uri.ToString(), file.ToString());
                } catch (Exception e) {
                    vm.RaiseException(e.Message);
                }
                return(null);
            }
Ejemplo n.º 6
0
            private IodineObject DownloadRaw(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
                IodineString uri = args [0] as IodineString;

                byte[] data;
                try {
                    data = client.DownloadData(uri.ToString());
                } catch (Exception e) {
                    vm.RaiseException(e.Message);
                    return(null);
                }
                return(new IodineBytes(data));
            }
Ejemplo n.º 7
0
            private IodineObject UploadString(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
                IodineString uri = args [0] as IodineString;
                IodineString str = args [1] as IodineString;

                try {
                    string result = client.UploadString(uri.ToString(), "POST", str.ToString());
                    return(new IodineString(result));
                } catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.InnerException);
                }
                return(new IodineString(""));
            }
Ejemplo n.º 8
0
            private IodineObject UploadValues(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
                IodineString     uri  = args [0] as IodineString;
                IodineDictionary dict = args [1] as IodineDictionary;

                NameValueCollection nv = new NameValueCollection();

                foreach (IodineObject key in dict.Keys)
                {
                    nv [key.ToString()] = dict.Get(key).ToString();
                }

                byte[] result = client.UploadValues(uri.ToString(), nv);
                return(new IodineBytes(result));
            }
Ejemplo n.º 9
0
            private IodineObject setHost(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                if (args.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                IodineString hostObj = args [0] as IodineString;

                if (hostObj == null)
                {
                    vm.RaiseException(new IodineTypeException("Str"));
                }

                host = hostObj.ToString();
                return(null);
            }