diff options
-rw-r--r-- | lib/LuaHttp.cc | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index 8284537..cfa26da 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaHttp.cc,v 1.28 2008-07-16 16:50:24 pixel Exp $ */ +/* $Id: LuaHttp.cc,v 1.29 2008-07-18 14:02:39 pixel Exp $ */ #include "Domain.h" #include "LuaHttp.h" @@ -25,6 +25,7 @@ #include "LuaTask.h" #include "Base64.h" #include "HashFunction.h" +#include "RandISAAC.h" class LuaDomain : public Domain { public: @@ -123,6 +124,7 @@ enum HttpResponse_functions_t { HTTPRESPONSE_MD5, HTTPRESPONSE_SHA1, HTTPRESPONSE_SHA256, + HTTPRESPONSE_GENTICKET, }; struct lua_functypes_t HttpResponse_methods[] = { @@ -138,6 +140,7 @@ struct lua_functypes_t HttpResponse_functions[] = { { HTTPRESPONSE_MD5, "MD5", 1, 1, { BLUA_STRING } }, { HTTPRESPONSE_SHA1, "SHA1", 1, 1, { BLUA_STRING } }, { HTTPRESPONSE_SHA256, "SHA256", 1, 1, { BLUA_STRING } }, + { HTTPRESPONSE_GENTICKET, "GenTicket", 0, 1, { BLUA_NUMBER } }, { -1, 0, 0, 0, 0 } }; @@ -152,6 +155,7 @@ class sLua_HttpResponse : public Base { DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_MD5); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256); + DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_GENTICKET); private: static int HttpResponse_proceed(Lua * L, int n, HttpResponse * obj, int caller); static int HttpResponse_proceed_statics(Lua * L, int n, int caller); @@ -174,6 +178,7 @@ void LuaHttpResponse::pushstatics(Lua * L) throw (GeneralException) { PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_MD5); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256); + PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_GENTICKET); export_enum(L, HTTP_200_OK); export_enum(L, HTTP_301_PERM_MOVED); @@ -270,8 +275,16 @@ int sLua_HttpResponse::HttpResponse_proceed(Lua * L, int n, HttpResponse * res, return r; } +Random rand_gen; + +static const char ticket_chars[] = + "Q52VHu0JfkgQP2IjCpWIOldzwiGU1Ery49H7Z6tgYB8UpGuM4P@rFrBL_qvf3utE" + "dJRaXT8WVcvD6JSjcTNW9mqbnNRcoAlh7naMZJqDBRRgs@Tep_2p3@vcw1Bk7hex" + "D2Y_syYIWUbFyfXAiSN9xXn15evI4zXM9r1VHKbkAKfs8POd0nQ5Ch4adqumOhig" + "SlVTmQFC0AGMFY33ZENE6@CjlKatLox6xZ07jw5LePGy_LoHKbi8zStwOUkmoDsz"; + int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) { - int r = 0, l, i; + int r = 0, l, i, size = 32; String enc, dec; char * enc_t; const char * dec_t; @@ -335,6 +348,17 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) } r = 1; break; + case HTTPRESPONSE_GENTICKET: + if (n == 1) + size = L->tonumber(); + enc_t = (char *) malloc(size + 1); + for (i = 0; i < size; i++) { + enc_t[i] = ticket_chars[rand_gen.get() % 256]; + } + enc_t[size] = 0; + L->push(String(enc_t)); + r = 1; + break; } return r; |