From f09b51a6a5998bdc97c079daebdfce533085a9d2 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 25 May 2009 16:13:27 -0700 Subject: Adding Base64DecodeBin, and fixing memory leak. --- lib/LuaHttp.cc | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index e9dc90d..80ed0eb 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -119,6 +119,7 @@ enum HttpResponse_functions_t { HTTPRESPONSE_NEWHTTPRESPONSE = 0, HTTPRESPONSE_BASE64_ENCODE, HTTPRESPONSE_BASE64_DECODE, + HTTPRESPONSE_BASE64_DECODE_BIN, HTTPRESPONSE_MD5, HTTPRESPONSE_SHA1, HTTPRESPONSE_SHA256, @@ -132,13 +133,14 @@ struct lua_functypes_t HttpResponse_methods[] = { }; struct lua_functypes_t HttpResponse_functions[] = { - { HTTPRESPONSE_NEWHTTPRESPONSE, "HttpResponse", 0, 0, { } }, - { HTTPRESPONSE_BASE64_ENCODE, "Base64Encode", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, - { HTTPRESPONSE_BASE64_DECODE, "Base64Decode", 1, 1, { BLUA_STRING } }, - { HTTPRESPONSE_MD5, "MD5", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, - { HTTPRESPONSE_SHA1, "SHA1", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, - { HTTPRESPONSE_SHA256, "SHA256", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, - { HTTPRESPONSE_GENTICKET, "GenTicket", 0, 1, { BLUA_NUMBER } }, + { HTTPRESPONSE_NEWHTTPRESPONSE, "HttpResponse", 0, 0, { } }, + { HTTPRESPONSE_BASE64_ENCODE, "Base64Encode", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, + { HTTPRESPONSE_BASE64_DECODE, "Base64Decode", 1, 1, { BLUA_STRING } }, + { HTTPRESPONSE_BASE64_DECODE_BIN, "Base64DecodeBin", 2, 2, { BLUA_STRING | BLUA_OBJECT } }, + { HTTPRESPONSE_MD5, "MD5", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, + { HTTPRESPONSE_SHA1, "SHA1", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, + { HTTPRESPONSE_SHA256, "SHA256", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, + { HTTPRESPONSE_GENTICKET, "GenTicket", 0, 1, { BLUA_NUMBER } }, { -1, 0, 0, 0, 0 } }; @@ -150,6 +152,7 @@ class sLua_HttpResponse : public Base { DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_NEWHTTPRESPONSE); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_ENCODE); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE); + DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE_BIN); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_MD5); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256); @@ -173,6 +176,7 @@ void LuaHttpResponse::pushstatics(Lua * L) throw (GeneralException) { PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_NEWHTTPRESPONSE); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_ENCODE); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE); + PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE_BIN); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_MD5); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256); @@ -295,7 +299,6 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) } r = 1; break; - case HTTPRESPONSE_BASE64_ENCODE: if (L->isstring()) { dec = L->tostring(); @@ -311,14 +314,23 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) } r = 1; break; - case HTTPRESPONSE_BASE64_DECODE: enc_t = (char *) Base64::decode(L->tostring(), &l); enc_t[l] = 0; L->push(enc_t, l); + free(enc_t); r = 1; break; - + case HTTPRESPONSE_BASE64_DECODE_BIN: + { + Handle * out = lua_recast(L, 2); + if (!out) + L->error("Need an output handle to Base64DecodeBin") + enc_t = (char *) Base64::decode(L->tostring(), &l); + out->write(enc_t, l); + free(enc_t); + } + break; case HTTPRESPONSE_MD5: if (L->isstring()) { dec = L->tostring(); -- cgit v1.2.3