private IodineObject DownloadString(VirtualMachine vm, IodineObject self, IodineObject[] args) { ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true; IodineString uri = args [0] as IodineString; string data; try { data = this.client.DownloadString(uri.ToString()); } catch (Exception e) { vm.RaiseException(e.Message); return(null); } return(new IodineString(data)); }
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("")); }
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)); }
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); }
public override void Accept(UseStatement useStmt) { string import = !useStmt.Relative ? useStmt.Module : Path.Combine( Path.GetDirectoryName(useStmt.Location.File), useStmt.Module); /* * Implementation detail: The use statement in all reality is simply an * alias for the function require (); Here we translate the use statement * into a call to the require function */ if (useStmt.Wildcard) { module.Initializer.EmitInstruction(useStmt.Location, Opcode.LoadConst, module.DefineConstant(new IodineString(import))); module.Initializer.EmitInstruction(useStmt.Location, Opcode.BuildTuple, 0); module.Initializer.EmitInstruction(useStmt.Location, Opcode.LoadGlobal, module.DefineConstant(new IodineName("require"))); module.Initializer.EmitInstruction(useStmt.Location, Opcode.Invoke, 2); module.Initializer.EmitInstruction(useStmt.Location, Opcode.Pop); } else { IodineObject[] items = new IodineObject [useStmt.Imports.Count]; module.Initializer.EmitInstruction(useStmt.Location, Opcode.LoadConst, module.DefineConstant(new IodineString(import))); if (items.Length > 0) { for (int i = 0; i < items.Length; i++) { items [i] = new IodineString(useStmt.Imports [i]); module.Initializer.EmitInstruction(useStmt.Location, Opcode.LoadConst, module.DefineConstant(new IodineString(useStmt.Imports [i]))); } module.Initializer.EmitInstruction(useStmt.Location, Opcode.BuildTuple, items.Length); } module.Initializer.EmitInstruction(useStmt.Location, Opcode.LoadGlobal, module.DefineConstant(new IodineName("require"))); module.Initializer.EmitInstruction(useStmt.Location, Opcode.Invoke, items.Length == 0 ? 1 : 2); module.Initializer.EmitInstruction(useStmt.Location, Opcode.Pop); } }
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); }
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); }
private IodineObject getHostEntry(VirtualMachine vm, IodineObject self, IodineObject[] args) { if (args.Length <= 0) { vm.RaiseException(new IodineArgumentException(1)); return(null); } IodineString domain = args [0] as IodineString; if (domain == null) { vm.RaiseException(new IodineTypeException("Str")); return(null); } try { return(new IodineHostEntry(Dns.GetHostEntry(domain.Value))); } catch (Exception ex) { vm.RaiseException(new IodineException(ex.Message)); return(null); } }
public static IodineOptions Parse(string[] args) { IodineOptions ret = new IodineOptions(); int i; bool sentinel = true; for (i = 0; i < args.Length && sentinel; i++) { switch (args [i]) { case "-d": case "--debug": ret.DebugFlag = true; break; case "-l": case "--loop": ret.LoopFlag = true; break; case "-w": ret.WarningFlag = true; break; case "-x": ret.SupressWarningFlag = true; break; case "-f": case "--fallback-repl": ret.FallBackFlag = true; break; case "-r": case "--repl": ret.ReplFlag = true; break; case "-c": case "--check": ret.InterpreterAction = InterpreterAction.Check; break; case "-v": case "--version": ret.InterpreterAction = InterpreterAction.ShowVersion; break; case "-h": case "--help": ret.InterpreterAction = InterpreterAction.ShowHelp; break; case "-e": case "--eval": ret.InterpreterAction = InterpreterAction.EvaluateArgument; break; case "--no-cache": ret.SupressAutoCache = true; break; case "--no-optimize": ret.SupressOptimizer = true; break; default: if (args [i].StartsWith("-")) { Console.Error.WriteLine("Unknown option '{0}'", args [i]); } else { ret.FileName = args [i]; if (ret.InterpreterAction == InterpreterAction.Repl) { ret.InterpreterAction = InterpreterAction.EvaluateFile; } } sentinel = false; break; } } IodineObject[] arguments = new IodineObject [ args.Length - i > 0 ? args.Length - i : 0 ]; int start = i; for (; i < args.Length; i++) { arguments [i - start] = new IodineString(args [i]); } ret.IodineArguments = new IodineList(arguments); return(ret); }
private void WriteString(IodineString str) { binaryWriter.Write((byte)DataType.StringObject); binaryWriter.Write(str.Value); }