node-firebird 1.1.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/node.js.yml +45 -10
- package/ENCRYPTION_CALLBACK.md +152 -0
- package/PR_SUMMARY.md +139 -0
- package/README.md +80 -17
- package/Roadmap.md +80 -0
- package/lib/index.d.ts +16 -2
- package/lib/index.js +1 -1
- package/lib/pool.js +83 -82
- package/lib/srp.js +3 -0
- package/lib/wire/connection.js +1639 -1295
- package/lib/wire/const.js +16 -10
- package/lib/wire/database.js +224 -118
- package/lib/wire/eventConnection.js +94 -92
- package/lib/wire/fbEventManager.js +107 -72
- package/lib/wire/serialize.js +434 -408
- package/lib/wire/service.js +935 -931
- package/lib/wire/socket.js +175 -0
- package/lib/wire/statement.js +32 -31
- package/lib/wire/transaction.js +135 -107
- package/lib/wire/xsqlvar.js +339 -330
- package/package.json +5 -5
- package/srp.js +94 -0
- package/vitest.config.js +13 -0
- package/.travis.yml +0 -23
package/lib/pool.js
CHANGED
|
@@ -4,104 +4,105 @@
|
|
|
4
4
|
*
|
|
5
5
|
***************************************/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var self = this;
|
|
19
|
-
self.pending.push(callback);
|
|
20
|
-
self.check();
|
|
21
|
-
return self;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
Pool.prototype.check = function() {
|
|
7
|
+
class Pool {
|
|
8
|
+
constructor(attach, max, options) {
|
|
9
|
+
this.attach = attach;
|
|
10
|
+
this.internaldb = []; // connection created by the pool (for destroy)
|
|
11
|
+
this.pooldb = []; // available connection in the pool
|
|
12
|
+
this.dbinuse = 0; // connection currently in use into the pool
|
|
13
|
+
this._creating = 0; // connections currently being created
|
|
14
|
+
this.max = max || 4;
|
|
15
|
+
this.pending = [];
|
|
16
|
+
this.options = options;
|
|
17
|
+
}
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
get(callback) {
|
|
20
|
+
var self = this;
|
|
21
|
+
self.pending.push(callback);
|
|
22
|
+
self.check();
|
|
28
23
|
return self;
|
|
24
|
+
}
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
cb
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
26
|
+
check() {
|
|
27
|
+
var self = this;
|
|
28
|
+
if ((self.dbinuse + self._creating) >= self.max)
|
|
29
|
+
return self;
|
|
30
|
+
|
|
31
|
+
var cb = self.pending.shift();
|
|
32
|
+
if (!cb)
|
|
33
|
+
return self;
|
|
34
|
+
if (self.pooldb.length) {
|
|
35
|
+
self.dbinuse++;
|
|
36
|
+
cb(null, self.pooldb.shift());
|
|
37
|
+
} else {
|
|
38
|
+
self._creating++;
|
|
39
|
+
this.attach(self.options, function (err, db) {
|
|
40
|
+
self._creating--;
|
|
41
|
+
if (!err) {
|
|
42
|
+
self.dbinuse++;
|
|
43
|
+
self.internaldb.push(db);
|
|
44
|
+
db.on('detach', function () {
|
|
45
|
+
// also in pool (could be a twice call to detach)
|
|
46
|
+
if (self.pooldb.indexOf(db) !== -1 || self.internaldb.indexOf(db) === -1)
|
|
47
|
+
return;
|
|
48
|
+
// if not usable don't put in again in the pool and remove reference on it
|
|
49
|
+
if (db.connection._isClosed || db.connection._isDetach || db.connection._pooled === false)
|
|
50
|
+
self.internaldb.splice(self.internaldb.indexOf(db), 1);
|
|
51
|
+
else
|
|
52
|
+
self.pooldb.push(db);
|
|
49
53
|
|
|
50
|
-
if (db.connection._pooled)
|
|
51
54
|
self.dbinuse--;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// attach fail so not in the pool
|
|
56
|
-
self.dbinuse--;
|
|
57
|
-
}
|
|
55
|
+
self.check();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
cb(err, db);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
setImmediate(function() {
|
|
63
|
+
self.check();
|
|
60
64
|
});
|
|
65
|
+
|
|
66
|
+
return self;
|
|
61
67
|
}
|
|
62
|
-
setImmediate(function() {
|
|
63
|
-
self.check();
|
|
64
|
-
});
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
destroy(callback) {
|
|
70
|
+
var self = this;
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
var self = this;
|
|
72
|
+
var connectionCount = this.internaldb.length;
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
if (connectionCount === 0 && callback) {
|
|
75
|
+
callback();
|
|
76
|
+
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
function detachCallback(err) {
|
|
79
|
+
if (err) {
|
|
80
|
+
if (callback) {
|
|
81
|
+
callback(err);
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
77
85
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
callback(err);
|
|
86
|
+
connectionCount--;
|
|
87
|
+
if (connectionCount === 0 && callback) {
|
|
88
|
+
callback();
|
|
82
89
|
}
|
|
83
|
-
return;
|
|
84
90
|
}
|
|
85
91
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
this.internaldb.forEach(function(db) {
|
|
93
|
+
if (db.connection._pooled === false) {
|
|
94
|
+
detachCallback();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// check if the db is not free into the pool otherwise user should manual detach it
|
|
98
|
+
var _db_in_pool = self.pooldb.indexOf(db);
|
|
99
|
+
if (_db_in_pool !== -1) {
|
|
100
|
+
self.pooldb.splice(_db_in_pool, 1);
|
|
101
|
+
db.connection._pooled = false;
|
|
102
|
+
db.detach(detachCallback);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
90
105
|
}
|
|
91
|
-
|
|
92
|
-
this.internaldb.forEach(function(db) {
|
|
93
|
-
if (db.connection._pooled === false) {
|
|
94
|
-
detachCallback();
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
// check if the db is not free into the pool otherwise user should manual detach it
|
|
98
|
-
var _db_in_pool = self.pooldb.indexOf(db);
|
|
99
|
-
if (_db_in_pool !== -1) {
|
|
100
|
-
self.pooldb.splice(_db_in_pool, 1);
|
|
101
|
-
db.connection._pooled = false;
|
|
102
|
-
db.detach(detachCallback);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
+
}
|
|
106
107
|
|
|
107
108
|
module.exports = Pool;
|
package/lib/srp.js
CHANGED
|
@@ -181,6 +181,9 @@ function clientSession(user, password, salt, A, B, a) {
|
|
|
181
181
|
diff = diff.add(PRIME.N);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
// Note: While the SRP specification says exponents should not be reduced mod N,
|
|
185
|
+
// the Firebird engine implementation does reduce these exponents mod N.
|
|
186
|
+
// We must match the server's behavior for authentication to succeed.
|
|
184
187
|
var ux = u.multiply(x).mod(PRIME.N);
|
|
185
188
|
var aux = a.add(ux).mod(PRIME.N);
|
|
186
189
|
var sessionSecret = diff.modPow(aux, PRIME.N);
|