Changeset 2ea74a7d99056374e198cf3c9e124c223ddbc963

Show
Ignore:
Timestamp:
09/29/09 05:22:39 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1254201759 +0000
git-parent:

[4ff9608cdb1365ae2aa16b1e63e8fbcb4495b685]

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

need this for digest auth, refs #186

Files:

Legend:

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

    r6e62ef4 r2ea74a7  
    4646#include <libxml/xpath.h> 
    4747#include <libxml/tree.h> 
     48#include <openssl/md5.h> 
    4849 
    4950#include "noit_conf.h" 
     
    725726  return 1; 
    726727} 
     728static const char _hexchars[16] = 
     729  {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; 
     730static int 
     731nl_md5_hex(lua_State *L) { 
     732  int i; 
     733  MD5_CTX ctx; 
     734  size_t inlen; 
     735  const char *in; 
     736  unsigned char md5[MD5_DIGEST_LENGTH]; 
     737  char md5_hex[MD5_DIGEST_LENGTH * 2 + 1]; 
     738 
     739  if(lua_gettop(L) != 1) luaL_error(L, "bad call to noit.md5_hex"); 
     740  MD5_Init(&ctx); 
     741  in = lua_tolstring(L, 1, &inlen); 
     742  MD5_Update(&ctx, (const void *)in, (unsigned long)inlen); 
     743  MD5_Final(md5, &ctx); 
     744  for(i=0;i<MD5_DIGEST_LENGTH;i++) { 
     745    md5_hex[i*2] = _hexchars[(md5[i] >> 4) & 0xf]; 
     746    md5_hex[i*2+1] = _hexchars[md5[i] & 0xf]; 
     747  } 
     748  md5_hex[i*2] = '\0'; 
     749  lua_pushstring(L, md5_hex); 
     750  return 1; 
     751} 
    727752static int 
    728753nl_gettimeofday(lua_State *L) { 
     
    12291254  { "base64_decode", nl_base64_decode }, 
    12301255  { "base64_encode", nl_base64_encode }, 
     1256  { "md5_hex", nl_md5_hex }, 
    12311257  { "pcre", nl_pcre }, 
    12321258  { "socket_ipv6", nl_socket_ipv6 },