oracledb 5.4.0 → 6.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/CHANGELOG.md +1 -1849
- package/LICENSE.txt +8 -222
- package/NOTICE.txt +1 -1
- package/README.md +38 -30
- package/SECURITY.md +38 -0
- package/THIRD_PARTY_LICENSES.txt +1 -1
- package/build/Release/oracledb-6.0.0-darwin-x64.node +0 -0
- package/build/Release/oracledb-6.0.0-darwin-x64.node-buildinfo.txt +1 -0
- package/build/Release/oracledb-6.0.0-js-buildinfo.txt +1 -0
- package/build/Release/oracledb-6.0.0-linux-arm64.node +0 -0
- package/build/Release/oracledb-6.0.0-linux-arm64.node-buildinfo.txt +1 -0
- package/build/Release/oracledb-6.0.0-linux-x64.node +0 -0
- package/build/Release/oracledb-6.0.0-linux-x64.node-buildinfo.txt +1 -0
- package/build/Release/oracledb-6.0.0-win32-x64.node +0 -0
- package/build/Release/oracledb-6.0.0-win32-x64.node-buildinfo.txt +1 -0
- package/examples/README.md +113 -0
- package/examples/dbconfig.js +100 -0
- package/examples/example.js +156 -0
- package/index.js +26 -0
- package/lib/aqDeqOptions.js +146 -7
- package/lib/aqEnqOptions.js +59 -7
- package/lib/aqMessage.js +118 -7
- package/lib/aqQueue.js +242 -53
- package/lib/connection.js +1324 -465
- package/lib/constants.js +203 -0
- package/lib/dbObject.js +346 -32
- package/lib/errors.js +781 -0
- package/lib/impl/aqDeqOptions.js +197 -0
- package/lib/impl/aqEnqOptions.js +89 -0
- package/lib/impl/aqMessage.js +134 -0
- package/lib/impl/aqQueue.js +81 -0
- package/lib/impl/connection.js +529 -0
- package/lib/impl/dbObject.js +159 -0
- package/lib/impl/index.js +59 -0
- package/lib/impl/lob.js +85 -0
- package/lib/impl/pool.js +195 -0
- package/lib/impl/resultset.js +223 -0
- package/lib/impl/sodaCollection.js +174 -0
- package/lib/impl/sodaDatabase.js +81 -0
- package/lib/impl/sodaDocCursor.js +63 -0
- package/lib/impl/sodaDocument.js +98 -0
- package/lib/impl/sodaOperation.js +109 -0
- package/lib/lob.js +156 -68
- package/lib/oracledb.js +1051 -257
- package/lib/pool.js +654 -465
- package/lib/poolStatistics.js +23 -9
- package/lib/queryStream.js +14 -7
- package/lib/resultset.js +292 -171
- package/lib/settings.js +191 -0
- package/lib/sodaCollection.js +214 -201
- package/lib/sodaDatabase.js +107 -71
- package/lib/sodaDocCursor.js +44 -32
- package/lib/sodaDocument.js +76 -14
- package/lib/sodaOperation.js +131 -118
- package/lib/thin/connection.js +1038 -0
- package/lib/thin/dbObject.js +629 -0
- package/lib/thin/index.js +40 -0
- package/lib/thin/lob.js +188 -0
- package/lib/thin/pool.js +481 -0
- package/lib/thin/protocol/buffer.js +1040 -0
- package/lib/thin/protocol/capabilities.js +116 -0
- package/lib/thin/protocol/constants.js +764 -0
- package/lib/thin/protocol/encryptDecrypt.js +185 -0
- package/lib/thin/protocol/messages/auth.js +348 -0
- package/lib/thin/protocol/messages/base.js +475 -0
- package/lib/thin/protocol/messages/commit.js +56 -0
- package/lib/thin/protocol/messages/dataType.js +382 -0
- package/lib/thin/protocol/messages/execute.js +312 -0
- package/lib/thin/protocol/messages/fetch.js +60 -0
- package/lib/thin/protocol/messages/index.js +53 -0
- package/lib/thin/protocol/messages/lobOp.js +200 -0
- package/lib/thin/protocol/messages/logOff.js +53 -0
- package/lib/thin/protocol/messages/ping.js +56 -0
- package/lib/thin/protocol/messages/protocol.js +78 -0
- package/lib/thin/protocol/messages/rollback.js +56 -0
- package/lib/thin/protocol/messages/sessionRelease.js +60 -0
- package/lib/thin/protocol/messages/withData.js +811 -0
- package/lib/thin/protocol/oson.js +660 -0
- package/lib/thin/protocol/packet.js +520 -0
- package/lib/thin/protocol/protocol.js +202 -0
- package/lib/thin/protocol/utils.js +88 -0
- package/lib/thin/resultSet.js +122 -0
- package/lib/thin/sqlnet/connStrategy.js +175 -0
- package/lib/thin/sqlnet/constants.js +199 -0
- package/lib/thin/sqlnet/ezConnectResolver.js +488 -0
- package/lib/thin/sqlnet/navNodes.js +870 -0
- package/lib/thin/sqlnet/networkSession.js +620 -0
- package/lib/thin/sqlnet/ntTcp.js +525 -0
- package/lib/thin/sqlnet/nvStrToNvPair.js +783 -0
- package/lib/thin/sqlnet/packet.js +405 -0
- package/lib/thin/sqlnet/paramParser.js +205 -0
- package/lib/thin/sqlnet/sessionAtts.js +160 -0
- package/lib/thin/statement.js +301 -0
- package/lib/thin/util.js +289 -0
- package/lib/transformer.js +250 -0
- package/lib/types.js +357 -0
- package/lib/util.js +194 -108
- package/lib/version.js +36 -0
- package/package/README.md +33 -30
- package/package/install.js +89 -64
- package/package/prunebinaries.js +60 -12
- package/package.json +3 -3
- package/build/Release/oracledb-5.4.0-darwin-x64.node +0 -0
- package/build/Release/oracledb-5.4.0-darwin-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-5.4.0-linux-x64.node +0 -0
- package/build/Release/oracledb-5.4.0-linux-x64.node-buildinfo.txt +0 -1
- package/build/Release/oracledb-5.4.0-win32-x64.node +0 -0
- package/build/Release/oracledb-5.4.0-win32-x64.node-buildinfo.txt +0 -1
|
@@ -0,0 +1,870 @@
|
|
|
1
|
+
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
|
|
2
|
+
|
|
3
|
+
//-----------------------------------------------------------------------------
|
|
4
|
+
//
|
|
5
|
+
// This software is dual-licensed to you under the Universal Permissive License
|
|
6
|
+
// (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
|
|
7
|
+
// 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
|
|
8
|
+
// either license.
|
|
9
|
+
//
|
|
10
|
+
// If you elect to accept the software under the Apache License, Version 2.0,
|
|
11
|
+
// the following applies:
|
|
12
|
+
//
|
|
13
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
// you may not use this file except in compliance with the License.
|
|
15
|
+
// You may obtain a copy of the License at
|
|
16
|
+
//
|
|
17
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
//
|
|
19
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
20
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
21
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
|
+
// See the License for the specific language governing permissions and
|
|
23
|
+
// limitations under the License.
|
|
24
|
+
//
|
|
25
|
+
//-----------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
'use strict';
|
|
28
|
+
|
|
29
|
+
const { findNVPairRecurse, createNVPair } = require('./nvStrToNvPair.js');
|
|
30
|
+
const errors = require("../../errors.js");
|
|
31
|
+
const os = require("os");
|
|
32
|
+
const net = require('net');
|
|
33
|
+
const dns = require('dns');
|
|
34
|
+
const dnsPromises = dns.promises;
|
|
35
|
+
|
|
36
|
+
const SchemaObjectFactoryInterface = {
|
|
37
|
+
ADDR:0,
|
|
38
|
+
ADDR_LIST:1,
|
|
39
|
+
DESC:2,
|
|
40
|
+
DESC_LIST:3,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Class representing Address Object
|
|
45
|
+
*/
|
|
46
|
+
class Address {
|
|
47
|
+
|
|
48
|
+
/** return the type of this SchemaObject */
|
|
49
|
+
isS() {
|
|
50
|
+
return SchemaObjectFactoryInterface.ADDR;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** initialize this object from the given string
|
|
54
|
+
* @param string the string
|
|
55
|
+
* Error thrown if invalid NV-string format (ie, bad parens)
|
|
56
|
+
* Error thrown if invalid syntax
|
|
57
|
+
* (ie, "(ADDRESS=(DESCRIPTION=...)) and ")
|
|
58
|
+
*/
|
|
59
|
+
initFromString(s) {
|
|
60
|
+
let nvp = createNVPair(s);
|
|
61
|
+
this.initFromNVPair(nvp);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** initialize this object from an NVPair
|
|
65
|
+
* @param nvp the NVPair
|
|
66
|
+
* Error thrown if invalid syntax
|
|
67
|
+
* (ie, "(ADDRESS=(DESCRIPTION=...))")
|
|
68
|
+
*/
|
|
69
|
+
initFromNVPair(nvp) {
|
|
70
|
+
if (nvp == null || !(nvp.name.toUpperCase() == "ADDRESS"))
|
|
71
|
+
errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
72
|
+
let protnvp = findNVPairRecurse(nvp, 'protocol');
|
|
73
|
+
let portnvp = findNVPairRecurse(nvp, 'port');
|
|
74
|
+
let hostnvp = findNVPairRecurse(nvp, 'host');
|
|
75
|
+
let httpsProxyNVP = findNVPairRecurse(nvp, 'https_proxy');
|
|
76
|
+
let httpsProxyPortNVP = findNVPairRecurse(nvp, 'https_proxy_port');
|
|
77
|
+
|
|
78
|
+
if (portnvp)
|
|
79
|
+
this.port = portnvp.atom;
|
|
80
|
+
|
|
81
|
+
if (hostnvp)
|
|
82
|
+
this.host = hostnvp.atom;
|
|
83
|
+
|
|
84
|
+
if (protnvp)
|
|
85
|
+
this.prot = protnvp.atom;
|
|
86
|
+
|
|
87
|
+
if (httpsProxyNVP)
|
|
88
|
+
this.httpsProxy = httpsProxyNVP.atom;
|
|
89
|
+
if (httpsProxyPortNVP)
|
|
90
|
+
this.httpsProxyPort = httpsProxyPortNVP.atom;
|
|
91
|
+
|
|
92
|
+
this.addr = nvp.toString();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** return the string representation of this object */
|
|
96
|
+
toString() {
|
|
97
|
+
return this.addr;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Class representing addressList object
|
|
103
|
+
*/
|
|
104
|
+
class AddressList {
|
|
105
|
+
constructor() {
|
|
106
|
+
this.children = new Array();
|
|
107
|
+
this.sourceRoute = false;
|
|
108
|
+
this.loadBalance = false;
|
|
109
|
+
this.failover = true;
|
|
110
|
+
}
|
|
111
|
+
/** return the type of this SchemaObject */
|
|
112
|
+
isS() {
|
|
113
|
+
return SchemaObjectFactoryInterface.ADDR_LIST;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** initialize this object from the given string
|
|
117
|
+
* @param string the string
|
|
118
|
+
* Error thrown if invalid NV-string format (ie, bad parens)
|
|
119
|
+
* Error thrown if invalid syntax
|
|
120
|
+
* (ie, "(ADDRESS=(DESCRIPTION=...))")
|
|
121
|
+
*/
|
|
122
|
+
initFromString(s) {
|
|
123
|
+
let nvp = createNVPair(s);
|
|
124
|
+
this.initFromNVPair(nvp);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** initialize this object from an NVPair
|
|
128
|
+
* @param nvp the NVPair
|
|
129
|
+
* Error thrown if invalid syntax
|
|
130
|
+
* (ie, "(ADDRESS=(DESCRIPTION=...))")
|
|
131
|
+
*/
|
|
132
|
+
initFromNVPair(nvp) {
|
|
133
|
+
/* for each child of "ADDRESS_LIST", create child or set SR/LB/FO */
|
|
134
|
+
this.children = [];
|
|
135
|
+
let childnv, child;
|
|
136
|
+
let listsize = nvp.getListSize();
|
|
137
|
+
if (listsize == 0) /* atom can not be valid */
|
|
138
|
+
errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
139
|
+
|
|
140
|
+
for (let i = 0; i < listsize; i++) {
|
|
141
|
+
childnv = nvp.getListElement(i);
|
|
142
|
+
if (childnv.name.toUpperCase() == "SOURCE_ROUTE") {
|
|
143
|
+
this.sourceRoute = (childnv.atom.toLowerCase() == "yes"
|
|
144
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
145
|
+
|| childnv.atom.toLowerCase() == "true");
|
|
146
|
+
} else if (childnv.name.toUpperCase() == "LOAD_BALANCE") {
|
|
147
|
+
this.loadBalance = (childnv.atom.toLowerCase() == "yes"
|
|
148
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
149
|
+
|| childnv.atom.toLowerCase() == "true");
|
|
150
|
+
} else if (childnv.name.toUpperCase() == "FAILOVER") {
|
|
151
|
+
this.failover = (childnv.atom.toLowerCase() == "yes"
|
|
152
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
153
|
+
|| childnv.atom.toLowerCase() == "true");
|
|
154
|
+
} else if (childnv.name.toUpperCase() == "ADDRESS") {
|
|
155
|
+
child = new NavAddress();
|
|
156
|
+
child.initFromNVPair(childnv);
|
|
157
|
+
this.children.push(child);
|
|
158
|
+
} else if (childnv.name.toUpperCase() == "ADDRESS_LIST") {
|
|
159
|
+
child = new NavAddressList();
|
|
160
|
+
child.initFromNVPair(childnv);
|
|
161
|
+
this.children.push(child);
|
|
162
|
+
} else errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
163
|
+
}
|
|
164
|
+
if (this.children.length == 0) errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
/** return the string representation of this object */
|
|
169
|
+
toString() {
|
|
170
|
+
let s = new String("");
|
|
171
|
+
if (this.children.size() < 1) // there is no address list without addresses
|
|
172
|
+
return s;
|
|
173
|
+
s += "(ADDRESS_LIST=";
|
|
174
|
+
|
|
175
|
+
for (let i = 0; i < this.children.size(); i++)
|
|
176
|
+
s += this.children[i].toString();
|
|
177
|
+
|
|
178
|
+
if (this.sourceRoute) s += "(SOURCE_ROUTE=yes)" + NavSchemaObject.HC;
|
|
179
|
+
if (this.loadBalance) s += "(LOAD_BALANCE=yes)";
|
|
180
|
+
if (!this.failover) s += "(FAILOVER=false)";
|
|
181
|
+
|
|
182
|
+
s += ")";
|
|
183
|
+
|
|
184
|
+
return s;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Class represnting description object
|
|
190
|
+
*/
|
|
191
|
+
class Description {
|
|
192
|
+
// description-level stuff
|
|
193
|
+
constructor() {
|
|
194
|
+
this.children = new Array();
|
|
195
|
+
this.sourceRoute = false;
|
|
196
|
+
this.loadBalance = false;
|
|
197
|
+
this.failover = true;
|
|
198
|
+
this.delayInMillis = -1;
|
|
199
|
+
this.params = {};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Return the type of this SchemaObject
|
|
204
|
+
*/
|
|
205
|
+
isS() {
|
|
206
|
+
return SchemaObjectFactoryInterface.DESC;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Initialize this object from the given string
|
|
211
|
+
*
|
|
212
|
+
* @param string
|
|
213
|
+
* the string
|
|
214
|
+
* Error rhrown if invalid NV-string format (ie, bad parens)
|
|
215
|
+
* Error thrown if invalid syntax (ie, "(ADDRESS=(DESCRIPTION=...))")
|
|
216
|
+
*/
|
|
217
|
+
initFromString(s) {
|
|
218
|
+
let nvp = createNVPair(s);
|
|
219
|
+
this.initFromNVPair(nvp);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** initialize this object from an NVPair
|
|
223
|
+
* @param nvp the NVPair
|
|
224
|
+
* Error thrown if invalid syntax
|
|
225
|
+
* (ie, "(ADDRESS=(DESCRIPTION=...))")
|
|
226
|
+
*/
|
|
227
|
+
//errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
228
|
+
initFromNVPair(nvp) {
|
|
229
|
+
let listsize = nvp.getListSize();
|
|
230
|
+
let childnv, child;
|
|
231
|
+
if (listsize == 0) // atom can not be valid
|
|
232
|
+
errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
233
|
+
|
|
234
|
+
for (let i = 0; i < listsize; i++) {
|
|
235
|
+
childnv = nvp.getListElement(i);
|
|
236
|
+
if (childnv.name.toUpperCase() == "SOURCE_ROUTE") {
|
|
237
|
+
this.sourceRoute = (childnv.atom.toLowerCase() == "yes"
|
|
238
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
239
|
+
|| childnv.atom.toLowerCase() == "true");
|
|
240
|
+
} else if (childnv.name.toUpperCase() == "LOAD_BALANCE") {
|
|
241
|
+
this.loadBalance = (childnv.atom.toLowerCase() == "yes"
|
|
242
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
243
|
+
|| childnv.atom.toLowerCase() == "true");
|
|
244
|
+
} else if (childnv.name.toUpperCase() == "FAILOVER") {
|
|
245
|
+
this.failover = (childnv.atom.toLowerCase() == "yes"
|
|
246
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
247
|
+
|| childnv.atom.toLowerCase() == "true");
|
|
248
|
+
} else if (childnv.name.toUpperCase() == "ADDRESS_LIST") {
|
|
249
|
+
child = new NavAddressList();
|
|
250
|
+
child.initFromNVPair(childnv);
|
|
251
|
+
this.children.push(child);
|
|
252
|
+
} else if (childnv.name.toUpperCase() == "ADDRESS") {
|
|
253
|
+
child = new NavAddress();
|
|
254
|
+
child.initFromNVPair(childnv);
|
|
255
|
+
this.children.push(child);
|
|
256
|
+
} else if (childnv.name.toUpperCase() == "CONNECT_DATA") {
|
|
257
|
+
let tmpnv;
|
|
258
|
+
let listsize = childnv.getListSize();
|
|
259
|
+
for (let i = 0; i < listsize; i++) {
|
|
260
|
+
tmpnv = childnv.getListElement(i);
|
|
261
|
+
if (tmpnv.name.toUpperCase() == "CONNECTION_ID_PREFIX") {
|
|
262
|
+
this.params.connectionIdPrefix = tmpnv.atom;
|
|
263
|
+
childnv.removeListElement(i);
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
this.connectData = childnv.valueToString();
|
|
268
|
+
} else if (childnv.name.toUpperCase() == "RETRY_DELAY") {
|
|
269
|
+
// Delay between retries.
|
|
270
|
+
// If no unit is provided, it is interpreted in seconds.
|
|
271
|
+
// The value is internally stored in milliseconds.
|
|
272
|
+
if (childnv.atom > 0)
|
|
273
|
+
this.delayInMillis = childnv.atom * 1000;
|
|
274
|
+
} else if (childnv.name.toUpperCase() == "RETRY_COUNT") {
|
|
275
|
+
this.retryCount = childnv.atom;
|
|
276
|
+
} else if (childnv.name.toUpperCase() == "CONNECTION_ID_PREFIX") {
|
|
277
|
+
this.conidPrefix = childnv.atom;
|
|
278
|
+
} else if (childnv.name.toUpperCase() == "CONNECT_TIMEOUT") {
|
|
279
|
+
if (childnv.atom > 0)
|
|
280
|
+
this.params.connectTimeout = childnv.atom;
|
|
281
|
+
} else if (childnv.name.toUpperCase() == "TRANSPORT_CONNECT_TIMEOUT") {
|
|
282
|
+
if (childnv.atom > 0)
|
|
283
|
+
this.params.transportConnectTimeout = childnv.atom;
|
|
284
|
+
} else if (childnv.name.toUpperCase() == "ENABLE") {
|
|
285
|
+
this.params.enable = childnv.atom;
|
|
286
|
+
} else if (childnv.name.toUpperCase() == "RECV_TIMEOUT") {
|
|
287
|
+
if (childnv.atom > 0) {
|
|
288
|
+
this.params.recvTimeout = childnv.atom;
|
|
289
|
+
}
|
|
290
|
+
} else if (childnv.name.toUpperCase() == "SDU") {
|
|
291
|
+
this.params.sdu = childnv.atom;
|
|
292
|
+
} else if (childnv.name.toUpperCase() == "EXPIRE_TIME") {
|
|
293
|
+
if (childnv.atom > 0)
|
|
294
|
+
this.params.expireTime = childnv.atom;
|
|
295
|
+
} else if (childnv.name.toUpperCase() == "SECURITY") {
|
|
296
|
+
let listsize = childnv.getListSize();
|
|
297
|
+
let tmpnv;
|
|
298
|
+
for (let i = 0; i < listsize; i++) {
|
|
299
|
+
tmpnv = childnv.getListElement(i);
|
|
300
|
+
if (tmpnv.name.toUpperCase() == "SSL_SERVER_CERT_DN") {
|
|
301
|
+
this.params.sslServerCertDN = tmpnv.valueToString();
|
|
302
|
+
} else if (tmpnv.name.toUpperCase() == "SSL_SERVER_DN_MATCH") {
|
|
303
|
+
this.params.sslServerDNMatch = (tmpnv.atom.toLowerCase() == "yes"
|
|
304
|
+
|| tmpnv.atom.toLowerCase() == "on"
|
|
305
|
+
|| tmpnv.atom.toLowerCase() == "true");
|
|
306
|
+
} else if ((tmpnv.name.toUpperCase() == "WALLET_LOCATION") || (tmpnv.name.toUpperCase() == "MY_WALLET_DIRECTORY")) {
|
|
307
|
+
this.params.walletLocation = tmpnv.atom;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
toString() {
|
|
314
|
+
let s = new String(""), child ;
|
|
315
|
+
|
|
316
|
+
// see if there are any endpoints
|
|
317
|
+
child = new String("");
|
|
318
|
+
for (let i = 0; i < this.children.size(); i++) {
|
|
319
|
+
child = this.children[i].toString();
|
|
320
|
+
if (!child == "")
|
|
321
|
+
s += child;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// some parameters make sense only if there are endpoints defined
|
|
325
|
+
if (!s == "" && this.sourceRoute)
|
|
326
|
+
s += "(SOURCE_ROUTE=yes)";
|
|
327
|
+
if (!s == "" && this.loadBalance)
|
|
328
|
+
s += "(LOAD_BALANCE=yes)";
|
|
329
|
+
if (!s == "" && !this.failover)
|
|
330
|
+
s += "(FAILOVER=false)";
|
|
331
|
+
if (!s.equals(""))
|
|
332
|
+
s = "(DESCRIPTION=" + s + ")";
|
|
333
|
+
|
|
334
|
+
return s;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Class representing DescriptionList object.
|
|
340
|
+
*/
|
|
341
|
+
class DescriptionList {
|
|
342
|
+
|
|
343
|
+
constructor() {
|
|
344
|
+
this.children = new Array();
|
|
345
|
+
this.sourceRoute = false;
|
|
346
|
+
this.loadBalance = true;
|
|
347
|
+
this.failover = true;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/** return the type of this SchemaObject */
|
|
351
|
+
isS() {
|
|
352
|
+
return SchemaObjectFactoryInterface.ADDR_LIST;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/** initialize this object from the given string
|
|
356
|
+
* @param string the string
|
|
357
|
+
* Error thrown if invalid NV-string format (ie, bad parens)
|
|
358
|
+
* Error thrown if invalid syntax
|
|
359
|
+
* (ie, "(ADDRESS=(DESCRIPTION=...))")
|
|
360
|
+
*/
|
|
361
|
+
initFromString(s) {
|
|
362
|
+
let nvp = createNVPair(s);
|
|
363
|
+
this.initFromNVPair(nvp);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** initialize this object from an NVPair
|
|
367
|
+
* @param nvp the NVPair
|
|
368
|
+
* Error thrown if invalid syntax
|
|
369
|
+
* (ie, "(ADDRESS=(DESCRIPTION=...))")
|
|
370
|
+
*/
|
|
371
|
+
initFromNVPair(nvp) {
|
|
372
|
+
let listsize = nvp.getListSize();
|
|
373
|
+
let child, childnv;
|
|
374
|
+
if (listsize == 0) /* atom can not be valid */
|
|
375
|
+
errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
376
|
+
|
|
377
|
+
for (let i = 0; i < listsize; i++) {
|
|
378
|
+
childnv = nvp.getListElement(i);
|
|
379
|
+
if (childnv.name.toUpperCase() == "SOURCE_ROUTE") {
|
|
380
|
+
this.sourceRoute = (childnv.atom.toLowerCase() == "yes"
|
|
381
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
382
|
+
|| childnv.atom.toLowerCase == "true");
|
|
383
|
+
} else if (childnv.name.toUpperCase() == "LOAD_BALANCE") {
|
|
384
|
+
this.loadBalance = (childnv.atom.toLowerCase() == "yes"
|
|
385
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
386
|
+
|| childnv.atom.toLowerCase() == "true");
|
|
387
|
+
} else if (childnv.name.toUpperCase() == "FAILOVER") {
|
|
388
|
+
this.failover = (childnv.atom.toLowerCase() == "yes"
|
|
389
|
+
|| childnv.atom.toLowerCase() == "on"
|
|
390
|
+
|| childnv.atom.toLowerCase() == "true");
|
|
391
|
+
} else if (childnv.name.toUpperCase() == "DESCRIPTION") {
|
|
392
|
+
child = new NavDescription();
|
|
393
|
+
child.initFromNVPair(childnv);
|
|
394
|
+
this.children.push(child);
|
|
395
|
+
} else errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
396
|
+
}
|
|
397
|
+
if (this.children.length == 0) errors.throwErr(errors.ERR_INVALID_CONNECT_STRING_SYNTAX);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/** return the string representation of this object */
|
|
401
|
+
toString() {
|
|
402
|
+
let s = new String("");
|
|
403
|
+
if (this.children.size() < 1) // no descr list without descriptions
|
|
404
|
+
return s;
|
|
405
|
+
|
|
406
|
+
let child = new String("");
|
|
407
|
+
for (let i = 0; i < this.children.size(); i++) {
|
|
408
|
+
child = this.children[i].toString();
|
|
409
|
+
if (!child.equals(""))
|
|
410
|
+
s += child;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// some parameters make sense only if there are endpoints defined
|
|
414
|
+
if (s.equals("") && this.sourceRoute) s += "(SOURCE_ROUTE=yes)";
|
|
415
|
+
if (s.equals("") && !this.loadBalance) s += "(LOAD_BALANCE=no)";
|
|
416
|
+
if (s.equals("") && !this.failover) s += "(FAILOVER=false)";
|
|
417
|
+
|
|
418
|
+
if (!s.equals("")) // no valid children were found
|
|
419
|
+
s = "(DESCRIPTION_LIST=" + s + ")";
|
|
420
|
+
|
|
421
|
+
return s;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Class that contains information about a possible connection.
|
|
431
|
+
*/
|
|
432
|
+
class ConnOption {
|
|
433
|
+
constructor() {
|
|
434
|
+
this.CNdata = new Array();
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
const NavSchemaObject = {
|
|
440
|
+
DEBUG: false,
|
|
441
|
+
SR: "(SOURCE_ROUTE=yes)",
|
|
442
|
+
HC: "(HOP_COUNT=0)",
|
|
443
|
+
LB: "(LOAD_BALANCE=yes)",
|
|
444
|
+
NFO: "(FAILOVER=false)",
|
|
445
|
+
CD: "(CONNECT_DATA=",
|
|
446
|
+
CID: `(CID=(PROGRAM=nodejs)(HOST=${os.hostname()})(USER=${os.userInfo().username}))`,
|
|
447
|
+
CONID: "(CONNECTION_ID="
|
|
448
|
+
};
|
|
449
|
+
const options = {
|
|
450
|
+
all:true,
|
|
451
|
+
};
|
|
452
|
+
/**
|
|
453
|
+
* Class that navigates the address node in the tree.
|
|
454
|
+
*/
|
|
455
|
+
class NavAddress extends Address {
|
|
456
|
+
constructor() {
|
|
457
|
+
super();
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Set the connection option to this address.
|
|
461
|
+
* @param {object} cs
|
|
462
|
+
*/
|
|
463
|
+
async navigate(cs) {
|
|
464
|
+
let addresses;
|
|
465
|
+
let nullHost = 0;
|
|
466
|
+
let needToCloseDescription = false;
|
|
467
|
+
if (!this.host) {
|
|
468
|
+
nullHost = 1;
|
|
469
|
+
this.host = os.hostname();
|
|
470
|
+
try {
|
|
471
|
+
await dnsPromises.lookup(this.host, options);
|
|
472
|
+
} catch {
|
|
473
|
+
this.host = 'localhost';
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
// Sometimes REDIRECT packets do not have DESCRIPTION
|
|
477
|
+
// this is for handling such conditions.
|
|
478
|
+
if (cs.getcurrentDescription() == null) {
|
|
479
|
+
cs.newConnectionDescription();
|
|
480
|
+
needToCloseDescription = true;
|
|
481
|
+
}
|
|
482
|
+
if (!net.isIP(this.host)) {
|
|
483
|
+
try {
|
|
484
|
+
addresses = await dnsPromises.lookup(this.host, options);
|
|
485
|
+
for (let addr in addresses) {
|
|
486
|
+
let co = new ConnOption();
|
|
487
|
+
co.hostname = this.host;
|
|
488
|
+
co.port = this.port;
|
|
489
|
+
co.protocol = this.prot;
|
|
490
|
+
co.httpsProxy = this.httpsProxy;
|
|
491
|
+
co.httpsProxyPort = this.httpsProxyPort;
|
|
492
|
+
co.desc = cs.getcurrentDescription();
|
|
493
|
+
co.CNdata.push(cs.sBuf.join(""));
|
|
494
|
+
if (nullHost == 1)
|
|
495
|
+
co.CNdata.push('(address=(protocol=' + this.prot + ')(host=' + this.host + ')(port=' + this.port + '))');
|
|
496
|
+
else
|
|
497
|
+
co.CNdata.push(this.toString());
|
|
498
|
+
co.host = addresses[addr].address;
|
|
499
|
+
co.addr = this.addr;
|
|
500
|
+
cs.getcurrentDescription().addConnectOption(co);
|
|
501
|
+
}
|
|
502
|
+
} catch {
|
|
503
|
+
// do nothing
|
|
504
|
+
}
|
|
505
|
+
} else {
|
|
506
|
+
let co = new ConnOption();
|
|
507
|
+
co.hostname = this.host;
|
|
508
|
+
co.port = this.port;
|
|
509
|
+
co.protocol = this.prot;
|
|
510
|
+
co.httpsProxy = this.httpsProxy;
|
|
511
|
+
co.httpsProxyPort = this.httpsProxyPort;
|
|
512
|
+
co.desc = cs.getcurrentDescription();
|
|
513
|
+
co.CNdata.push(cs.sBuf.join(""));
|
|
514
|
+
co.CNdata.push(this.toString());
|
|
515
|
+
co.host = this.host;
|
|
516
|
+
co.addr = this.addr;
|
|
517
|
+
cs.getcurrentDescription().addConnectOption(co);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (needToCloseDescription) {
|
|
521
|
+
cs.closeDescription();
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* AddToString is used to construct a string representation of the TNS
|
|
530
|
+
* Address. Constructing a string is mainly needed when source route is ON.
|
|
531
|
+
*/
|
|
532
|
+
addToString(cs) {
|
|
533
|
+
let NVString = this.toString();
|
|
534
|
+
let cOpts = new Array();
|
|
535
|
+
cOpts = cs.getcurrentDescription().getConnectOptions();
|
|
536
|
+
for (let i = 0;i < cOpts.length; i++) {
|
|
537
|
+
if (cOpts[i].done) {
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
cOpts[i].CNdata.push(NVString);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Class that navigates the addressList node in the tree.
|
|
547
|
+
*/
|
|
548
|
+
class NavAddressList extends AddressList {
|
|
549
|
+
constructor() {
|
|
550
|
+
super();
|
|
551
|
+
this.activeChildren = new Array();
|
|
552
|
+
this.sBuflength = 0;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Method decides how to traverse and sets the active children based on
|
|
557
|
+
* the loadbalancing, failover values.
|
|
558
|
+
* @param {object} cs
|
|
559
|
+
*/
|
|
560
|
+
async navigate(cs) {
|
|
561
|
+
await this.navigate2(cs, 0);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
async navigate2(cs, reCurCnt) {
|
|
565
|
+
reCurCnt++;
|
|
566
|
+
this.sBuflength = cs.sBuf.length;
|
|
567
|
+
cs.sBuf.push("(ADDRESS_LIST=");
|
|
568
|
+
if (this.sourceRoute) {
|
|
569
|
+
this.activeChildren = this.children;
|
|
570
|
+
await this.activeChildren[0].navigate(cs);
|
|
571
|
+
|
|
572
|
+
for (let i = 1; i < this.activeChildren.length; i++) {
|
|
573
|
+
this.activeChildren[i].addToString(cs);
|
|
574
|
+
}
|
|
575
|
+
} else { // SR is off
|
|
576
|
+
this.activeChildren = NavDescriptionList.setActiveChildren(this.children, this.failover,
|
|
577
|
+
this.loadBalance);
|
|
578
|
+
for (let i = 0; i < this.activeChildren.length; i++) {
|
|
579
|
+
if (this.getChildrenType(i) == 1) {
|
|
580
|
+
await this.activeChildren[i].navigate2(cs, reCurCnt);
|
|
581
|
+
} else {
|
|
582
|
+
await this.activeChildren[i].navigate(cs);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
this.closeNVPair(cs);
|
|
588
|
+
cs.sBuf.length = this.sBuflength;
|
|
589
|
+
|
|
590
|
+
}
|
|
591
|
+
addToString(cs) {
|
|
592
|
+
let NVString = this.toString();
|
|
593
|
+
let cOpts = new Array();
|
|
594
|
+
cOpts = cs.getcurrentDescription().getConnectOptions();
|
|
595
|
+
for (let i = 0;i < cOpts.length; i++) {
|
|
596
|
+
if (cOpts[i].done) {
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
cOpts[i].CNdata.push(NVString);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
getChildrenSize() {
|
|
605
|
+
let size = 0;
|
|
606
|
+
for (let i = 0; i < this.activeChildren.length; i++) {
|
|
607
|
+
if (this.getChildrenType(i) == 1) {
|
|
608
|
+
size += this.activeChildren[i].getChildrenSize();
|
|
609
|
+
} else {
|
|
610
|
+
size++;
|
|
611
|
+
}
|
|
612
|
+
if (this.sourceRoute)
|
|
613
|
+
return size;
|
|
614
|
+
}
|
|
615
|
+
return (size);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* get children type
|
|
620
|
+
*/
|
|
621
|
+
getChildrenType(childNum) {
|
|
622
|
+
return (this.activeChildren[childNum].isS());
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
*get child at a given pos
|
|
627
|
+
*/
|
|
628
|
+
getChild(childNum) {
|
|
629
|
+
return (this.children[childNum]);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
closeNVPair(cs) {
|
|
633
|
+
let cOpts = new Array();
|
|
634
|
+
let childS = this.getChildrenSize();
|
|
635
|
+
if (cs.getcurrentDescription() != null) {
|
|
636
|
+
cOpts = cs.getcurrentDescription().getConnectOptions();
|
|
637
|
+
let numChildren = 0;
|
|
638
|
+
let prevHost = null;
|
|
639
|
+
let prevPort = null;
|
|
640
|
+
for (let i = cOpts.length - 1 ; (i >= 0
|
|
641
|
+
&& !cOpts[i].done); i--) {
|
|
642
|
+
if (cOpts[i].hostname != prevHost || cOpts[i].port != prevPort)
|
|
643
|
+
numChildren++;
|
|
644
|
+
prevHost = cOpts[i].hostname;
|
|
645
|
+
prevPort = cOpts[i].port;
|
|
646
|
+
|
|
647
|
+
// close NV Pair for current active children
|
|
648
|
+
if ((numChildren > childS)) {
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (this.sourceRoute) {
|
|
653
|
+
cOpts[i].CNdata.push(NavSchemaObject.SR);
|
|
654
|
+
cOpts[i].CNdata.push(NavSchemaObject.HC);
|
|
655
|
+
cOpts[i].done = true;
|
|
656
|
+
}
|
|
657
|
+
// Always close the NV Pair with a ")"
|
|
658
|
+
cOpts[i].CNdata.push(")");
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Class that navigates the description node in a tree.
|
|
668
|
+
*/
|
|
669
|
+
class NavDescription extends Description {
|
|
670
|
+
constructor() {
|
|
671
|
+
super();
|
|
672
|
+
this.activeChildren = new Array();
|
|
673
|
+
this.descProcessed = 0;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Method decides how to traverse and sets the active children based on
|
|
678
|
+
* the loadbalancing, failover values. Also creates connection description
|
|
679
|
+
* object.
|
|
680
|
+
* @param {object} cs
|
|
681
|
+
*/
|
|
682
|
+
async navigate(cs) {
|
|
683
|
+
cs.sBuf.length = 0; //reset
|
|
684
|
+
cs.sBuf.push("(DESCRIPTION=");
|
|
685
|
+
let desc = cs.newConnectionDescription(); //connectiondescription
|
|
686
|
+
if (this.retryCount != null) {
|
|
687
|
+
cs.retryCount = this.getIntValue(this.retryCount, cs.retryCount);
|
|
688
|
+
desc.retryCount = cs.retryCount;
|
|
689
|
+
}
|
|
690
|
+
if (this.delayInMillis != -1) {
|
|
691
|
+
desc.delayInMillis = this.delayInMillis;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
desc.params = this.params;
|
|
695
|
+
|
|
696
|
+
if ('connectTimeout' in this.params) {
|
|
697
|
+
cs.sBuf.push("(CONNECT_TIMEOUT=" + this.params.connectTimeout + ")");
|
|
698
|
+
}
|
|
699
|
+
if ('transportConnectTimeout' in this.params) {
|
|
700
|
+
cs.sBuf.push("(TRANSPORT_CONNECT_TIMEOUT=" + this.params.transportConnectTimeout + ")");
|
|
701
|
+
}
|
|
702
|
+
if ('recvTimeout' in this.params) {
|
|
703
|
+
cs.sBuf.push("(RECV_TIMEOUT=" + this.params.recvTimeout + ")");
|
|
704
|
+
}
|
|
705
|
+
if ('sdu' in this.params) {
|
|
706
|
+
cs.sBuf.push("(SDU=" + this.params.sdu + ")");
|
|
707
|
+
}
|
|
708
|
+
if ('expireTime' in this.params) {
|
|
709
|
+
cs.sBuf.push("(EXPIRE_TIME=" + this.params.expireTime + ")");
|
|
710
|
+
}
|
|
711
|
+
if ('enable' in this.params) {
|
|
712
|
+
cs.sBuf.push("(ENABLE=" + this.params.enable + ")");
|
|
713
|
+
}
|
|
714
|
+
if (('sslServerCertDN' in this.params) || ('sslServerDNMatch' in this.params) || ('walletLocation' in this.params)) {
|
|
715
|
+
cs.sBuf.push("(SECURITY=");
|
|
716
|
+
if ('sslServerCertDN' in this.params) {
|
|
717
|
+
cs.sBuf.push("(SSL_SERVER_CERT_DN=" + this.params.sslServerCertDN + ")");
|
|
718
|
+
}
|
|
719
|
+
if ('sslServerDNMatch' in this.params) {
|
|
720
|
+
cs.sBuf.push("(SSL_SERVER_DN_MATCH=" + this.params.sslServerDNMatch + ")");
|
|
721
|
+
}
|
|
722
|
+
if ('walletLocation' in this.params) {
|
|
723
|
+
cs.sBuf.push("(WALLET_LOCATION=" + this.params.walletLocation + ")");
|
|
724
|
+
}
|
|
725
|
+
cs.sBuf.push(")");
|
|
726
|
+
}
|
|
727
|
+
if ('httpsProxyPort' in this.params) {
|
|
728
|
+
cs.sBuf.push("(HTTPS_PROXY_PORT=" + this.params.httpsProxyPort + ")");
|
|
729
|
+
}
|
|
730
|
+
if ('httpsProxy' in this.params) {
|
|
731
|
+
cs.sBuf.push("(HTTPS_PROXY=" + this.params.httpsProxy + ")");
|
|
732
|
+
}
|
|
733
|
+
if (!this.failover) {
|
|
734
|
+
cs.sBuf.push(NavSchemaObject.NFO);
|
|
735
|
+
}
|
|
736
|
+
if (!this.sourceRoute) {
|
|
737
|
+
// SR is off, navigate every child and close the NV Pair
|
|
738
|
+
this.activeChildren = NavDescriptionList.setActiveChildren(this.children, this.failover,
|
|
739
|
+
this.loadBalance);
|
|
740
|
+
for (let i = 0; i < this.activeChildren.length; i++) {
|
|
741
|
+
await this.activeChildren[i].navigate(cs);
|
|
742
|
+
}
|
|
743
|
+
this.closeNVPair(cs);
|
|
744
|
+
} else {
|
|
745
|
+
// SR is ON
|
|
746
|
+
this.activeChildren = this.children;
|
|
747
|
+
await this.activeChildren[0].navigate(cs);
|
|
748
|
+
for (let i = 1; i < this.activeChildren.length; i++) {
|
|
749
|
+
this.activeChildren[i].addToString(cs);
|
|
750
|
+
}
|
|
751
|
+
this.closeNVPair(cs);
|
|
752
|
+
}
|
|
753
|
+
cs.closeDescription();
|
|
754
|
+
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
closeNVPair(cs) {
|
|
758
|
+
|
|
759
|
+
if (cs.getcurrentDescription() == null)
|
|
760
|
+
return;
|
|
761
|
+
let cOpts = new Array();
|
|
762
|
+
cOpts = cs.getcurrentDescription().getConnectOptions();
|
|
763
|
+
for (let i = 0; i < cOpts.length; ++i) {
|
|
764
|
+
|
|
765
|
+
if (this.sourceRoute) {
|
|
766
|
+
cOpts[i].CNdata.push(NavSchemaObject.SR);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// Use default service, if no connect_data
|
|
770
|
+
if (this.connectData == null) {
|
|
771
|
+
this.connectData = "(SERVICE_NAME=)";
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
cOpts[i].CNdata.push(NavSchemaObject.CD);
|
|
775
|
+
cOpts[i].CNdata.push(this.connectData);
|
|
776
|
+
cOpts[i].CNdata.push(NavSchemaObject.CID);
|
|
777
|
+
cOpts[i].CNdata.push(")");
|
|
778
|
+
|
|
779
|
+
if (this.SID != null) {
|
|
780
|
+
cOpts[i].sid = this.SID;
|
|
781
|
+
}
|
|
782
|
+
if (this.serviceName != null) {
|
|
783
|
+
cOpts[i].service_name = this.serviceName;
|
|
784
|
+
}
|
|
785
|
+
if (this.instanceName != null) {
|
|
786
|
+
cOpts[i].instance_name = this.instanceName;
|
|
787
|
+
}
|
|
788
|
+
// Close the description
|
|
789
|
+
cOpts[i].CNdata.push(")");
|
|
790
|
+
cOpts[i].done = true;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
getIntValue(stringInt, defaultValue) {
|
|
795
|
+
try {
|
|
796
|
+
return parseInt(stringInt);
|
|
797
|
+
} catch (exception) {
|
|
798
|
+
return defaultValue;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Class that navigates descriptionlist node in a tree.
|
|
806
|
+
*/
|
|
807
|
+
class NavDescriptionList extends DescriptionList {
|
|
808
|
+
constructor(activeChildren = new Array(), descProcessed = 0, done = 0) {
|
|
809
|
+
super();
|
|
810
|
+
this.activeChildren = activeChildren;
|
|
811
|
+
this.descProcessed = descProcessed;
|
|
812
|
+
this.done = done;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/**
|
|
816
|
+
* Method decides how to traverse and sets the active children based on
|
|
817
|
+
* the loadbalancing, failover values.
|
|
818
|
+
* @param {object} cs
|
|
819
|
+
*/
|
|
820
|
+
async navigate(cs) {
|
|
821
|
+
cs.sBuf.push("(DESCRIPTION_LIST=");
|
|
822
|
+
this.activeChildren = NavDescriptionList.setActiveChildren(this.children, this.failover, this.loadBalance);
|
|
823
|
+
while (this.descProcessed < this.activeChildren.length) {
|
|
824
|
+
await this.activeChildren[this.descProcessed].navigate(cs);
|
|
825
|
+
this.descProcessed++;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
/** set active children based on lb and failover values.
|
|
831
|
+
* @param children
|
|
832
|
+
* @param failover
|
|
833
|
+
* @param loadBalance
|
|
834
|
+
*/
|
|
835
|
+
static setActiveChildren(children, failover, loadBalance) {
|
|
836
|
+
let randNumber;
|
|
837
|
+
let listSize = children.length;
|
|
838
|
+
let tmpChildren = new Array();
|
|
839
|
+
let rand = Math.floor(Math.random() * 10);
|
|
840
|
+
let arr = new Array(listSize).fill(false);
|
|
841
|
+
|
|
842
|
+
if (failover) {
|
|
843
|
+
if (loadBalance) {
|
|
844
|
+
for (let i = 0; i < listSize; i++) {
|
|
845
|
+
do {
|
|
846
|
+
randNumber = Math.abs(Math.floor(Math.random() * 10)) % listSize;
|
|
847
|
+
} while (arr[randNumber]);
|
|
848
|
+
arr[randNumber] = true;
|
|
849
|
+
tmpChildren.push(children[randNumber]);
|
|
850
|
+
}
|
|
851
|
+
} else {
|
|
852
|
+
tmpChildren = children;
|
|
853
|
+
}
|
|
854
|
+
} else { // not failover
|
|
855
|
+
if (loadBalance) {
|
|
856
|
+
randNumber = Math.abs(rand) % listSize;
|
|
857
|
+
tmpChildren.push(children[randNumber]);
|
|
858
|
+
} else {
|
|
859
|
+
tmpChildren.push(children[0]);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
return (tmpChildren);
|
|
864
|
+
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
}
|
|
870
|
+
module.exports = {NavAddress, NavAddressList, NavDescription, NavDescriptionList};
|