corba.js 0.1.14 → 0.1.15

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.
Files changed (139) hide show
  1. package/lib/idl/idl.cjs +3982 -0
  2. package/lib/idl/idl.cjs.map +1 -0
  3. package/lib/idl/src/idl/cc/typeIDLtoCC.d.ts +7 -0
  4. package/lib/idl/src/idl/cc/typeIDLtoGIOPCC.d.ts +3 -0
  5. package/lib/idl/src/idl/cc/write-code.d.ts +2 -0
  6. package/lib/idl/src/idl/cc/write-interface.d.ts +4 -0
  7. package/lib/idl/src/idl/cc/write-skeleton.d.ts +2 -0
  8. package/lib/idl/src/idl/cc/write-stub.d.ts +2 -0
  9. package/lib/idl/src/idl/idl-lexer.d.ts +19 -0
  10. package/lib/idl/src/idl/idl-node.d.ts +102 -0
  11. package/lib/idl/src/idl/idl-parser.d.ts +3 -0
  12. package/lib/idl/src/idl/idl.d.ts +1 -0
  13. package/lib/idl/src/idl/ts/typeIDLtoGIOPTS.d.ts +3 -0
  14. package/lib/idl/src/idl/ts/typeIDLtoTS.d.ts +3 -0
  15. package/lib/idl/src/idl/ts/write-interface.d.ts +2 -0
  16. package/lib/idl/src/idl/ts/write-skeleton.d.ts +2 -0
  17. package/lib/idl/src/idl/ts/write-stub.d.ts +2 -0
  18. package/lib/idl/src/idl/ts/write-value.d.ts +2 -0
  19. package/lib/idl/src/idl/ts/write-valueimpl.d.ts +2 -0
  20. package/lib/idl/src/idl/ts/write-valuetype.d.ts +2 -0
  21. package/lib/idl/src/idl/util.d.ts +22 -0
  22. package/lib/idl/src/index.d.ts +5 -0
  23. package/lib/idl/src/net/browser.d.ts +27 -0
  24. package/lib/idl/src/net/index.d.ts +3 -0
  25. package/lib/idl/src/net/tcp.d.ts +10 -0
  26. package/lib/idl/src/net/tls.d.ts +24 -0
  27. package/lib/idl/src/net/ws.d.ts +42 -0
  28. package/lib/idl/src/orb/asn1.d.ts +48 -0
  29. package/lib/idl/src/orb/connection.d.ts +25 -0
  30. package/lib/idl/src/orb/giop.d.ts +283 -0
  31. package/lib/idl/src/orb/index.d.ts +3 -0
  32. package/lib/idl/src/orb/ior.d.ts +89 -0
  33. package/lib/idl/src/orb/orb.d.ts +147 -0
  34. package/lib/idl/src/orb/protocol.d.ts +6 -0
  35. package/lib/idl/src/orb/uint8map.d.ts +14 -0
  36. package/lib/idl/src/orb/url.d.ts +55 -0
  37. package/lib/src/idl/cc/typeIDLtoCC.d.ts +7 -0
  38. package/lib/src/idl/cc/typeIDLtoCC.js +141 -0
  39. package/lib/src/idl/cc/typeIDLtoCC.js.map +1 -0
  40. package/lib/src/idl/cc/typeIDLtoGIOPCC.d.ts +3 -0
  41. package/lib/src/idl/cc/typeIDLtoGIOPCC.js +137 -0
  42. package/lib/src/idl/cc/typeIDLtoGIOPCC.js.map +1 -0
  43. package/lib/src/idl/cc/write-code.d.ts +2 -0
  44. package/lib/src/idl/cc/write-code.js +283 -0
  45. package/lib/src/idl/cc/write-code.js.map +1 -0
  46. package/lib/src/idl/cc/write-interface.d.ts +4 -0
  47. package/lib/src/idl/cc/write-interface.js +211 -0
  48. package/lib/src/idl/cc/write-interface.js.map +1 -0
  49. package/lib/src/idl/cc/write-skeleton.d.ts +2 -0
  50. package/lib/src/idl/cc/write-skeleton.js +43 -0
  51. package/lib/src/idl/cc/write-skeleton.js.map +1 -0
  52. package/lib/src/idl/cc/write-stub.d.ts +2 -0
  53. package/lib/src/idl/cc/write-stub.js +101 -0
  54. package/lib/src/idl/cc/write-stub.js.map +1 -0
  55. package/lib/src/idl/idl-lexer.d.ts +19 -0
  56. package/lib/src/idl/idl-lexer.js +234 -0
  57. package/lib/src/idl/idl-lexer.js.map +1 -0
  58. package/lib/src/idl/idl-node.d.ts +102 -0
  59. package/lib/src/idl/idl-node.js +214 -0
  60. package/lib/src/idl/idl-node.js.map +1 -0
  61. package/lib/src/idl/idl-parser.d.ts +3 -0
  62. package/lib/src/idl/idl-parser.js +1210 -0
  63. package/lib/src/idl/idl-parser.js.map +1 -0
  64. package/lib/src/idl/idl.d.ts +1 -0
  65. package/lib/src/idl/idl.js +219 -0
  66. package/lib/src/idl/idl.js.map +1 -0
  67. package/lib/src/idl/ts/typeIDLtoGIOPTS.d.ts +3 -0
  68. package/lib/src/idl/ts/typeIDLtoGIOPTS.js +101 -0
  69. package/lib/src/idl/ts/typeIDLtoGIOPTS.js.map +1 -0
  70. package/lib/src/idl/ts/typeIDLtoTS.d.ts +3 -0
  71. package/lib/src/idl/ts/typeIDLtoTS.js +92 -0
  72. package/lib/src/idl/ts/typeIDLtoTS.js.map +1 -0
  73. package/lib/src/idl/ts/write-interface.d.ts +2 -0
  74. package/lib/src/idl/ts/write-interface.js +225 -0
  75. package/lib/src/idl/ts/write-interface.js.map +1 -0
  76. package/lib/src/idl/ts/write-skeleton.d.ts +2 -0
  77. package/lib/src/idl/ts/write-skeleton.js +136 -0
  78. package/lib/src/idl/ts/write-skeleton.js.map +1 -0
  79. package/lib/src/idl/ts/write-stub.d.ts +2 -0
  80. package/lib/src/idl/ts/write-stub.js +150 -0
  81. package/lib/src/idl/ts/write-stub.js.map +1 -0
  82. package/lib/src/idl/ts/write-value.d.ts +2 -0
  83. package/lib/src/idl/ts/write-value.js +208 -0
  84. package/lib/src/idl/ts/write-value.js.map +1 -0
  85. package/lib/src/idl/ts/write-valueimpl.d.ts +2 -0
  86. package/lib/src/idl/ts/write-valueimpl.js +159 -0
  87. package/lib/src/idl/ts/write-valueimpl.js.map +1 -0
  88. package/lib/src/idl/ts/write-valuetype.d.ts +2 -0
  89. package/lib/src/idl/ts/write-valuetype.js +99 -0
  90. package/lib/src/idl/ts/write-valuetype.js.map +1 -0
  91. package/lib/src/idl/util.d.ts +22 -0
  92. package/lib/src/idl/util.js +84 -0
  93. package/lib/src/idl/util.js.map +1 -0
  94. package/lib/src/index.d.ts +5 -0
  95. package/lib/src/index.js +6 -0
  96. package/lib/src/index.js.map +1 -0
  97. package/lib/src/net/browser.d.ts +27 -0
  98. package/lib/src/net/browser.js +101 -0
  99. package/lib/src/net/browser.js.map +1 -0
  100. package/lib/src/net/index.d.ts +3 -0
  101. package/lib/src/net/index.js +4 -0
  102. package/lib/src/net/index.js.map +1 -0
  103. package/lib/src/net/tcp.d.ts +10 -0
  104. package/lib/src/net/tcp.js +67 -0
  105. package/lib/src/net/tcp.js.map +1 -0
  106. package/lib/src/net/tls.d.ts +24 -0
  107. package/lib/src/net/tls.js +70 -0
  108. package/lib/src/net/tls.js.map +1 -0
  109. package/lib/src/net/ws.d.ts +42 -0
  110. package/lib/src/net/ws.js +159 -0
  111. package/lib/src/net/ws.js.map +1 -0
  112. package/lib/src/orb/asn1.d.ts +48 -0
  113. package/lib/src/orb/asn1.js +60 -0
  114. package/lib/src/orb/asn1.js.map +1 -0
  115. package/lib/src/orb/connection.d.ts +25 -0
  116. package/lib/src/orb/connection.js +19 -0
  117. package/lib/src/orb/connection.js.map +1 -0
  118. package/lib/src/orb/giop.d.ts +283 -0
  119. package/lib/src/orb/giop.js +1302 -0
  120. package/lib/src/orb/giop.js.map +1 -0
  121. package/lib/src/orb/index.d.ts +3 -0
  122. package/lib/src/orb/index.js +4 -0
  123. package/lib/src/orb/index.js.map +1 -0
  124. package/lib/src/orb/ior.d.ts +89 -0
  125. package/lib/src/orb/ior.js +113 -0
  126. package/lib/src/orb/ior.js.map +1 -0
  127. package/lib/src/orb/orb.d.ts +147 -0
  128. package/lib/src/orb/orb.js +712 -0
  129. package/lib/src/orb/orb.js.map +1 -0
  130. package/lib/src/orb/protocol.d.ts +6 -0
  131. package/lib/src/orb/protocol.js +2 -0
  132. package/lib/src/orb/protocol.js.map +1 -0
  133. package/lib/src/orb/uint8map.d.ts +14 -0
  134. package/lib/src/orb/uint8map.js +48 -0
  135. package/lib/src/orb/uint8map.js.map +1 -0
  136. package/lib/src/orb/url.d.ts +55 -0
  137. package/lib/src/orb/url.js +255 -0
  138. package/lib/src/orb/url.js.map +1 -0
  139. package/package.json +1 -1
