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
7 changes: 7 additions & 0 deletions src/Lua-cURL-callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
******************************************************************************/

#include <string.h> /* memcpy */
#include <stdio.h> /* stdin, stdout */

#include "Lua-cURL.h"
#include "Lua-utility.h"
Expand Down Expand Up @@ -95,19 +96,25 @@ int l_easy_clear_headerfunction(lua_State *L, CURL* curl) {
l_easy_private *privatep = luaL_checkudata(L, 1, LUACURL_EASYMETATABLE);
if (curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, NULL) != CURLE_OK)
luaL_error(L, "%s", privatep->error);
if (curl_easy_setopt(curl, CURLOPT_WRITEHEADER, NULL) != CURLE_OK)
luaL_error(L, "%s", privatep->error);
return 0;
}

int l_easy_clear_writefunction(lua_State *L, CURL* curl) {
l_easy_private *privatep = luaL_checkudata(L, 1, LUACURL_EASYMETATABLE);
if (curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL) != CURLE_OK)
luaL_error(L, "%s", privatep->error);
if (curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout) != CURLE_OK)
luaL_error(L, "%s", privatep->error);
return 0;
}

int l_easy_clear_readfunction(lua_State *L, CURL* curl) {
l_easy_private *privatep = luaL_checkudata(L, 1, LUACURL_EASYMETATABLE);
if (curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL) != CURLE_OK)
luaL_error(L, "%s", privatep->error);
if (curl_easy_setopt(curl, CURLOPT_READDATA, stdin) != CURLE_OK)
luaL_error(L, "%s", privatep->error);
return 0;
}
9 changes: 7 additions & 2 deletions src/Lua-cURL.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ int l_easy_perform(lua_State *L) {
int headerfunction;
/* do readcallback */
int readfunction;
/* curl_easy_perform return code*/
CURLcode perform_status;

/* check optional callback table */
luaL_opt(L, luaL_checktable, 2, lua_newtable(L));
Expand Down Expand Up @@ -155,8 +157,7 @@ int l_easy_perform(lua_State *L) {


/* callback table is on top on stack */
if (curl_easy_perform(curl) != CURLE_OK)
luaL_error(L, "%s", privatep->error);
perform_status = curl_easy_perform(curl);

/* unset callback functions */
if (headerfunction)
Expand All @@ -165,6 +166,10 @@ int l_easy_perform(lua_State *L) {
l_easy_clear_writefunction(L, privatep->curl);
if (readfunction)
l_easy_clear_readfunction(L, privatep->curl);

if (perform_status != CURLE_OK)
return luaL_error(L, "%s", privatep->error);

return 0;
}

Expand Down