From 2ea268de54fd9a386f5f0671c2fb3bfc3156168a Mon Sep 17 00:00:00 2001 From: gamax92 Date: Tue, 19 May 2015 11:57:20 -0600 Subject: [PATCH] I really need to push this, so do so --- src/component/internet.lua | 46 ++++++++++++++++++++++++++++++++++++++ src/config.lua | 2 ++ 2 files changed, 48 insertions(+) create mode 100644 src/component/internet.lua diff --git a/src/component/internet.lua b/src/component/internet.lua new file mode 100644 index 0000000..1ca913c --- /dev/null +++ b/src/component/internet.lua @@ -0,0 +1,46 @@ +-- internet component +local obj = {} + +function obj.isTcpEnabled() -- Returns whether TCP connections can be made (config setting). + cprint("internet.isTcpEnabled") + return config.get("internet.enableTcp",true) +end +function obj.isHttpEnabled() -- Returns whether HTTP requests can be made (config setting). + cprint("internet.isHttpEnabled") + return config.get("internet.enableHttp",true) +end +function obj.connect(address, port) -- Opens a new TCP connection. Returns the handle of the connection. + --STUB + cprint("internet.connect",address, port) + if port == nil then port = -1 end + compCheckArg(1,address,"string") + compCheckArg(2,port,"number") + if not config.get("internet.enableTcp",true) then + return nil, "tcp connections are unavailable" + end + return nil +end +function obj.request(url, postData) -- Starts an HTTP request. If this returns true, further results will be pushed using `http_response` signals. + --STUB + cprint("internet.request",url, postData) + compCheckArg(1,url,"string") + if not config.get("internet.enableHttp",true) then + return nil, "http requests are unavailable" + end + local post + if type(postData) == "string" then + post = postData + end + return nil +end + +local cec = {} + +local doc = { + ["isTcpEnabled"]="function():boolean -- Returns whether TCP connections can be made (config setting).", + ["isHttpEnabled"]="function():boolean -- Returns whether HTTP requests can be made (config setting).", + ["connect"]="function(address:string[, port:number]):userdata -- Opens a new TCP connection. Returns the handle of the connection.", + ["request"]="function(url:string[, postData:string]):userdata -- Starts an HTTP request. If this returns true, further results will be pushed using `http_response` signals.", +} + +return obj,cec,doc diff --git a/src/config.lua b/src/config.lua index a4e9482..bd734f8 100644 --- a/src/config.lua +++ b/src/config.lua @@ -6,6 +6,8 @@ local comments = { ["computer.lua"]="Settings specific to the Lua architecture.", ["computer.lua.allowBytecode"]="Whether to allow loading precompiled bytecode via Lua's `load` function, or related functions (`loadfile`, `dofile`). Enable this only if you absolutely trust all users on your server and all Lua code you run. This can be a MASSIVE SECURITY RISK, since precompiled code can easily be used for exploits, running arbitrary code on the real server! I cannot stress this enough: only enable this is you know what you're doing.", ["computer.timeout"]="The time in seconds a program may run without yielding before it is forcibly aborted. This is used to avoid stupidly written or malicious programs blocking other computers by locking down the executor threads. Note that changing this won't have any effect on computers that are already running - they'll have to be rebooted for this to take effect.", +["internet.enableHttp"]="Whether to allow HTTP requests via internet cards. When enabled, the `request` method on internet card components becomes available.", +["internet.enableTcp"]="Whether to allow TCP connections via internet cards. When enabled, the `connect` method on internet card components becomes available.", } local function writeComment(text,file,size)