0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00
mongodb/scripting/utils.cpp

63 lines
1.8 KiB
C++
Raw Normal View History

2010-01-28 18:21:56 +01:00
// utils.cpp
/*
* Copyright (C) 2010 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2010-01-28 18:21:56 +01:00
2010-04-27 21:27:52 +02:00
#include "pch.h"
2010-01-28 18:21:56 +01:00
#include "engine.h"
#include "../util/md5.hpp"
#include "../util/version.h"
2010-01-28 18:21:56 +01:00
namespace mongo {
2010-09-15 00:53:09 +02:00
void installBenchmarkSystem( Scope& scope );
2011-01-04 06:40:41 +01:00
BSONObj jsmd5( const BSONObj &a ) {
2010-01-28 18:21:56 +01:00
uassert( 10261 , "js md5 needs a string" , a.firstElement().type() == String );
const char * s = a.firstElement().valuestrsafe();
2011-01-04 06:40:41 +01:00
2010-01-28 18:21:56 +01:00
md5digest d;
md5_state_t st;
md5_init(&st);
md5_append( &st , (const md5_byte_t*)s , strlen( s ) );
md5_finish(&st, d);
2011-01-04 06:40:41 +01:00
2010-01-28 18:21:56 +01:00
return BSON( "" << digestToString( d ) );
}
2011-01-04 06:40:41 +01:00
BSONObj JSVersion( const BSONObj& args ) {
2010-01-28 18:21:56 +01:00
cout << "version: " << versionString << endl;
if ( strstr( versionString , "+" ) )
printGitVersion();
return BSONObj();
}
2010-09-15 00:53:09 +02:00
// ---------------------------------
// ---- installer --------
// ---------------------------------
2011-01-04 06:40:41 +01:00
void installGlobalUtils( Scope& scope ) {
2010-01-28 18:21:56 +01:00
scope.injectNative( "hex_md5" , jsmd5 );
scope.injectNative( "version" , JSVersion );
2010-09-15 00:53:09 +02:00
installBenchmarkSystem( scope );
2010-01-28 18:21:56 +01:00
}
}
2011-01-04 06:40:41 +01:00
2010-01-28 18:21:56 +01:00