[Reconnoiter-devel] [reconnoiter commit] r895 - trunk/src/modules

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Mon Sep 28 21:46:11 EDT 2009


Author: jesus
Date: 2009-09-28 21:46:10 -0400 (Mon, 28 Sep 2009)
New Revision: 895

Modified:
   trunk/src/modules/lua_noit.c
Log:
wrap base64 in lua

Modified: trunk/src/modules/lua_noit.c
===================================================================
--- trunk/src/modules/lua_noit.c	2009-09-29 01:00:31 UTC (rev 894)
+++ trunk/src/modules/lua_noit.c	2009-09-29 01:46:10 UTC (rev 895)
@@ -52,6 +52,7 @@
 #include "noit_check_tools.h"
 #include "utils/noit_log.h"
 #include "utils/noit_str.h"
+#include "utils/noit_b64.h"
 #include "eventer/eventer.h"
 #include "lua_noit.h"
 
@@ -693,6 +694,37 @@
   return 0;
 }
 static int
+nl_base64_decode(lua_State *L) {
+  size_t inlen, decoded_len;
+  const char *message;
+  unsigned char *decoded;
+
+  if(lua_gettop(L) != 1) luaL_error(L, "bad call to noit.decode");
+
+  message = lua_tolstring(L, 1, &inlen);
+  decoded = malloc(MAX(1,inlen));
+  if(!decoded) luaL_error(L, "out-of-memory");
+  decoded_len = noit_b64_decode(message, inlen, decoded, MAX(1,inlen));
+  lua_pushlstring(L, (char *)decoded, decoded_len);
+  return 1;
+}
+static int
+nl_base64_encode(lua_State *L) {
+  size_t inlen, encoded_len;
+  const unsigned char *message;
+  char *encoded;
+
+  if(lua_gettop(L) != 1) luaL_error(L, "bad call to noit.encode");
+
+  message = (const unsigned char *)lua_tolstring(L, 1, &inlen);
+  encoded_len = (((inlen + 2) / 3) * 4) + 1;
+  encoded = malloc(encoded_len);
+  if(!encoded) luaL_error(L, "out-of-memory");
+  encoded_len = noit_b64_encode(message, inlen, encoded, encoded_len);
+  lua_pushlstring(L, (char *)encoded, encoded_len);
+  return 1;
+}
+static int
 nl_gettimeofday(lua_State *L) {
   struct timeval now;
   gettimeofday(&now, NULL);
@@ -1194,6 +1226,8 @@
   { "gettimeofday", nl_gettimeofday },
   { "socket", nl_socket },
   { "log", nl_log },
+  { "base64_decode", nl_base64_decode },
+  { "base64_encode", nl_base64_encode },
   { "pcre", nl_pcre },
   { "socket_ipv6", nl_socket_ipv6 },
   { "gunzip", nl_gunzip },



More information about the Reconnoiter-devel mailing list