Show
Ignore:
Timestamp:
02/02/11 01:45:35 (3 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1296611135 +0000
git-parent:

[87e8a7c5242cb8108f494d787f6548c873e82743]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1296611135 +0000
Message:

fixes #346

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/modules/lua_noit.c

    r68fdcd3 r1774a2d  
    5555#include "utils/noit_log.h" 
    5656#include "utils/noit_str.h" 
     57#include "utils/noit_b32.h" 
    5758#include "utils/noit_b64.h" 
    5859#include "eventer/eventer.h" 
     
    984985  lua_pop(L, 1); /* "string" table */ 
    985986  return 0; 
     987} 
     988static int 
     989nl_base32_decode(lua_State *L) { 
     990  size_t inlen, decoded_len; 
     991  const char *message; 
     992  unsigned char *decoded; 
     993 
     994  if(lua_gettop(L) != 1) luaL_error(L, "bad call to noit.decode"); 
     995 
     996  message = lua_tolstring(L, 1, &inlen); 
     997  decoded = malloc(MAX(1,inlen)); 
     998  if(!decoded) luaL_error(L, "out-of-memory"); 
     999  decoded_len = noit_b32_decode(message, inlen, decoded, MAX(1,inlen)); 
     1000  lua_pushlstring(L, (char *)decoded, decoded_len); 
     1001  return 1; 
     1002} 
     1003static int 
     1004nl_base32_encode(lua_State *L) { 
     1005  size_t inlen, encoded_len; 
     1006  const unsigned char *message; 
     1007  char *encoded; 
     1008 
     1009  if(lua_gettop(L) != 1) luaL_error(L, "bad call to noit.encode"); 
     1010 
     1011  message = (const unsigned char *)lua_tolstring(L, 1, &inlen); 
     1012  encoded_len = (((inlen + 7) / 5) * 8) + 1; 
     1013  encoded = malloc(encoded_len); 
     1014  if(!encoded) luaL_error(L, "out-of-memory"); 
     1015  encoded_len = noit_b32_encode(message, inlen, encoded, encoded_len); 
     1016  lua_pushlstring(L, (char *)encoded, encoded_len); 
     1017  return 1; 
    9861018} 
    9871019static int 
     
    18251857  { "dns", nl_dns_lookup }, 
    18261858  { "log", nl_log }, 
     1859  { "base32_decode", nl_base32_decode }, 
     1860  { "base32_encode", nl_base32_encode }, 
    18271861  { "base64_decode", nl_base64_decode }, 
    18281862  { "base64_encode", nl_base64_encode },