Comparison

mod_storage_mongodb/mod_storage_mongodb.lua @ 509:bf2ad6d6c778

mod_storage_mongodb: (un)lock globals around require; only auth if we need to
author James Callahan <james@chatid.com>
date Mon, 19 Dec 2011 10:36:50 +1100
parent 508:9831506dcfd6
child 813:2469f779b3f7
comparison
equal deleted inserted replaced
508:9831506dcfd6 509:bf2ad6d6c778
1 local next = next; 1 local next = next;
2 local setmetatable = setmetatable; 2 local setmetatable = setmetatable;
3 3
4 local params = assert ( module:get_option("mongodb") , "mongodb configuration not found" ); 4 local params = assert ( module:get_option("mongodb") , "mongodb configuration not found" );
5 5
6 prosody.unlock_globals();
6 local mongo = require "mongo"; 7 local mongo = require "mongo";
8 prosody.lock_globals();
7 9
8 local conn 10 local conn
9 11
10 local keyval_store = {}; 12 local keyval_store = {};
11 keyval_store.__index = keyval_store; 13 keyval_store.__index = keyval_store;
46 48
47 function driver:open(store, typ) 49 function driver:open(store, typ)
48 if not conn then 50 if not conn then
49 conn = assert ( mongo.Connection.New ( true ) ); 51 conn = assert ( mongo.Connection.New ( true ) );
50 assert ( conn:connect ( params.server ) ); 52 assert ( conn:connect ( params.server ) );
51 assert ( conn:auth ( params ) ); 53 if params.username then
54 assert ( conn:auth ( params ) );
55 end
52 end 56 end
53 57
54 if not typ then -- default key-value store 58 if not typ then -- default key-value store
55 return setmetatable({ store = store }, keyval_store); 59 return setmetatable({ store = store }, keyval_store);
56 end; 60 end;