celeron55/minetest — pull request #490 by Jeija (2013-02-14 19:30:57+00:00)
Title: Allow downloading files/requesting urls from Lua

Example

```Lua
on_punch = function (pos, node)
minetest.download_http("mesecons.net", 10, function (result, code)
print(result)
print(code)
end)
end
```

Use cases

* Tell user when update for a mod is available
* Share creations with others (Buildings, mesecons microcontroller code snippets)
* Interaction with other servers (Inter-Server Chat, Inter-Server Trade)
* Interface to Real-Life devices (e.g. Mod that notifys server owners e.g. by email or sms)
* There are propably more cases you can think of

How it works

Downloads/Calls are all in seperate threads (CurlFetchThread : SimpleThread)
The lua function minetest.curl_fetch(url, timeout) starts a thread and returns a handle.
The handle can be used in data, curlcode = minetest.get_curl_fetch_result(handle)
Returns nil if not finished or data from website and curlcode if succesful.
The function minetest.download_http(url, timeout, callbackfunction) defined in builtin/misc.lua defines a callback-like interface to be used by mods, by polling the status of the current downloads.
For some reason the timeout doesn't seem to work on all setups, but as downloads are in a seperate thread anyway, that doesn't really matter anyway.

Security

Being able to send stuff across the internet likely sounds like a vulnerability. I propose to merge sapier's pull request concerning the safe file opening API, so that mods cannot remotely modify the server's computer. Additionaly, when accessing curl, the server will output something like
```
20:01:32: ACTION[ServerThread]: WARNING: A mod accesses URL 'example.org'. Remove it if you don't trust that site.
```