make hex_md5 work server side

This commit is contained in:
Eliot Horowitz
2010-01-28 12:21:56 -05:00
parent 367de29611
commit 6df2f6c7e6
5 changed files with 43 additions and 27 deletions

36
scripting/utils.cpp Normal file
View File

@@ -0,0 +1,36 @@
// utils.cpp
#include "../stdafx.h"
#include "engine.h"
#include "../util/md5.hpp"
namespace mongo {
BSONObj jsmd5( const BSONObj &a ){
uassert( 10261 , "js md5 needs a string" , a.firstElement().type() == String );
const char * s = a.firstElement().valuestrsafe();
md5digest d;
md5_state_t st;
md5_init(&st);
md5_append( &st , (const md5_byte_t*)s , strlen( s ) );
md5_finish(&st, d);
return BSON( "" << digestToString( d ) );
}
BSONObj JSVersion( const BSONObj& args ){
cout << "version: " << versionString << endl;
if ( strstr( versionString , "+" ) )
printGitVersion();
return BSONObj();
}
void installGlobalUtils( Scope& scope ){
scope.injectNative( "hex_md5" , jsmd5 );
scope.injectNative( "version" , JSVersion );
}
}