From 600c2ef2d8dd8dcf71166ec5a0b1b7fdf2eb6f4f Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 26 Sep 2008 18:15:01 -0700 Subject: Adding the ability to hash data from handles. --- lib/LuaHttp.cc | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index 89e55e7..dd2e74d 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -135,11 +135,11 @@ 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_ENCODE, "Base64Encode", 1, 1, { BLUA_STRING | BLUA_OBJECT } }, { HTTPRESPONSE_BASE64_DECODE, "Base64Decode", 1, 1, { BLUA_STRING } }, - { HTTPRESPONSE_MD5, "MD5", 1, 1, { BLUA_STRING } }, - { HTTPRESPONSE_SHA1, "SHA1", 1, 1, { BLUA_STRING } }, - { HTTPRESPONSE_SHA256, "SHA256", 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 } }, { -1, 0, 0, 0, 0 } }; @@ -322,29 +322,44 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) break; case HTTPRESPONSE_MD5: - dec = L->tostring(); - { + if (L->isstring()) { + dec = L->tostring(); MD5 h; h.Update(dec); L->push(h.Finish()); + } else { + Handle * hdata = (Handle *) LuaObject::getme(L, 1); + MD5 h; + h.Update(hdata); + L->push(h.Finish()); } r = 1; break; case HTTPRESPONSE_SHA1: - dec = L->tostring(); - { + if (L->isstring()) { + dec = L->tostring(); SHA1 h; h.Update(dec); L->push(h.Finish()); + } else { + Handle * hdata = (Handle *) LuaObject::getme(L, 1); + SHA1 h; + h.Update(hdata); + L->push(h.Finish()); } r = 1; break; case HTTPRESPONSE_SHA256: - dec = L->tostring(); - { + if (L->isstring()) { + dec = L->tostring(); SHA256 h; h.Update(dec); L->push(h.Finish()); + } else { + Handle * hdata = (Handle *) LuaObject::getme(L, 1); + SHA256 h; + h.Update(hdata); + L->push(h.Finish()); } r = 1; break; -- cgit v1.2.3