CLuaInstance: Add class for using libcurl

- Add simple download function
 - Set Lua api version to 1.24

	parameter	typ		default
	----------------------------------------
	url		string		required
	o, outputfile	string		when empty then save to string
					as secund return value
	A, userAgent	string		empty
	v, verbose	bool		false
	s, silent	bool		false
	connectTimeout	number		20
	ipv4		bool		false
	ipv6		bool		false
	useProxy	bool		true (default)
	followRedir	bool		true
	maxRedirs	number		20

Example:
	-- simplest program call:
	-- ----------------------
	local curl = curl.new()
	local ret, data = curl:download{url="http://example.com", o="/tmp/test.txt"}
	if ret ~= CURL.OK then
		print("Error: " .. data)
	end

	-- or --

	local curl = curl.new()
	local ret, data = curl:download{url="http://example.com"}
	if ret == CURL.OK then
		-- downloaded data
		print(data)
		..
	else
		print("Error: " .. data)
	end
This commit is contained in:
M. Liebmann
2015-12-13 23:32:16 +01:00
parent 8f810d52fa
commit 4f9158c2a9
6 changed files with 429 additions and 1 deletions

60
src/gui/lua/lua_curl.h Normal file
View File

@@ -0,0 +1,60 @@
/*
* simple lua curl functions
*
* (C) 2015 M. Liebmann (micha-bbg)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LUACURL_H
#define _LUACURL_H
class CLuaCurl
{
public:
CLuaCurl() {};
~CLuaCurl() {};
};
struct progressData {
CURL *curl;
double last_dlnow;
};
class CLuaInstCurl
{
public:
enum {
LUA_CURL_OK = 0,
LUA_CURL_ERR_HANDLE = 1,
LUA_CURL_ERR_NO_URL = 2,
LUA_CURL_ERR_CREATE_FILE = 3,
LUA_CURL_ERR_CURL = 4
};
CLuaInstCurl() {};
~CLuaInstCurl() {};
static CLuaInstCurl* getInstance();
static void LuaCurlRegister(lua_State *L);
private:
static CLuaCurl *CurlCheckData(lua_State *L, int n);
static int CurlNew(lua_State *L);
static size_t CurlWriteToString(void *ptr, size_t size, size_t nmemb, void *data);
static int CurlProgressFunc(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
static int CurlDownload(lua_State *L);
static int CurlDelete(lua_State *L);
};
#endif //_LUACURL_H