summaryrefslogtreecommitdiff
path: root/backend/node
authorMichael Krelin <hacker@klever.net>2014-06-29 19:56:49 (UTC)
committer Michael Krelin <hacker@klever.net>2014-06-29 20:48:23 (UTC)
commitd21898d430781387bc128f83e6f8aead1149a4e5 (patch) (side-by-side diff)
tree15809c4544128bd8a5723cdf96f2b066928edcba /backend/node
parenta90f522c1e06149420a14100f34b252d7b1119c4 (diff)
downloadclipperz-d21898d430781387bc128f83e6f8aead1149a4e5.zip
clipperz-d21898d430781387bc128f83e6f8aead1149a4e5.tar.gz
clipperz-d21898d430781387bc128f83e6f8aead1149a4e5.tar.bz2
fix a typo in session store implementation
Diffstat (limited to 'backend/node') (more/less context) (show whitespace changes)
-rw-r--r--backend/node/src/clipperz.js2
1 files changed, 1 insertions, 1 deletions
diff --git a/backend/node/src/clipperz.js b/backend/node/src/clipperz.js
index c51b0bc..5b4df0a 100644
--- a/backend/node/src/clipperz.js
+++ b/backend/node/src/clipperz.js
@@ -1,89 +1,89 @@
var FS = require('fs');
var CRYPTO = require('crypto');
var BIGNUM = require('bignum');
var ASYNC = require('async');
var express_store = require('express-session').Store;
function clipperz_hash(v) {
return CRYPTO.createHash('sha256').update(
CRYPTO.createHash('sha256').update(v).digest('binary')
).digest('hex');
};
function clipperz_random() {
for(var r = '';r.length<64;r+=''+BIGNUM(Math.floor(Math.random()*1e18)).toString(16));
return r.substr(0,64);
};
function clipperz_store(PG) {
var rv = function(o) { express_store.call(this,o); }
rv.prototype.get = function(sid,cb) { PG.Q(
"SELECT s_data FROM clipperz.thesession WHERE s_id=$1",[sid],
function(e,r) { cb(e,(e||!r.rowCount)?null:JSON.parse(r.rows[0].s_data)); }
) };
rv.prototype.set = function(sid,data,cb) {
var d = JSON.stringify(data);
PG.Q(
"UPDATE clipperz.thesession SET s_data=$1, s_mtime=current_timestamp"
+" WHERE s_id=$2",[d,sid], function(e,r) {
if(e) return cb(e);
if(r.rowCount) return cb();
PG.Q("INSERT INTO clipperz.thesession (s_id,s_data) VALUES ($1,$2)",[sid,d],cb);
});
};
rv.prototype.destroy = function(sid,cb) { PG.Q(
"DELETE FROM clipperz.thesession WHERE s_id=$1",[sid],cb
) };
rv.prototype.length = function(cb) { PG.Q(
"SELECT count(*) AS c FROM clipperz.thesession", function(e,r) {
cb(e,e?null:r.rows[0].c);
}
) };
- rv.prototype.length = function(cb) { PQ.Q(
+ rv.prototype.clear = function(cb) { PQ.Q(
"DELETE FROM clipperz.thesession", cb
) };
rv.prototype.__proto__ = express_store.prototype;
return rv;
}
var srp_g = BIGNUM(2);
var srp_n = BIGNUM("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3",16);
var n123 = '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00';
var CLIPPERZ = module.exports = function(CONFIG) {
var LOGGER = CONFIG.logger||{trace:function(){}};
var PG = {
url: CONFIG.psql,
PG: require('pg').native,
Q: function(q,a,cb) {
if('function'===typeof a) cb=a,a=[];
LOGGER.trace({query:q,args:a},'SQL: %s',q);
PG.PG.connect(PG.url,function(e,C,D) {
if(e) return cb(e);
var t0=new Date();
C.query(q,a,function(e,r) {
var t1=new Date(), dt=t1-t0;
D();
LOGGER.trace({query:q,args:a,ms:dt,rows:r&&r.rowCount,err:e},"SQL query '%s' took %dms",q,dt);
cb(e,r);
});
});
},
T: function(cb) {
PG.PG.connect(PG.url,function(e,C,D) {
if(e) return cb(e);
C.query('BEGIN',function(e){
if(e) return D(),cb(e);
LOGGER.trace('SQL: transaction begun');
cb(null,{
Q: function(q,a,cb) {
LOGGER.trace({query:q,args:a},'SQL: %s',q);
if(this.over) return cb(new Error('game over'));
if('function'===typeof a) cb=a,a=[];
var t0=new Date();
C.query(q,a,function(e,r) {
var t1=new Date(), dt=t1-t0;
LOGGER.trace({query:q,args:a,ms:dt,rows:r&&r.rowCount,err:e},"SQL query '%s' took %dms",q,dt);
cb(e,r);