Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Lua-cURL-setopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ static struct {
{P"timevalue ", CURLOPT_TIMEVALUE , l_easy_setopt_long},
/* network options */
{P"url", CURLOPT_URL, l_easy_setopt_string},
{P"protocols", CURLOPT_PROTOCOLS, l_easy_setopt_long},
{P"redir_protocols", CURLOPT_REDIR_PROTOCOLS, l_easy_setopt_long},
{P"proxy", CURLOPT_PROXY, l_easy_setopt_string},
{P"userpwd", CURLOPT_USERPWD, l_easy_setopt_string},
{P"proxyuserpwd", CURLOPT_PROXYUSERPWD, l_easy_setopt_string},
Expand Down
58 changes: 58 additions & 0 deletions src/Lua-cURL.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define luaL_newlibtable(L,l) lua_createtable(L,0,sizeof(l)/sizeof((l)[0]))
#define luaL_newlib(L,l) (luaL_newlibtable(L,l),luaL_register(L,NULL,l))
#define luaL_setfuncs(L,l,nups) luaL_register(L,NULL,l)
#define lua_pushunsigned(L,val) lua_pushinteger(L,val)
#endif

/* methods assigned to easy table */
Expand Down Expand Up @@ -71,6 +72,41 @@ static const struct luaL_Reg luacurl_m[] = {

{NULL, NULL}};

/* (key,value) items in the cURL.protocols table */
static const struct {
char *name; /* human readable name: used as table index */
unsigned long value; /* CURLPROTO_* value */
} luacurl_protos[] = {
{"HTTP", CURLPROTO_HTTP},
{"HTTPS", CURLPROTO_HTTPS},
{"FTP", CURLPROTO_FTP},
{"FTPS", CURLPROTO_FTPS},
{"SCP", CURLPROTO_SCP},
{"SFTP", CURLPROTO_SFTP},
{"TELNET", CURLPROTO_TELNET},
{"LDAP", CURLPROTO_LDAP},
{"LDAPS", CURLPROTO_LDAPS},
{"DICT", CURLPROTO_DICT},
{"FILE", CURLPROTO_FILE},
{"TFTP", CURLPROTO_TFTP},
{"IMAP", CURLPROTO_IMAP},
{"IMAPS", CURLPROTO_IMAPS},
{"POP3", CURLPROTO_POP3},
{"POP3S", CURLPROTO_POP3S},
{"SMTP", CURLPROTO_SMTP},
{"SMTPS", CURLPROTO_SMTPS},
{"RTSP", CURLPROTO_RTSP},
{"RTMP", CURLPROTO_RTMP},
{"RTMPT", CURLPROTO_RTMPT},
{"RTMPE", CURLPROTO_RTMPE},
{"RTMPTE", CURLPROTO_RTMPTE},
{"RTMPS", CURLPROTO_RTMPS},
{"RTMPTS", CURLPROTO_RTMPTS},
{"GOPHER", CURLPROTO_GOPHER},
{"ALL", CURLPROTO_ALL},
{NULL, 0}
};

int l_easy_escape(lua_State *L) {
size_t length = 0;
l_easy_private *privatep = luaL_checkudata(L, 1, LUACURL_EASYMETATABLE);
Expand Down Expand Up @@ -297,6 +333,25 @@ int l_easy_gc(lua_State *L) {
return 0;
}

/*
* Registers a table named "protocols" in the table on top of the stack.
*
* This function is meant for local use only. It's main use is for keeping the
* module registration function clean
*/
static void l_protocols_register(lua_State *L) {
size_t i;

lua_createtable(L, 0, sizeof luacurl_protos / sizeof luacurl_protos[0]);

for(i = 0; luacurl_protos[i].name != NULL; i++) {
lua_pushunsigned(L, luacurl_protos[i].value);
lua_setfield(L, -2, luacurl_protos[i].name);
}

lua_setfield(L, -2, "protocols");
}

/* registration hook function */
LUACURL_API int luaopen_cURL(lua_State* L) {
CURLcode rc;
Expand Down Expand Up @@ -353,6 +408,9 @@ LUACURL_API int luaopen_cURL(lua_State* L) {
lua_pushvalue(L,-1);
lua_setglobal(L,LUACURL_LIBNAME);

/* set protocols table */
l_protocols_register(L);

/* initialize curl once */
if ((rc = curl_global_init(CURL_GLOBAL_ALL)) != CURLE_OK)
luaL_error(L, "curl_global_init: %s", curl_easy_strerror(rc));
Expand Down