@@ -0,0 +1,712 @@
1
+ import { GIOPDecoder, GIOPEncoder, MessageType, LocateStatusType, ReplyStatus, EstablishContext, AuthenticationStatus } from "./giop.js";
2
+ import { IOR } from "./ior.js";
3
+ import { Uint8Map } from "./uint8map.js";
4
+ import { CorbaName, UrlParser } from "./url.js";
5
+ export class Exception extends Error {
6
+ }
7
+ export class UserException extends Exception {
8
+ }
9
+ export var CompletionStatus;
10
+ (function (CompletionStatus) {
11
+ CompletionStatus[CompletionStatus["YES"] = 0] = "YES";
12
+ CompletionStatus[CompletionStatus["NO"] = 1] = "NO";
13
+ CompletionStatus[CompletionStatus["MAYBE"] = 2] = "MAYBE";
14
+ })(CompletionStatus || (CompletionStatus = {}));
15
+ export class SystemException extends Exception {
16
+ constructor(minor, completed) {
17
+ super();
18
+ this.minor = minor;
19
+ this.completed = completed;
20
+ }
21
+ }
22
+ export class MARSHAL extends SystemException {
23
+ constructor(minor, completed) {
24
+ super(minor, completed);
25
+ let explanationList = {
26
+ 0x4f4d0001: "Unable to locate value factory.",
27
+ 0x4f4d0002: "ServerRequest::set_result called before ServerRequest::ctx when the operation IDL contains a context clause.",
28
+ 0x4f4d0003: "NVList passed to ServerRequest::arguments does not describe all parameters passed by client.",
29
+ 0x4f4d0004: "Attempt to marshal local object.",
30
+ 0x4f4d0005: "wchar or wstring data erroneously sent by client over GIOP 1.0 connection.",
31
+ 0x4f4d0006: "wchar or wstring data erroneously returned by server over GIOP 1.0 connection.",
32
+ 0x4f4d0007: "Unsupported RMI/IDL custom value type stream format.",
33
+ 0x4154000a: "Pass end of message",
34
+ 0x41540012: "Sequence is too long",
35
+ 0x41540015: "Index out of range",
36
+ 0x41540016: "Received an invalid zero length string",
37
+ 0x41540034: "Invalid IOR",
38
+ 0x4154004f: "Invalid ContextList",
39
+ 0x4154005a: "Invalid Indirection",
40
+ 0x4154005b: "Invalid TypeCodeKind",
41
+ 0x4154005d: "Message too long",
42
+ 0x41540070: "Invalid value tag"
43
+ };
44
+ const description = this.minor in explanationList ? `, ${explanationList[this.minor]}` : "";
45
+ this.message = `MARSHAL(minor=0x${this.minor.toString(16)}, completed=${CompletionStatus[this.completed]}${description})`;
46
+ }
47
+ get major() {
48
+ return "IDL:omg.org/CORBA/MARSHAL:1.0";
49
+ }
50
+ }
51
+ export class NO_PERMISSION extends SystemException {
52
+ constructor(minor, completed) {
53
+ super(minor, completed);
54
+ }
55
+ toString() {
56
+ return `NO_PERMISSION(minor=0x${this.minor.toString(16)}, completed=${CompletionStatus[this.completed]})`;
57
+ }
58
+ get major() {
59
+ return "IDL:omg.org/CORBA/NO_PERMISSION:1.0";
60
+ }
61
+ }
62
+ export class BAD_PARAM extends SystemException {
63
+ constructor(minor, completed) {
64
+ super(minor, completed);
65
+ let explanationList = {
66
+ 0x4154001d: "Invalid initial size"
67
+ };
68
+ const description = this.minor in explanationList ? `, ${explanationList[this.minor]}` : "";
69
+ this.message = `BAD_PARAM(minor=0x${this.minor.toString(16)}, completed=${CompletionStatus[this.completed]}${description})`;
70
+ }
71
+ get major() {
72
+ return "IDL:omg.org/CORBA/BAD_PARAM:1.0";
73
+ }
74
+ }
75
+ export class BAD_OPERATION extends SystemException {
76
+ constructor(minor, completed) {
77
+ super(minor, completed);
78
+ }
79
+ toString() {
80
+ return `BAD_OPERATION(minor=0x${this.minor.toString(16)}, completed=${CompletionStatus[this.completed]})`;
81
+ }
82
+ get major() {
83
+ return "IDL:omg.org/CORBA/BAD_OPERATION:1.0";
84
+ }
85
+ }
86
+ export class OBJECT_NOT_EXIST extends SystemException {
87
+ constructor(minor, completed) {
88
+ super(minor, completed);
89
+ }
90
+ toString() {
91
+ return `OBJECT_NOT_EXIST(minor=0x${this.minor.toString(16)}, completed=${CompletionStatus[this.completed]})`;
92
+ }
93
+ get major() {
94
+ return "IDL:omg.org/CORBA/OBJECT_NOT_EXIST:1.0";
95
+ }
96
+ }
97
+ export class TRANSIENT extends SystemException {
98
+ constructor(minor, completed) {
99
+ super(minor, completed);
100
+ let explanationList = {
101
+ 0x41540002: "Connect Failed"
102
+ };
103
+ const description = this.minor in explanationList ? `, ${explanationList[this.minor]}` : "";
104
+ this.message = `TRANSIENT(minor=0x${this.minor.toString(16)}, completed=${CompletionStatus[this.completed]}${description})`;
105
+ }
106
+ get major() {
107
+ return "IDL:omg.org/CORBA/TRANSIENT:1.0";
108
+ }
109
+ }
110
+ export class OBJECT_ADAPTER extends SystemException {
111
+ constructor(minor, completed) {
112
+ super(minor, completed);
113
+ let descriptionList = {
114
+ 0x4f4d0001: "POA Unknown adapter",
115
+ 0x4f4d0002: "No servant",
116
+ 0x4f4d0003: "No default servant",
117
+ 0x4f4d0004: "No servant manager",
118
+ 0x4f4d0005: "Wrong incarnate policy",
119
+ 0x4154000f: "BiDir not allowed",
120
+ 0x41540021: "BOA not initialized",
121
+ 0x41540035: "POA not initialized",
122
+ 0x4154003f: "Servant already active",
123
+ 0x41540061: "Incompatible servant",
124
+ };
125
+ const description = this.minor in descriptionList ? `, ${descriptionList[this.minor]}` : "";
126
+ this.message = `OBJECT_ADAPTER(minor=0x${this.minor.toString(16)}, completed=${CompletionStatus[this.completed]}${description})`;
127
+ }
128
+ get major() {
129
+ return "IDL:omg.org/CORBA/OBJECT_ADAPTER:1.0";
130
+ }
131
+ }
132
+ export class PromiseHandler {
133
+ constructor(decode, reject) {
134
+ this.decode = decode;
135
+ this.reject = reject;
136
+ }
137
+ }
138
+ export class ORB {
139
+ static installSystemExceptionHandler(object, handler) {
140
+ this.exceptionHandler.set(object, handler);
141
+ }
142
+ static connectionClose(conn) {
143
+ conn.stubsById.forEach(stub => {
144
+ const handler = this.exceptionHandler.get(stub);
145
+ if (handler !== undefined) {
146
+ this.exceptionHandler.delete(stub);
147
+ handler();
148
+ }
149
+ });
150
+ }
151
+ constructor() {
152
+ this.debug = 0;
153
+ this.name = "";
154
+ this.stubsByName = new Map();
155
+ this.servants = new Uint8Map();
156
+ this.servantIdCounter = 0n;
157
+ this.accesibleServants = new Set();
158
+ this.initialReferences = new Map();
159
+ this.listeners = new Map();
160
+ this.protocols = [];
161
+ this.connections = [];
162
+ this.namingService = new NamingContextExtImpl(this);
163
+ this.initialReferences.set("NameService", this.namingService);
164
+ this.servants.set(ORB.nameServiceKey, this.namingService);
165
+ }
166
+ addProtocol(protocol) {
167
+ this.protocols.push(protocol);
168
+ }
169
+ addConnection(connection) {
170
+ this.connections.push(connection);
171
+ }
172
+ removeConnection(connection) {
173
+ for (let i = 0; i < this.connections.length; ++i) {
174
+ if (connection === this.connections[i]) {
175
+ this.connections.splice(i, 1);
176
+ break;
177
+ }
178
+ }
179
+ }
180
+ logConnection() {
181
+ this.connections.forEach(c => console.log(`CONNECTION ${c.localAddress}:${c.localPort}->${c.remoteAddress}:${c.remotePort}`));
182
+ }
183
+ async shutdown() {
184
+ for (let i = 0; i < this.protocols.length; ++i) {
185
+ await this.protocols[i].close();
186
+ }
187
+ for (let i = 0; i < this.connections.length; ++i) {
188
+ await this.connections[i].close();
189
+ }
190
+ this.connections.length = 0;
191
+ }
192
+ async replaceAllConnections() {
193
+ const list = this.connections.map(x => x);
194
+ for (let i = 0; i < list.length; ++i) {
195
+ const oldConnection = list[i];
196
+ this.removeConnection(oldConnection);
197
+ const newConnection = await this.getConnection(oldConnection.remoteAddress, oldConnection.remotePort);
198
+ oldConnection.close();
199
+ oldConnection.stubsById.forEach((stub, key) => {
200
+ stub.connection = newConnection;
201
+ newConnection.stubsById.set(key, stub);
202
+ });
203
+ oldConnection.stubsById.clear();
204
+ }
205
+ }
206
+ async getConnection(host, port) {
207
+ if (host === "::1") {
208
+ host = "localhost";
209
+ }
210
+ for (const conn of this.connections) {
211
+ if (conn.remoteAddress === host && conn.remotePort === port) {
212
+ await conn.connect();
213
+ return conn;
214
+ }
215
+ }
216
+ for (const p of this.protocols) {
217
+ if (this.debug) {
218
+ if (this.connections.length === 0) {
219
+ console.log(`ORB: Creating new connection to ${host}:${port} as no others exist`);
220
+ }
221
+ else {
222
+ console.log(`ORB: Creating new connection to ${host}:${port}, as none found to`);
223
+ }
224
+ for (const c of this.connections) {
225
+ console.log(`ORB: active connection ${c.remoteAddress}:${c.remotePort}`);
226
+ }
227
+ }
228
+ return await p.connect(this, host, port);
229
+ }
230
+ throw Error(`failed to allocate connection to ${host}:${port}`);
231
+ }
232
+ async stringToObject(iorString) {
233
+ const parser = new UrlParser(iorString);
234
+ const iorOrLocation = parser.parse();
235
+ if (iorOrLocation instanceof IOR) {
236
+ return this.iorToObject(new IOR(iorString));
237
+ }
238
+ if (iorOrLocation instanceof CorbaName) {
239
+ const a = iorOrLocation.addr[0];
240
+ switch (a.proto) {
241
+ case "iiop":
242
+ const nameConnection = await this.getConnection(a.host, a.port);
243
+ const objectKey = new TextEncoder().encode(iorOrLocation.objectKey);
244
+ let rootNamingContext = nameConnection.stubsById.get(objectKey);
245
+ if (rootNamingContext === undefined) {
246
+ rootNamingContext = new NamingContextExtStub(this, objectKey, nameConnection);
247
+ nameConnection.stubsById.set(objectKey, rootNamingContext);
248
+ }
249
+ const reference = await rootNamingContext.resolve_str(iorOrLocation.name);
250
+ const objectConnection = await this.getConnection(reference.host, reference.port);
251
+ let object = objectConnection.stubsById.get(reference.objectKey);
252
+ if (object !== undefined)
253
+ return object;
254
+ const shortName = reference.oid.substring(4, reference.oid.length - 4);
255
+ let aStubClass = objectConnection.orb.stubsByName.get(shortName);
256
+ if (aStubClass === undefined) {
257
+ throw Error(`ORB: no stub registered for OID '${reference.oid} (${shortName})'`);
258
+ }
259
+ object = new aStubClass(objectConnection.orb, reference.objectKey, objectConnection);
260
+ objectConnection.stubsById.set(reference.objectKey, object);
261
+ return object;
262
+ default:
263
+ throw Error("yikes");
264
+ }
265
+ }
266
+ throw Error("yikes");
267
+ }
268
+ async iorToObject(ior) {
269
+ const connection = await this.getConnection(ior.host, ior.port);
270
+ let object = connection.stubsById.get(ior.objectKey);
271
+ if (object !== undefined) {
272
+ return object;
273
+ }
274
+ const shortName = ior.oid.substring(4, ior.oid.length - 4);
275
+ let aStubClass = this.stubsByName.get(shortName);
276
+ if (aStubClass === undefined) {
277
+ throw Error(`ORB: can not deserialize object of unregistered stub '${ior.oid}' (${shortName})'`);
278
+ }
279
+ object = new aStubClass(this, ior.objectKey, connection);
280
+ connection.stubsById.set(ior.objectKey, object);
281
+ return object;
282
+ }
283
+ onewayCall(stub, method, encode) {
284
+ const requestId = stub.connection.requestId;
285
+ stub.connection.requestId += 2;
286
+ this.callCore(stub.connection, requestId, false, stub._id, method, encode);
287
+ }
288
+ twowayCall(stub, method, encode, decode) {
289
+ const requestId = stub.connection.requestId;
290
+ stub.connection.requestId += 2;
291
+ return new Promise((resolve, reject) => {
292
+ try {
293
+ stub.connection.pendingReplies.set(requestId, new PromiseHandler((decoder) => resolve(decode(decoder)), reject));
294
+ this.callCore(stub.connection, requestId, true, stub._id, method, encode);
295
+ }
296
+ catch (e) {
297
+ reject(e);
298
+ }
299
+ });
300
+ }
301
+ callCore(connection, requestId, responseExpected, objectId, method, encode) {
302
+ if (this.debug) {
303
+ console.log(`ORB ${this.name}: send request method:${method}, requestId:${requestId}, responseExpected:${responseExpected} to ${connection.remoteAddress}:${connection.remotePort}`);
304
+ }
305
+ const encoder = new GIOPEncoder(connection);
306
+ encoder.encodeRequest(objectId, method, requestId, responseExpected);
307
+ encode(encoder);
308
+ encoder.setGIOPHeader(MessageType.REQUEST);
309
+ connection.send(encoder.buffer.slice(0, encoder.offset));
310
+ }
311
+ socketRcvd(connection, buffer) {
312
+ const decoder = new GIOPDecoder(buffer, connection);
313
+ const type = decoder.scanGIOPHeader();
314
+ switch (type) {
315
+ case MessageType.LOCATE_REQUEST:
316
+ {
317
+ const data = decoder.scanLocateRequest();
318
+ const servant = this.servants.get(data.objectKey);
319
+ const encoder = new GIOPEncoder(connection);
320
+ encoder.encodeLocateReply(data.requestId, servant !== undefined ?
321
+ LocateStatusType.OBJECT_HERE :
322
+ LocateStatusType.UNKNOWN_OBJECT);
323
+ encoder.setGIOPHeader(MessageType.LOCATE_REPLY);
324
+ connection.send(encoder.buffer.slice(0, encoder.offset));
325
+ }
326
+ break;
327
+ case MessageType.REQUEST:
328
+ {
329
+ const request = decoder.scanRequestHeader();
330
+ const servant = this.servants.get(request.objectKey);
331
+ if (servant === undefined) {
332
+ if (request.responseExpected) {
333
+ const encoder = new GIOPEncoder(connection);
334
+ encoder.skipReplyHeader();
335
+ encoder.string("IDL:omg.org/CORBA/OBJECT_NOT_EXIST:1.0");
336
+ encoder.ulong(0x4f4d0001);
337
+ encoder.ulong(CompletionStatus.NO);
338
+ const length = encoder.offset;
339
+ encoder.setGIOPHeader(MessageType.REPLY);
340
+ encoder.setReplyHeader(request.requestId, ReplyStatus.SYSTEM_EXCEPTION);
341
+ connection.send(encoder.buffer.slice(0, length));
342
+ }
343
+ return;
344
+ }
345
+ for (let i = 0; i < request.serviceContext.length; ++i) {
346
+ const e = request.serviceContext[i];
347
+ if (e instanceof EstablishContext) {
348
+ if (this.incomingAuthenticator && servant !== this.namingService) {
349
+ if (this.incomingAuthenticator(connection, e) !== AuthenticationStatus.SUCCESS) {
350
+ if (request.responseExpected) {
351
+ const encoder = new GIOPEncoder(connection);
352
+ encoder.skipReplyHeader();
353
+ encoder.string("IDL:omg.org/CORBA/NO_PERMISSION:1.0");
354
+ encoder.ulong(0);
355
+ encoder.ulong(CompletionStatus.NO);
356
+ const length = encoder.offset;
357
+ encoder.setGIOPHeader(MessageType.REPLY);
358
+ encoder.setReplyHeader(request.requestId, ReplyStatus.SYSTEM_EXCEPTION);
359
+ connection.send(encoder.buffer.slice(0, length));
360
+ }
361
+ return;
362
+ }
363
+ }
364
+ }
365
+ }
366
+ if (request.method == '_is_a') {
367
+ const repositoryId = decoder.string();
368
+ const encoder = new GIOPEncoder(connection);
369
+ encoder.skipReplyHeader();
370
+ encoder.bool(`IDL:${servant.constructor._idlClassName()}:1.0` === repositoryId);
371
+ const length = encoder.offset;
372
+ encoder.setGIOPHeader(MessageType.REPLY);
373
+ encoder.setReplyHeader(request.requestId, ReplyStatus.NO_EXCEPTION);
374
+ connection.send(encoder.buffer.slice(0, length));
375
+ return;
376
+ }
377
+ const method = servant[`_orb_${request.method}`];
378
+ if (method === undefined) {
379
+ if (request.responseExpected) {
380
+ const encoder = new GIOPEncoder(connection);
381
+ encoder.skipReplyHeader();
382
+ encoder.string("IDL:omg.org/CORBA/BAD_OPERATION:1.0");
383
+ encoder.ulong(0x4f4d0002);
384
+ encoder.ulong(CompletionStatus.NO);
385
+ const length = encoder.offset;
386
+ encoder.setGIOPHeader(MessageType.REPLY);
387
+ encoder.setReplyHeader(request.requestId, ReplyStatus.SYSTEM_EXCEPTION);
388
+ connection.send(encoder.buffer.slice(0, length));
389
+ }
390
+ return;
391
+ }
392
+ const encoder = new GIOPEncoder(connection);
393
+ encoder.skipReplyHeader();
394
+ method.call(servant, decoder, encoder)
395
+ .then(() => {
396
+ if (request.responseExpected) {
397
+ const length = encoder.offset;
398
+ encoder.setGIOPHeader(MessageType.REPLY);
399
+ encoder.setReplyHeader(request.requestId, ReplyStatus.NO_EXCEPTION);
400
+ connection.send(encoder.buffer.slice(0, length));
401
+ }
402
+ })
403
+ .catch((error) => {
404
+ if (request.responseExpected) {
405
+ if (error instanceof SystemException) {
406
+ encoder.skipReplyHeader();
407
+ encoder.string(error.major);
408
+ encoder.ulong(error.minor);
409
+ encoder.ulong(error.completed);
410
+ const length = encoder.offset;
411
+ encoder.setGIOPHeader(MessageType.REPLY);
412
+ encoder.setReplyHeader(request.requestId, ReplyStatus.SYSTEM_EXCEPTION);
413
+ connection.send(encoder.buffer.slice(0, length));
414
+ }
415
+ else {
416
+ encoder.skipReplyHeader();
417
+ encoder.string("IDL:mark13.org/CORBA/GENERIC:1.0");
418
+ encoder.ulong(0);
419
+ encoder.ulong(0);
420
+ encoder.string(`${`IDL:${servant.constructor._idlClassName()}:1.0`}:${request.method}(): ${error.message}`);
421
+ const length = encoder.offset;
422
+ encoder.setGIOPHeader(MessageType.REPLY);
423
+ encoder.setReplyHeader(request.requestId, ReplyStatus.SYSTEM_EXCEPTION);
424
+ connection.send(encoder.buffer.slice(0, length));
425
+ }
426
+ }
427
+ else {
428
+ console.log(`ORB: ignoring servant exception because method does not expect response`);
429
+ console.log(error);
430
+ }
431
+ });
432
+ }
433
+ break;
434
+ case MessageType.REPLY:
435
+ {
436
+ const data = decoder.scanReplyHeader();
437
+ const handler = connection.pendingReplies.get(data.requestId);
438
+ if (handler === undefined) {
439
+ console.log(`corba.js: Unexpected reply to requestId ${data.requestId} from ${connection.remoteAddress}:${connection.remotePort}`);
440
+ console.log(connection.pendingReplies);
441
+ return;
442
+ }
443
+ try {
444
+ connection.pendingReplies.delete(data.requestId);
445
+ switch (data.replyStatus) {
446
+ case ReplyStatus.NO_EXCEPTION:
447
+ handler.decode(decoder);
448
+ break;
449
+ case ReplyStatus.USER_EXCEPTION:
450
+ throw new Error(`User Exception for requestId ${data.requestId}`);
451
+ case ReplyStatus.SYSTEM_EXCEPTION:
452
+ const exceptionId = decoder.string();
453
+ const minorCodeValue = decoder.ulong();
454
+ const completionStatus = decoder.ulong();
455
+ let vendorList = {
456
+ 0x41540: "OmniORB",
457
+ 0x47430: "GNU Classpath",
458
+ 0x49424: "IBM",
459
+ 0x49540: "IONA",
460
+ 0x4A430: "JacORB",
461
+ 0x4D313: "corba.js",
462
+ 0x4F4D0: "OMG",
463
+ 0x53550: "SUN",
464
+ 0x54410: "TAO",
465
+ 0x56420: "Borland (VisiBroker)",
466
+ 0xA11C0: "Adiron"
467
+ };
468
+ const vendorId = (minorCodeValue & 0xFFFFF000) >> 12;
469
+ const vendor = vendorId in vendorList ? ` ${vendorList[vendorId]}` : "";
470
+ let explanation = "";
471
+ switch (exceptionId) {
472
+ case "IDL:omg.org/CORBA/MARSHAL:1.0":
473
+ throw new MARSHAL(minorCodeValue, completionStatus);
474
+ case "IDL:omg.org/CORBA/TRANSIENT:1.0":
475
+ throw new TRANSIENT(minorCodeValue, completionStatus);
476
+ case "IDL:omg.org/CORBA/BAD_PARAM:1.0":
477
+ throw new BAD_PARAM(minorCodeValue, completionStatus);
478
+ case "IDL:omg.org/CORBA/BAD_OPERATION:1.0":
479
+ throw new BAD_OPERATION(minorCodeValue, completionStatus);
480
+ case "IDL:omg.org/CORBA/OBJECT_NOT_EXIST:1.0":
481
+ throw new OBJECT_NOT_EXIST(minorCodeValue, completionStatus);
482
+ case "IDL:omg.org/CORBA/OBJECT_ADAPTER:1.0":
483
+ throw new OBJECT_ADAPTER(minorCodeValue, completionStatus);
484
+ case "IDL:omg.org/CORBA/NO_PERMISSION:1.0":
485
+ throw new NO_PERMISSION(minorCodeValue, completionStatus);
486
+ case "IDL:mark13.org/CORBA/GENERIC:1.0":
487
+ throw new Error(`Remote CORBA exception from ${connection.remoteAddress}:${connection.remotePort}: ${decoder.string()}`);
488
+ }
489
+ throw new Error(`CORBA System Exception ${exceptionId} from ${connection.remoteAddress}:${connection.remotePort}:${vendor}${explanation} (0x${minorCodeValue.toString(16)}), operation completed: ${CompletionStatus[completionStatus]}`);
490
+ default:
491
+ throw new Error(`ReplyStatusType ${data.replyStatus} is not supported`);
492
+ }
493
+ }
494
+ catch (e) {
495
+ handler.reject(e);
496
+ }
497
+ }
498
+ break;
499
+ default: {
500
+ throw Error(`Received ${MessageType[type]} which is not implemented in corba.js`);
501
+ }
502
+ }
503
+ }
504
+ socketError(connection, error) {
505
+ throw error;
506
+ }
507
+ socketClosed(connection) {
508
+ this.dispatchEvent(new Event("closed"));
509
+ this.release();
510
+ this.removeConnection(connection);
511
+ }
512
+ addEventListener(type, listener, options) {
513
+ if (listener === null)
514
+ return;
515
+ let set = this.listeners.get(type);
516
+ if (set === undefined) {
517
+ set = new Set();
518
+ this.listeners.set(type, set);
519
+ }
520
+ set.add(listener);
521
+ }
522
+ removeEventListener(type, listener, options) {
523
+ if (listener === null || listener === undefined)
524
+ return;
525
+ let set = this.listeners.get(type);
526
+ if (set === undefined)
527
+ return;
528
+ set.delete(listener);
529
+ }
530
+ dispatchEvent(event) {
531
+ let set = this.listeners.get(event.type);
532
+ if (set === undefined)
533
+ return true;
534
+ for (let handler of set) {
535
+ if (typeof handler === "function")
536
+ handler(event);
537
+ else
538
+ handler.handleEvent(event);
539
+ }
540
+ return true;
541
+ }
542
+ set onclose(listener) {
543
+ this.listeners.delete("close");
544
+ this.addEventListener("close", listener);
545
+ }
546
+ registerServant(servant) {
547
+ let id = ++this.servantIdCounter;
548
+ const x = new BigUint64Array([id]);
549
+ const u = new Uint8Array(x.buffer);
550
+ this.servants.set(u, servant);
551
+ return u;
552
+ }
553
+ unregisterServant(servant) {
554
+ this.servants.delete(servant._id);
555
+ }
556
+ registerStubClass(aStubClass) {
557
+ this.stubsByName.set(aStubClass._idlClassName(), aStubClass);
558
+ }
559
+ releaseObject(object) {
560
+ ORB.exceptionHandler.delete(object);
561
+ }
562
+ releaseStub(stub) {
563
+ }
564
+ static registerValueType(name, valuetypeConstructor) {
565
+ let information = ORB.valueTypeByName.get(name);
566
+ if (information === undefined) {
567
+ console.log(`registerValueType: number of known types: ${ORB.valueTypeByName.size}`);
568
+ ORB.valueTypeByName.forEach((value, key) => console.log(key));
569
+ throw Error(`ORB.registerValueType: valuetype '${name}' not defined in IDL`);
570
+ }
571
+ information.name = name;
572
+ information.construct = valuetypeConstructor;
573
+ ORB.valueTypeByPrototype.set(valuetypeConstructor.prototype, information);
574
+ }
575
+ static lookupValueType(name) {
576
+ let information = ORB.valueTypeByName.get(name);
577
+ if (information === undefined) {
578
+ throw Error(`ORB.lookupValueType: valuetype '${name}' not defined in IDL`);
579
+ }
580
+ if (information.construct === undefined) {
581
+ throw Error(`ORB.lookupValueType: valuetype '${name}' not registered via ORB.registerValueType()`);
582
+ }
583
+ return information.construct;
584
+ }
585
+ bind(id, obj) {
586
+ const nameService = this.initialReferences.get("NameService");
587
+ if (nameService === undefined)
588
+ throw Error(`No NameService found.`);
589
+ if (nameService instanceof NamingContextExtImpl) {
590
+ nameService.bind(id, obj);
591
+ return;
592
+ }
593
+ throw Error(`NameService is not of type IDL:omg.org/CosNaming/NamingContext:1.0`);
594
+ }
595
+ async list() {
596
+ throw Error("Obsolete");
597
+ }
598
+ async resolve(id) {
599
+ throw Error("Obsolete: Use objectToString(`corbaname::${hostname}#${objectname}`) instead");
600
+ }
601
+ serialize(value) {
602
+ const encoder = new GIOPEncoder();
603
+ encoder.endian();
604
+ encoder.value(value);
605
+ return encoder.buffer.slice(0, encoder.offset);
606
+ }
607
+ deserialize(buffer) {
608
+ const decoder = new GIOPDecoder(buffer);
609
+ decoder.endian();
610
+ return decoder.value();
611
+ }
612
+ setIncomingAuthenticator(authenticator) {
613
+ this.incomingAuthenticator = authenticator;
614
+ }
615
+ setOutgoingAuthenticator(authenticator) {
616
+ this.outgoingAuthenticator = authenticator;
617
+ }
618
+ release() {
619
+ this.aclDeleteAll();
620
+ }
621
+ aclAdd(servant) {
622
+ servant.acl.add(this);
623
+ this.accesibleServants.add(servant);
624
+ }
625
+ aclDeleteAll() {
626
+ for (let servant of this.accesibleServants)
627
+ servant.acl.delete(this);
628
+ this.accesibleServants.clear();
629
+ }
630
+ }
631
+ ORB.exceptionHandler = new Map();
632
+ ORB.nameServiceKey = new Uint8Array(new TextEncoder().encode("NameService"));
633
+ ORB.valueTypeByName = new Map();
634
+ ORB.valueTypeByPrototype = new Map();
635
+ export class CORBAObject {
636
+ constructor(orb, id) {
637
+ this._orb = orb;
638
+ this._id = id;
639
+ }
640
+ release() {
641
+ this._orb.releaseObject(this);
642
+ }
643
+ }
644
+ export class Skeleton extends CORBAObject {
645
+ constructor(orb) {
646
+ super(orb, undefined);
647
+ this._id = orb.registerServant(this);
648
+ this.acl = new Set();
649
+ }
650
+ }
651
+ export class Stub extends CORBAObject {
652
+ constructor(orb, remoteID, connection) {
653
+ super(orb, remoteID);
654
+ this.connection = connection;
655
+ }
656
+ release() {
657
+ super.release();
658
+ this._orb.releaseStub(this);
659
+ }
660
+ }
661
+ class NamingContextExtStub extends Stub {
662
+ static _idlClassName() {
663
+ return "omg.org/CosNaming/NamingContextExt";
664
+ }
665
+ static narrow(object) {
666
+ if (object instanceof NamingContextExtStub)
667
+ return object;
668
+ throw Error("NamingContextExt.narrow() failed");
669
+ }
670
+ async resolve_str(name) {
671
+ return await this._orb.twowayCall(this, "resolve_str", (encoder) => {
672
+ encoder.string(name);
673
+ }, (decoder) => decoder.reference());
674
+ }
675
+ }
676
+ class NamingContextExtImpl extends Skeleton {
677
+ constructor(orb) {
678
+ super(orb);
679
+ this.map = new Map();
680
+ }
681
+ static _idlClassName() {
682
+ return "omg.org/CosNaming/NamingContextExt";
683
+ }
684
+ bind(name, servant) {
685
+ if (this.map.has(name))
686
+ throw Error(`name '${name}' is already bound to object`);
687
+ this.map.set(name, servant);
688
+ }
689
+ async resolve(name) {
690
+ const servant = this.map.get(name);
691
+ if (servant === undefined) {
692
+ throw Error(`orb ${this._orb.name}: name '${name}' is not bound to an object`);
693
+ }
694
+ return servant;
695
+ }
696
+ async _orb_resolve(decoder, encoder) {
697
+ const entries = decoder.ulong();
698
+ const name = decoder.string();
699
+ const key = decoder.string();
700
+ if (entries !== 1 && key.length !== 0) {
701
+ console.log(`warning: resolve got ${entries} (expected 1) and/or key is "${key}" (expected "")`);
702
+ }
703
+ const result = await this.resolve(name);
704
+ encoder.object(result);
705
+ }
706
+ async _orb_resolve_str(decoder, encoder) {
707
+ const name = decoder.string();
708
+ const result = await this.resolve(name);
709
+ encoder.object(result);
710
+ }
711
+ }
712
+ //# sourceMappingURL=orb.js.map