summaryrefslogtreecommitdiff
path: root/lib/LuaHttp.cc
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-06-06 10:56:48 -0700
committerPixel <pixel@nobis-crew.org>2009-06-06 10:56:48 -0700
commit98f9f21a998eec7860da7b75a4e1b528a833b866 (patch)
tree8bbb9524d9ec4f5b3151717b5f3570241f7ec52b /lib/LuaHttp.cc
parent0eb604eeafd829e9aa31c7928d0bd18ff836d3bc (diff)
Adding Base85 code.
Diffstat (limited to 'lib/LuaHttp.cc')
-rw-r--r--lib/LuaHttp.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc
index 2a78391..a88c77c 100644
--- a/lib/LuaHttp.cc
+++ b/lib/LuaHttp.cc
@@ -22,6 +22,7 @@
#include "LuaHandle.h"
#include "LuaTask.h"
#include "Base64.h"
+#include "Base85.h"
#include "HashFunction.h"
#include "RandISAAC.h"
@@ -120,6 +121,9 @@ enum HttpResponse_functions_t {
HTTPRESPONSE_BASE64_ENCODE,
HTTPRESPONSE_BASE64_DECODE,
HTTPRESPONSE_BASE64_DECODE_BIN,
+ HTTPRESPONSE_BASE85_ENCODE,
+ HTTPRESPONSE_BASE85_DECODE,
+ HTTPRESPONSE_BASE85_DECODE_BIN,
HTTPRESPONSE_MD5,
HTTPRESPONSE_SHA1,
HTTPRESPONSE_SHA256,
@@ -137,6 +141,9 @@ struct lua_functypes_t HttpResponse_functions[] = {
{ 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_BASE85_ENCODE, "Base85Encode", 1, 1, { BLUA_STRING | BLUA_OBJECT } },
+ { HTTPRESPONSE_BASE85_DECODE, "Base85Decode", 1, 1, { BLUA_STRING } },
+ { HTTPRESPONSE_BASE85_DECODE_BIN, "Base85DecodeBin", 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 } },
@@ -153,6 +160,9 @@ class sLua_HttpResponse : public Base {
DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_ENCODE);
DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE);
DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE_BIN);
+ DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE85_ENCODE);
+ DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE85_DECODE);
+ DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE85_DECODE_BIN);
DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_MD5);
DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1);
DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256);
@@ -177,6 +187,9 @@ void LuaHttpResponse::pushstatics(Lua * L) throw (GeneralException) {
PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_ENCODE);
PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE);
PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE_BIN);
+ PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE85_ENCODE);
+ PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE85_DECODE);
+ PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE85_DECODE_BIN);
PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_MD5);
PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1);
PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256);
@@ -331,6 +344,38 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller)
free(enc_t);
}
break;
+ case HTTPRESPONSE_BASE85_ENCODE:
+ if (L->isstring()) {
+ dec = L->tostring();
+ dec_t = dec.to_charp();
+ L->push(Base85::encode(dec_t, dec.strlen()));
+ } else {
+ Handle * hdata = L->recast<Handle>(1);
+ int size = hdata->GetSize();
+ char * data = (char *) malloc(size);
+ hdata->read(data, size);
+ L->push(Base85::encode(data, size));
+ free(data);
+ }
+ r = 1;
+ break;
+ case HTTPRESPONSE_BASE85_DECODE:
+ enc_t = (char *) Base85::decode(L->tostring(), &l);
+ enc_t[l] = 0;
+ L->push(enc_t, l);
+ free(enc_t);
+ r = 1;
+ break;
+ case HTTPRESPONSE_BASE85_DECODE_BIN:
+ {
+ Handle * out = lua_recast<Handle>(L, 2);
+ if (!out)
+ L->error("Need an output handle to Base85DecodeBin");
+ enc_t = (char *) Base85::decode(L->tostring(1), &l);
+ out->write(enc_t, l);
+ free(enc_t);
+ }
+ break;
case HTTPRESPONSE_MD5:
if (L->isstring()) {
dec = L->tostring();