diff --git a/source/httpc.c b/source/httpc.c index 87c826d..9461a25 100644 --- a/source/httpc.c +++ b/source/httpc.c @@ -59,7 +59,7 @@ static int httpc_open(lua_State *L) { method = HTTPC_METHOD_DELETE; } Result ret = 0; - + ret = httpcOpenContext(context, method, url, 0); if (ret != 0) { lua_pushboolean(L, false); @@ -83,7 +83,7 @@ static int httpc_addRequestHeaderField(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); char *name = (char*)luaL_checkstring(L, 2); char *value = (char*)luaL_checkstring(L, 3); - + Result ret = httpcAddRequestHeaderField(context, name ,value); if (ret != 0) { lua_pushboolean(L, false); @@ -104,7 +104,7 @@ Begin a request to get the content at the URL. static int httpc_beginRequest(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); Result ret = 0; - + ret = httpcBeginRequest(context); if (ret != 0) { lua_pushboolean(L, false); @@ -126,7 +126,7 @@ static int httpc_getStatusCode(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); u32 statusCode = 0; - Result ret = httpcGetResponseStatusCode(context, &statusCode, 0); + Result ret = httpcGetResponseStatusCode(context, &statusCode); if (ret != 0) { lua_pushnil(L); lua_pushinteger(L, ret); @@ -144,9 +144,9 @@ Return the amount of data to download. static int httpc_getDownloadSize(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); u32 contentSize = 0; - + httpcGetDownloadSizeState(context, NULL, &contentSize); - + lua_pushinteger(L, contentSize); return 1; } @@ -161,17 +161,17 @@ Download and return the data of the context. static int httpc_downloadData(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); u32 status = 0; - Result ret = httpcGetResponseStatusCode(context, &status, 0); + Result ret = httpcGetResponseStatusCode(context, &status); if (ret != 0) { lua_pushnil(L); lua_pushinteger(L, ret); return 2; } - + u32 size = 0; httpcGetDownloadSizeState(context, NULL, &size); u8 *buff = (u8*)malloc(size); - + ret = httpcDownloadData(context, buff, size, NULL); if (ret != 0) { free(buff); @@ -179,7 +179,7 @@ static int httpc_downloadData(lua_State *L) { lua_pushinteger(L, ret); return 2; } - + lua_pushstring(L, (char*)buff); free(buff); //lua_pushinteger(L, size); // only for test purposes. @@ -192,9 +192,9 @@ Close the context. */ static int httpc_close(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); - + httpcCloseContext(context); - + return 0; } @@ -202,15 +202,15 @@ static int httpc_close(lua_State *L) { Add a POST form field to a HTTP context. @function :addPostData @tparam string name name of the field -@tparam string value value of the field +@tparam string value value of the field */ static int httpc_addPostData(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); char *name = (char*)luaL_checkstring(L, 2); char *value = (char*)luaL_checkstring(L, 3); - + httpcAddPostDataAscii(context, name, value); - + return 0; } @@ -226,9 +226,9 @@ static int httpc_getResponseHeader(lua_State *L) { char *name = (char*)luaL_checkstring(L, 2); u32 maxSize = luaL_checkinteger(L, 3); char* value = 0; - + httpcGetResponseHeader(context, name, value, maxSize); - + lua_pushstring(L, value); return 1; } @@ -245,14 +245,14 @@ static int httpc_addTrustedRootCA(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); u32 certsize; u8* cert = (u8*)luaL_checklstring(L, 2, (size_t*)&certsize); - + Result ret = httpcAddTrustedRootCA(context, cert, certsize); if (ret != 0) { lua_pushboolean(L, false); lua_pushinteger(L, ret); return 2; } - + lua_pushboolean(L, true); return 1; } @@ -265,14 +265,14 @@ Set SSL options for a context. */ static int httpc_setSSLOptions(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); - + bool disVer = lua_toboolean(L, 2); bool tsl10 = false; if (lua_isboolean(L, 3)) tsl10 = lua_toboolean(L, 3); - + httpcSetSSLOpt(context, (disVer?SSLCOPT_DisableVerify:0)|(tsl10?SSLCOPT_TLSv10:0)); - + return 0; } @@ -282,13 +282,13 @@ Add all the default certificates to the context. */ static int httpc_addDefaultCert(lua_State *L) { httpcContext *context = lua_touserdata(L, 1); - + httpcAddDefaultCert(context, SSLC_DefaultRootCert_CyberTrust); httpcAddDefaultCert(context, SSLC_DefaultRootCert_AddTrust_External_CA); httpcAddDefaultCert(context, SSLC_DefaultRootCert_COMODO); httpcAddDefaultCert(context, SSLC_DefaultRootCert_USERTrust); httpcAddDefaultCert(context, SSLC_DefaultRootCert_DigiCert_EV); - + return 0; } @@ -321,9 +321,9 @@ int luaopen_httpc_lib(lua_State *L) { lua_pushvalue(L, -1); lua_setfield(L, -2, "__index"); luaL_setfuncs(L, httpc_methods, 0); - + luaL_newlib(L, httpc_functions); - + return 1; } @@ -332,11 +332,10 @@ void load_httpc_lib(lua_State *L) { httpcInit(0x1000); isHttpcInitialized = true; } - + luaL_requiref(L, "ctr.httpc", luaopen_httpc_lib, false); } void unload_httpc_lib(lua_State *L) { httpcExit(); } -