mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
Merge branch 'master' of git@github.com:mongodb/mongo
This commit is contained in:
commit
62e40da7a0
@ -315,7 +315,7 @@ commonFiles += [ "util/background.cpp" , "util/mmap.cpp" , "util/sock.cpp" , "
|
||||
"util/thread_pool.cpp" ]
|
||||
commonFiles += Glob( "util/*.c" )
|
||||
commonFiles += Split( "client/connpool.cpp client/dbclient.cpp client/model.cpp client/parallel.cpp client/syncclusterconnection.cpp" )
|
||||
commonFiles += [ "scripting/engine.cpp" ]
|
||||
commonFiles += [ "scripting/engine.cpp" , "scripting/utils.cpp" ]
|
||||
|
||||
#mmap stuff
|
||||
|
||||
|
@ -26,7 +26,7 @@ namespace mongo {
|
||||
|
||||
typedef unsigned long long ScriptingFunction;
|
||||
typedef BSONObj (*NativeFunction) ( const BSONObj &args );
|
||||
|
||||
|
||||
class Scope : boost::noncopyable {
|
||||
public:
|
||||
Scope();
|
||||
@ -117,6 +117,8 @@ namespace mongo {
|
||||
static int _numScopes;
|
||||
};
|
||||
|
||||
void installGlobalUtils( Scope& scope );
|
||||
|
||||
class ScriptEngine : boost::noncopyable {
|
||||
public:
|
||||
ScriptEngine();
|
||||
@ -126,6 +128,7 @@ namespace mongo {
|
||||
Scope *s = createScope();
|
||||
if ( s && _scopeInitCallback )
|
||||
_scopeInitCallback( *s );
|
||||
installGlobalUtils( *s );
|
||||
return s;
|
||||
}
|
||||
|
||||
|
36
scripting/utils.cpp
Normal file
36
scripting/utils.cpp
Normal 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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ Mongo.prototype.getDB = function( name ){
|
||||
|
||||
Mongo.prototype.getDBs = function(){
|
||||
var res = this.getDB( "admin" ).runCommand( { "listDatabases" : 1 } );
|
||||
assert( res.ok == 1 , "listDatabases failed" );
|
||||
assert( res.ok == 1 , "listDatabases failed:" + tojson( res ) );
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
|
||||
#include "../client/dbclient.h"
|
||||
#include "../util/processinfo.h"
|
||||
#include "../util/md5.hpp"
|
||||
#include "utils.h"
|
||||
|
||||
extern const char * jsconcatcode_server;
|
||||
@ -139,13 +138,6 @@ namespace mongo {
|
||||
return b.obj();
|
||||
}
|
||||
|
||||
BSONObj JSVersion( const BSONObj& args ){
|
||||
cout << "version: " << versionString << endl;
|
||||
if ( strstr( versionString , "+" ) )
|
||||
printGitVersion();
|
||||
return BSONObj();
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
@ -474,19 +466,6 @@ namespace mongo {
|
||||
void KillMongoProgramInstances() {}
|
||||
#endif
|
||||
|
||||
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 ) );
|
||||
}
|
||||
|
||||
unsigned _randomSeed;
|
||||
|
||||
BSONObj JSSrand( const BSONObj &a ) {
|
||||
@ -512,8 +491,6 @@ namespace mongo {
|
||||
scope.injectNative( "sleep" , JSSleep );
|
||||
scope.injectNative( "quit", Quit );
|
||||
scope.injectNative( "getMemInfo" , JSGetMemInfo );
|
||||
scope.injectNative( "version" , JSVersion );
|
||||
scope.injectNative( "hex_md5" , jsmd5 );
|
||||
scope.injectNative( "_srand" , JSSrand );
|
||||
scope.injectNative( "_rand" , JSRand );
|
||||
#if !defined(_WIN32)
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include "../scripting/engine.h"
|
||||
|
||||
namespace mongo {
|
||||
|
||||
|
||||
namespace shellUtils {
|
||||
|
||||
extern std::string _dbConnect;
|
||||
@ -13,7 +13,7 @@ namespace mongo {
|
||||
|
||||
void RecordMyLocation( const char *_argv0 );
|
||||
void installShellUtils( Scope& scope );
|
||||
|
||||
|
||||
// Scoped management of mongo program instances. Simple implementation:
|
||||
// destructor kills all mongod instances created by the shell.
|
||||
struct MongoProgramScope {
|
||||
|
Loading…
Reference in New Issue
Block a user