Comparing version 0.8.2 to 0.8.3
@@ -27,3 +27,3 @@ var crypto = require('crypto'); | ||
this.secretKey = null; | ||
var self = this; | ||
this.ssl = config.ssl || false; | ||
}; | ||
@@ -47,2 +47,12 @@ | ||
con.on('connect', function() { | ||
if (self.ssl) { | ||
con.requestSsl(); | ||
} else { | ||
con.startup({ | ||
user: self.user, | ||
database: self.database | ||
}); | ||
} | ||
}); | ||
con.on('sslconnect', function() { | ||
con.startup({ | ||
@@ -49,0 +59,0 @@ user: self.user, |
@@ -20,2 +20,3 @@ var net = require('net'); | ||
this.writer = new Writer(); | ||
this.checkSslResponse = false; | ||
}; | ||
@@ -41,10 +42,38 @@ | ||
}); | ||
this.on('sslresponse', function(msg) { | ||
if (msg.text == 0x53) { | ||
var tls = require('tls'); | ||
self.stream.removeAllListeners(); | ||
self.stream = tls.connect({ socket: self.stream, servername: host, rejectUnauthorized: true }); | ||
self.stream.on('data', function(buffer) { | ||
self.setBuffer(buffer); | ||
var msg; | ||
while(msg = self.parseMessage()) { | ||
self.emit('message', msg); | ||
self.emit(msg.name, msg); | ||
} | ||
}); | ||
self.stream.on('error', function(error) { | ||
self.emit('error', error); | ||
}); | ||
self.emit('sslconnect'); | ||
} else { | ||
throw new Error("The server doesn't support SSL/TLS connections."); | ||
} | ||
}); | ||
this.stream.on('data', function(buffer) { | ||
self.setBuffer(buffer); | ||
var msg; | ||
while(msg = self.parseMessage()) { | ||
self.emit('message', msg); | ||
self.emit(msg.name, msg); | ||
if (self.checkSslResponse) { | ||
while(msg = self.readSslResponse()) { | ||
self.emit('message', msg); | ||
self.emit(msg.name, msg); | ||
} | ||
} else { | ||
while(msg = self.parseMessage()) { | ||
self.emit('message', msg); | ||
self.emit(msg.name, msg); | ||
} | ||
} | ||
@@ -58,2 +87,18 @@ }); | ||
p.requestSsl = function(config) { | ||
this.checkSslResponse = true; | ||
var bodyBuffer = this.writer | ||
.addInt16(0x04D2) | ||
.addInt16(0x162F).flush(); | ||
var length = bodyBuffer.length + 4; | ||
var buffer = new Writer() | ||
.addInt32(length) | ||
.add(bodyBuffer) | ||
.join(); | ||
this.stream.write(buffer); | ||
} | ||
p.startup = function(config) { | ||
@@ -231,2 +276,12 @@ var bodyBuffer = this.writer | ||
p.readSslResponse = function() { | ||
var remaining = this.buffer.length - (this.offset); | ||
if(remaining < 1) { | ||
this.lastBuffer = this.buffer; | ||
this.lastOffset = this.offset; | ||
return false; | ||
} | ||
return { name: 'sslresponse', text: this.buffer[this.offset++] }; | ||
}; | ||
p.parseMessage = function() { | ||
@@ -233,0 +288,0 @@ var remaining = this.buffer.length - (this.offset); |
@@ -122,5 +122,28 @@ var arrayParser = require(__dirname + "/arrayParser.js"); | ||
var parseByteA = function(val) { | ||
return new Buffer(val.replace(/\\([0-7]{3})/g, function (full_match, code) { | ||
return String.fromCharCode(parseInt(code, 8)); | ||
}).replace(/\\\\/g, "\\"), "binary"); | ||
if(/^\\x/.test(val)){ | ||
// new 'hex' style response (pg >9.0) | ||
return new Buffer(val.substr(2), 'hex'); | ||
}else{ | ||
out = "" | ||
i = 0 | ||
while(i < val.length){ | ||
if(val[i] != "\\"){ | ||
out += val[i] | ||
++i | ||
}else{ | ||
if(val.substr(i+1,3).match(/[0-7]{3}/)){ | ||
out += String.fromCharCode(parseInt(val.substr(i+1,3),8)) | ||
i += 4 | ||
}else{ | ||
backslashes = 1 | ||
while(i+backslashes < val.length && val[i+backslashes] == "\\") | ||
backslashes++ | ||
for(k=0; k<Math.floor(backslashes/2); ++k) | ||
out += "\\" | ||
i += Math.floor(backslashes / 2) * 2 | ||
} | ||
} | ||
} | ||
return new Buffer(out,"binary"); | ||
} | ||
} | ||
@@ -127,0 +150,0 @@ |
{ "name": "pg", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "PostgreSQL client - pure javascript & libpq with the same API", | ||
@@ -17,2 +17,3 @@ "keywords" : ["postgres", "pg", "libpq", "postgre", "database", "rdbms"], | ||
"test" : "make test-all connectionString=pg://postgres@localhost:5432/postgres", | ||
"prepublish": "rm -r build || (exit 0)", | ||
"install" : "node-gyp rebuild || (exit 0)" | ||
@@ -19,0 +20,0 @@ }, |
var helper = require(__dirname + '/test-helper'); | ||
test('emits notice message', function() { | ||
//TODO this doesn't work on all versions of postgres | ||
return false; | ||
var client = helper.client(); | ||
@@ -4,0 +6,0 @@ client.query('create temp table boom(id serial, size integer)'); |
@@ -34,3 +34,3 @@ //make assert a global... | ||
}); | ||
},2000); | ||
},5000); | ||
@@ -127,3 +127,3 @@ item.once(eventName, function() { | ||
assert.ok(executed, "Expected execution of function to be fired"); | ||
}, timeout || 2000) | ||
}, timeout || 5000) | ||
@@ -174,3 +174,3 @@ return function(err, queryResult) { | ||
var Sink = function(expected, timeout, callback) { | ||
var defaultTimeout = 1000; | ||
var defaultTimeout = 5000; | ||
if(typeof timeout == 'function') { | ||
@@ -177,0 +177,0 @@ callback = timeout; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
223214
6018
70
6