summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-05-25 16:13:27 -0700
committerPixel <pixel@nobis-crew.org>2009-05-25 16:13:27 -0700
commitf09b51a6a5998bdc97c079daebdfce533085a9d2 (patch)
tree0b51e8eacbceea4d97a37444382c1e78fde5da7b /lib
parent37fb09922f93215b2be2c76080f64e754bf2c6aa (diff)
Adding Base64DecodeBin, and fixing memory leak.
Diffstat (limited to 'lib')
-rw-r--r--lib/LuaHttp.cc32
1 files changed, 22 insertions, 10 deletions
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<Handle>(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();