stem-mqtt 0.9.0 → 0.9.2
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/broker/mqtt_broker-ffi.d.ts +28 -0
- package/broker/mqtt_broker-ffi.js +458 -0
- package/broker/mqtt_broker.d.ts +106 -0
- package/broker/mqtt_broker.js +404 -1
- package/package.json +6 -6
package/broker/mqtt_broker.d.ts
CHANGED
|
@@ -56,6 +56,12 @@ export interface BrokerTlsConfig {
|
|
|
56
56
|
* TLS listener.
|
|
57
57
|
*/
|
|
58
58
|
"client_ca_pem": Uint8Array | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* With mutual TLS, tie the MQTT client id to the verified client certificate, so a client cannot claim
|
|
61
|
+
* another's id (and with it its topics and its session). [`CertClientId::None`] (the default) leaves the id as the
|
|
62
|
+
* client sent it.
|
|
63
|
+
*/
|
|
64
|
+
"bind_client_id": CertClientId;
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
/**
|
|
@@ -154,6 +160,50 @@ export interface MqttBrokerConfig {
|
|
|
154
160
|
"session_expiry_secs": number;
|
|
155
161
|
}
|
|
156
162
|
|
|
163
|
+
/**
|
|
164
|
+
* One message a client published (or whose Last Will the broker published), for [`MqttMessageObserver`].
|
|
165
|
+
*/
|
|
166
|
+
export interface ObservedMessage {
|
|
167
|
+
/**
|
|
168
|
+
* The topic name.
|
|
169
|
+
*/
|
|
170
|
+
"topic": string;
|
|
171
|
+
/**
|
|
172
|
+
* The payload.
|
|
173
|
+
*/
|
|
174
|
+
"payload": Uint8Array;
|
|
175
|
+
/**
|
|
176
|
+
* The QoS it was published at.
|
|
177
|
+
*/
|
|
178
|
+
"qos": QoS;
|
|
179
|
+
/**
|
|
180
|
+
* Whether it was published as retained.
|
|
181
|
+
*/
|
|
182
|
+
"retain": boolean;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* How a verified client certificate is tied to the MQTT client id (see [`BrokerTlsConfig::bind_client_id`]).
|
|
187
|
+
*/
|
|
188
|
+
export declare const CertClientId: Readonly<{
|
|
189
|
+
/**
|
|
190
|
+
* The client id is whatever the client sent.
|
|
191
|
+
*/
|
|
192
|
+
"None": "None";
|
|
193
|
+
/**
|
|
194
|
+
* The client id must equal the certificate's subject common name; a client that sends an empty id is given it.
|
|
195
|
+
*/
|
|
196
|
+
"CommonName": "CommonName";
|
|
197
|
+
/**
|
|
198
|
+
* The client id must equal one of the certificate's DNS subject alternative names.
|
|
199
|
+
*/
|
|
200
|
+
"DnsName": "DnsName";
|
|
201
|
+
}>;
|
|
202
|
+
/**
|
|
203
|
+
* How a verified client certificate is tied to the MQTT client id (see [`BrokerTlsConfig::bind_client_id`]).
|
|
204
|
+
*/
|
|
205
|
+
export type CertClientId = (typeof CertClientId)[keyof typeof CertClientId];
|
|
206
|
+
|
|
157
207
|
/**
|
|
158
208
|
* The verdict of one round of an MQTT 5.0 enhanced authentication exchange.
|
|
159
209
|
*/
|
|
@@ -218,6 +268,24 @@ export declare const QoS: Readonly<{
|
|
|
218
268
|
*/
|
|
219
269
|
export type QoS = (typeof QoS)[keyof typeof QoS];
|
|
220
270
|
|
|
271
|
+
/**
|
|
272
|
+
* What a client asks to do with a topic, for [`MqttAuthorizer`].
|
|
273
|
+
*/
|
|
274
|
+
export declare const TopicAction: Readonly<{
|
|
275
|
+
/**
|
|
276
|
+
* Publish to a topic name (also a Last Will, checked at CONNECT).
|
|
277
|
+
*/
|
|
278
|
+
"Publish": "Publish";
|
|
279
|
+
/**
|
|
280
|
+
* Subscribe to a topic filter (for `$share/<group>/<filter>` the inner filter).
|
|
281
|
+
*/
|
|
282
|
+
"Subscribe": "Subscribe";
|
|
283
|
+
}>;
|
|
284
|
+
/**
|
|
285
|
+
* What a client asks to do with a topic, for [`MqttAuthorizer`].
|
|
286
|
+
*/
|
|
287
|
+
export type TopicAction = (typeof TopicAction)[keyof typeof TopicAction];
|
|
288
|
+
|
|
221
289
|
export interface BrokerEventClientConnected {
|
|
222
290
|
tag: "ClientConnected";
|
|
223
291
|
"client_id": string;
|
|
@@ -293,6 +361,22 @@ export interface MqttAuthProvider {
|
|
|
293
361
|
authenticate(client_id: string, username: string | undefined, password: Uint8Array | undefined): boolean;
|
|
294
362
|
}
|
|
295
363
|
|
|
364
|
+
/**
|
|
365
|
+
* Pluggable topic authorisation, evaluated for every PUBLISH, every filter of a SUBSCRIBE and a Last Will at CONNECT. With
|
|
366
|
+
* none registered every authenticated client may use every topic, as before.
|
|
367
|
+
*
|
|
368
|
+
* Denied: a PUBLISH is dropped and, in MQTT 5.0, acknowledged with reason 0x87 (not authorised; MQTT 3.1.1 has no
|
|
369
|
+
* such code, the publisher sees an ordinary acknowledgement); a SUBSCRIBE filter gets 0x87 (0x80 in 3.1.1); a Last Will
|
|
370
|
+
* refuses the CONNECT. The check is a plain call on the connection's task: it must be quick and must not block (an
|
|
371
|
+
* in-memory ACL, not a database). A panic counts as denied.
|
|
372
|
+
*/
|
|
373
|
+
export interface MqttAuthorizer {
|
|
374
|
+
/**
|
|
375
|
+
* Return `true` to allow `client_id` to do `action` on `topic`.
|
|
376
|
+
*/
|
|
377
|
+
authorize(client_id: string, action: TopicAction, topic: string): boolean;
|
|
378
|
+
}
|
|
379
|
+
|
|
296
380
|
/**
|
|
297
381
|
* Broker-side view of a delivered/observed event, for monitoring and
|
|
298
382
|
* logging from foreign code.
|
|
@@ -317,6 +401,18 @@ export interface MqttEnhancedAuthProvider {
|
|
|
317
401
|
step(client_id: string, method: string, data: Uint8Array | undefined, round: number): EnhancedAuthStep;
|
|
318
402
|
}
|
|
319
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Sees every message the broker accepts, with its payload, so a program that embeds the broker needs no MQTT client of its
|
|
406
|
+
* own to read telemetry. Called after authorisation, once per message, on the publishing connection's task: keep it
|
|
407
|
+
* quick (push to a channel); a panic is contained.
|
|
408
|
+
*/
|
|
409
|
+
export interface MqttMessageObserver {
|
|
410
|
+
/**
|
|
411
|
+
* A message from `client_id` was accepted (a Last Will is published by the broker on the dead client's behalf).
|
|
412
|
+
*/
|
|
413
|
+
on_message(client_id: string, message: ObservedMessage): void;
|
|
414
|
+
}
|
|
415
|
+
|
|
320
416
|
/**
|
|
321
417
|
* A running (or not-yet-started) MQTT broker instance, speaking both MQTT
|
|
322
418
|
* 3.1.1 and MQTT 5.0 — the protocol version is negotiated independently
|
|
@@ -387,6 +483,11 @@ export declare class MqttBroker extends UniffiObjectBase {
|
|
|
387
483
|
* may be replaced at any time.
|
|
388
484
|
*/
|
|
389
485
|
set_auth_provider(provider: MqttAuthProvider): void;
|
|
486
|
+
/**
|
|
487
|
+
* Register topic authorisation (see [`MqttAuthorizer`](crate::MqttAuthorizer)); may be replaced at any time. With
|
|
488
|
+
* none registered every authenticated client may use every topic.
|
|
489
|
+
*/
|
|
490
|
+
set_authorizer(authorizer: MqttAuthorizer): void;
|
|
390
491
|
/**
|
|
391
492
|
* Register the MQTT 5.0 enhanced-authentication provider (multi-round
|
|
392
493
|
* challenge/response during CONNECT). Without one, a CONNECT that names
|
|
@@ -397,6 +498,11 @@ export declare class MqttBroker extends UniffiObjectBase {
|
|
|
397
498
|
* Register a listener for connect/disconnect/publish events.
|
|
398
499
|
*/
|
|
399
500
|
set_event_listener(listener: MqttBrokerEventListener): void;
|
|
501
|
+
/**
|
|
502
|
+
* Register an observer that sees every accepted message with its payload (see
|
|
503
|
+
* [`MqttMessageObserver`](crate::MqttMessageObserver)), so an embedding program needs no client of its own.
|
|
504
|
+
*/
|
|
505
|
+
set_message_observer(observer: MqttMessageObserver): void;
|
|
400
506
|
/**
|
|
401
507
|
* Bind the listening socket(s) and start accepting connections. Also
|
|
402
508
|
* binds a second, MQTT-over-WebSocket listener on `config.ws_port` and
|
package/broker/mqtt_broker.js
CHANGED
|
@@ -348,6 +348,24 @@ function uniffiGetRustFutureContinuationPointer() {
|
|
|
348
348
|
return uniffiRustFutureContinuationPointer;
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
+
/**
|
|
352
|
+
* How a verified client certificate is tied to the MQTT client id (see [`BrokerTlsConfig::bind_client_id`]).
|
|
353
|
+
*/
|
|
354
|
+
export const CertClientId = Object.freeze({
|
|
355
|
+
/**
|
|
356
|
+
* The client id is whatever the client sent.
|
|
357
|
+
*/
|
|
358
|
+
"None": "None",
|
|
359
|
+
/**
|
|
360
|
+
* The client id must equal the certificate's subject common name; a client that sends an empty id is given it.
|
|
361
|
+
*/
|
|
362
|
+
"CommonName": "CommonName",
|
|
363
|
+
/**
|
|
364
|
+
* The client id must equal one of the certificate's DNS subject alternative names.
|
|
365
|
+
*/
|
|
366
|
+
"DnsName": "DnsName",
|
|
367
|
+
});
|
|
368
|
+
|
|
351
369
|
/**
|
|
352
370
|
* The verdict of one round of an MQTT 5.0 enhanced authentication exchange.
|
|
353
371
|
*/
|
|
@@ -395,6 +413,20 @@ export const QoS = Object.freeze({
|
|
|
395
413
|
"ExactlyOnce": "ExactlyOnce",
|
|
396
414
|
});
|
|
397
415
|
|
|
416
|
+
/**
|
|
417
|
+
* What a client asks to do with a topic, for [`MqttAuthorizer`].
|
|
418
|
+
*/
|
|
419
|
+
export const TopicAction = Object.freeze({
|
|
420
|
+
/**
|
|
421
|
+
* Publish to a topic name (also a Last Will, checked at CONNECT).
|
|
422
|
+
*/
|
|
423
|
+
"Publish": "Publish",
|
|
424
|
+
/**
|
|
425
|
+
* Subscribe to a topic filter (for `$share/<group>/<filter>` the inner filter).
|
|
426
|
+
*/
|
|
427
|
+
"Subscribe": "Subscribe",
|
|
428
|
+
});
|
|
429
|
+
|
|
398
430
|
/**
|
|
399
431
|
* A broker event, as returned by the pull-style `MqttBroker::next_event`
|
|
400
432
|
* (the polling twin of [`MqttBrokerEventListener`](crate::config::MqttBrokerEventListener)).
|
|
@@ -493,7 +525,7 @@ const FfiConverterAuthRequest = new (class extends AbstractFfiConverterByteArray
|
|
|
493
525
|
const FfiConverterBrokerTlsConfig = new (class extends AbstractFfiConverterByteArray {
|
|
494
526
|
allocationSize(value) {
|
|
495
527
|
const recordValue = uniffiRequireRecordObject("BrokerTlsConfig", value);
|
|
496
|
-
return FfiConverterUInt16.allocationSize(recordValue["port"]) + FfiConverterBytes.allocationSize(recordValue["cert_pem"]) + FfiConverterBytes.allocationSize(recordValue["key_pem"]) + uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["client_ca_pem"]);
|
|
528
|
+
return FfiConverterUInt16.allocationSize(recordValue["port"]) + FfiConverterBytes.allocationSize(recordValue["cert_pem"]) + FfiConverterBytes.allocationSize(recordValue["key_pem"]) + uniffiOptionalConverter(FfiConverterBytes).allocationSize(recordValue["client_ca_pem"]) + FfiConverterCertClientId.allocationSize(recordValue["bind_client_id"]);
|
|
497
529
|
}
|
|
498
530
|
|
|
499
531
|
write(value, writer) {
|
|
@@ -502,6 +534,7 @@ const FfiConverterBrokerTlsConfig = new (class extends AbstractFfiConverterByteA
|
|
|
502
534
|
FfiConverterBytes.write(recordValue["cert_pem"], writer);
|
|
503
535
|
FfiConverterBytes.write(recordValue["key_pem"], writer);
|
|
504
536
|
uniffiOptionalConverter(FfiConverterBytes).write(recordValue["client_ca_pem"], writer);
|
|
537
|
+
FfiConverterCertClientId.write(recordValue["bind_client_id"], writer);
|
|
505
538
|
}
|
|
506
539
|
|
|
507
540
|
read(reader) {
|
|
@@ -510,6 +543,7 @@ const FfiConverterBrokerTlsConfig = new (class extends AbstractFfiConverterByteA
|
|
|
510
543
|
"cert_pem": FfiConverterBytes.read(reader),
|
|
511
544
|
"key_pem": FfiConverterBytes.read(reader),
|
|
512
545
|
"client_ca_pem": uniffiOptionalConverter(FfiConverterBytes).read(reader),
|
|
546
|
+
"bind_client_id": FfiConverterCertClientId.read(reader),
|
|
513
547
|
};
|
|
514
548
|
}
|
|
515
549
|
})();
|
|
@@ -573,6 +607,66 @@ const FfiConverterMqttBrokerConfig = new (class extends AbstractFfiConverterByte
|
|
|
573
607
|
};
|
|
574
608
|
}
|
|
575
609
|
})();
|
|
610
|
+
const FfiConverterObservedMessage = new (class extends AbstractFfiConverterByteArray {
|
|
611
|
+
allocationSize(value) {
|
|
612
|
+
const recordValue = uniffiRequireRecordObject("ObservedMessage", value);
|
|
613
|
+
return FfiConverterString.allocationSize(recordValue["topic"]) + FfiConverterBytes.allocationSize(recordValue["payload"]) + FfiConverterQoS.allocationSize(recordValue["qos"]) + FfiConverterBool.allocationSize(recordValue["retain"]);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
write(value, writer) {
|
|
617
|
+
const recordValue = uniffiRequireRecordObject("ObservedMessage", value);
|
|
618
|
+
FfiConverterString.write(recordValue["topic"], writer);
|
|
619
|
+
FfiConverterBytes.write(recordValue["payload"], writer);
|
|
620
|
+
FfiConverterQoS.write(recordValue["qos"], writer);
|
|
621
|
+
FfiConverterBool.write(recordValue["retain"], writer);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
read(reader) {
|
|
625
|
+
return {
|
|
626
|
+
"topic": FfiConverterString.read(reader),
|
|
627
|
+
"payload": FfiConverterBytes.read(reader),
|
|
628
|
+
"qos": FfiConverterQoS.read(reader),
|
|
629
|
+
"retain": FfiConverterBool.read(reader),
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
})();
|
|
633
|
+
const FfiConverterCertClientId = new (class extends AbstractFfiConverterByteArray {
|
|
634
|
+
allocationSize(value) {
|
|
635
|
+
uniffiRequireFlatEnumValue(CertClientId, "CertClientId", value);
|
|
636
|
+
return 4;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
write(value, writer) {
|
|
640
|
+
const enumValue = uniffiRequireFlatEnumValue(CertClientId, "CertClientId", value);
|
|
641
|
+
switch (enumValue) {
|
|
642
|
+
case CertClientId["None"]:
|
|
643
|
+
writer.writeInt32(1);
|
|
644
|
+
return;
|
|
645
|
+
case CertClientId["CommonName"]:
|
|
646
|
+
writer.writeInt32(2);
|
|
647
|
+
return;
|
|
648
|
+
case CertClientId["DnsName"]:
|
|
649
|
+
writer.writeInt32(3);
|
|
650
|
+
return;
|
|
651
|
+
default:
|
|
652
|
+
throw new UnexpectedEnumCase(`Unexpected CertClientId case ${String(enumValue)}.`);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
read(reader) {
|
|
657
|
+
const enumTag = reader.readInt32();
|
|
658
|
+
switch (enumTag) {
|
|
659
|
+
case 1:
|
|
660
|
+
return CertClientId["None"];
|
|
661
|
+
case 2:
|
|
662
|
+
return CertClientId["CommonName"];
|
|
663
|
+
case 3:
|
|
664
|
+
return CertClientId["DnsName"];
|
|
665
|
+
default:
|
|
666
|
+
throw new UnexpectedEnumCase(`Unexpected CertClientId case ${String(enumTag)}.`);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
})();
|
|
576
670
|
const FfiConverterEnhancedAuthOutcome = new (class extends AbstractFfiConverterByteArray {
|
|
577
671
|
allocationSize(value) {
|
|
578
672
|
uniffiRequireFlatEnumValue(EnhancedAuthOutcome, "EnhancedAuthOutcome", value);
|
|
@@ -647,6 +741,38 @@ const FfiConverterQoS = new (class extends AbstractFfiConverterByteArray {
|
|
|
647
741
|
}
|
|
648
742
|
}
|
|
649
743
|
})();
|
|
744
|
+
const FfiConverterTopicAction = new (class extends AbstractFfiConverterByteArray {
|
|
745
|
+
allocationSize(value) {
|
|
746
|
+
uniffiRequireFlatEnumValue(TopicAction, "TopicAction", value);
|
|
747
|
+
return 4;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
write(value, writer) {
|
|
751
|
+
const enumValue = uniffiRequireFlatEnumValue(TopicAction, "TopicAction", value);
|
|
752
|
+
switch (enumValue) {
|
|
753
|
+
case TopicAction["Publish"]:
|
|
754
|
+
writer.writeInt32(1);
|
|
755
|
+
return;
|
|
756
|
+
case TopicAction["Subscribe"]:
|
|
757
|
+
writer.writeInt32(2);
|
|
758
|
+
return;
|
|
759
|
+
default:
|
|
760
|
+
throw new UnexpectedEnumCase(`Unexpected TopicAction case ${String(enumValue)}.`);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
read(reader) {
|
|
765
|
+
const enumTag = reader.readInt32();
|
|
766
|
+
switch (enumTag) {
|
|
767
|
+
case 1:
|
|
768
|
+
return TopicAction["Publish"];
|
|
769
|
+
case 2:
|
|
770
|
+
return TopicAction["Subscribe"];
|
|
771
|
+
default:
|
|
772
|
+
throw new UnexpectedEnumCase(`Unexpected TopicAction case ${String(enumTag)}.`);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
})();
|
|
650
776
|
const FfiConverterBrokerEvent = new (class extends AbstractFfiConverterByteArray {
|
|
651
777
|
allocationSize(value) {
|
|
652
778
|
const enumValue = uniffiRequireTaggedEnumValue("BrokerEvent", value);
|
|
@@ -865,6 +991,128 @@ const FfiConverterMqttAuthProvider = Object.freeze({
|
|
|
865
991
|
return UNIFFI_OBJECT_HANDLE_SIZE;
|
|
866
992
|
},
|
|
867
993
|
});
|
|
994
|
+
class UniffiMqttAuthorizerProxy extends UniffiObjectBase {
|
|
995
|
+
|
|
996
|
+
authorize(client_id, action, topic) {
|
|
997
|
+
const loweredSelf = uniffiMqttAuthorizerFactory.cloneHandle(this);
|
|
998
|
+
const ffiMethod =
|
|
999
|
+
uniffiMqttAuthorizerFactory.usesGenericAbi(this)
|
|
1000
|
+
? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttauthorizer_authorize_generic_abi
|
|
1001
|
+
: ffiFunctions.uniffi_mqtt_broker_fn_method_mqttauthorizer_authorize;
|
|
1002
|
+
const loweredClientId = uniffiLowerString(client_id);
|
|
1003
|
+
const loweredAction = uniffiLowerIntoRustBuffer(FfiConverterTopicAction, action);
|
|
1004
|
+
const loweredTopic = uniffiLowerString(topic);
|
|
1005
|
+
const uniffiResult = uniffiRustCaller.rustCall(
|
|
1006
|
+
(status) => ffiMethod(loweredSelf, loweredClientId, loweredAction, loweredTopic, status),
|
|
1007
|
+
uniffiRustCallOptions(),
|
|
1008
|
+
);
|
|
1009
|
+
return FfiConverterBool.lift(uniffiResult);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
const uniffiMqttAuthorizerFactory = createObjectFactory({
|
|
1014
|
+
typeName: "MqttAuthorizer",
|
|
1015
|
+
createInstance: () => Object.create(UniffiMqttAuthorizerProxy.prototype),
|
|
1016
|
+
cloneHandle(handle) {
|
|
1017
|
+
return uniffiRustCaller.rustCall(
|
|
1018
|
+
(status) => ffiFunctions.uniffi_mqtt_broker_fn_clone_mqttauthorizer(handle, status),
|
|
1019
|
+
uniffiRustCallOptions(),
|
|
1020
|
+
);
|
|
1021
|
+
},
|
|
1022
|
+
freeHandle(handle) {
|
|
1023
|
+
uniffiRustCaller.rustCall(
|
|
1024
|
+
(status) => ffiFunctions.uniffi_mqtt_broker_fn_free_mqttauthorizer(handle, status),
|
|
1025
|
+
uniffiRustCallOptions(),
|
|
1026
|
+
);
|
|
1027
|
+
},
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
function uniffiValidateMqttAuthorizerImplementation(implementation) {
|
|
1031
|
+
if ((typeof implementation !== "object" && typeof implementation !== "function") || implementation == null) {
|
|
1032
|
+
throw new TypeError(`${"MqttAuthorizer"} implementations must be objects with callable methods.`);
|
|
1033
|
+
}
|
|
1034
|
+
if (typeof implementation.authorize !== "function") {
|
|
1035
|
+
throw new TypeError(`${"MqttAuthorizer"} is missing required method authorize().`);
|
|
1036
|
+
}
|
|
1037
|
+
return implementation;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
const uniffiMqttAuthorizerRegistry = createCallbackRegistry({
|
|
1041
|
+
interfaceName: "MqttAuthorizer",
|
|
1042
|
+
validate: uniffiValidateMqttAuthorizerImplementation,
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
function uniffiRegisterMqttAuthorizerVtable(bindings, registrations, vtableReferences) {
|
|
1046
|
+
const authorizeCallback = koffi.register(
|
|
1047
|
+
(uniffiHandle, client_id, action, topic, uniffiOutReturn, callStatus) => {
|
|
1048
|
+
const uniffiStatus = callStatus == null
|
|
1049
|
+
? createRustCallStatus()
|
|
1050
|
+
: koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
|
|
1051
|
+
const uniffiResult = invokeCallbackMethod({
|
|
1052
|
+
registry: uniffiMqttAuthorizerRegistry,
|
|
1053
|
+
handle: uniffiHandle,
|
|
1054
|
+
methodName: "authorize",
|
|
1055
|
+
args: [
|
|
1056
|
+
uniffiLiftStringFromRustBuffer(client_id),
|
|
1057
|
+
uniffiLiftFromRustBuffer(FfiConverterTopicAction, action),
|
|
1058
|
+
uniffiLiftStringFromRustBuffer(topic),
|
|
1059
|
+
],
|
|
1060
|
+
lowerString: (value) => uniffiLowerString(value),
|
|
1061
|
+
status: uniffiStatus,
|
|
1062
|
+
});
|
|
1063
|
+
if (callStatus != null) {
|
|
1064
|
+
koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
|
|
1065
|
+
}
|
|
1066
|
+
if (uniffiStatus.code !== CALL_SUCCESS) {
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1069
|
+
const loweredReturn = FfiConverterBool.lower(uniffiResult);
|
|
1070
|
+
koffi.encode(uniffiOutReturn, "int8_t", loweredReturn);
|
|
1071
|
+
},
|
|
1072
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttAuthorizerMethod0),
|
|
1073
|
+
);
|
|
1074
|
+
registrations.push(authorizeCallback);
|
|
1075
|
+
const uniffiFree = koffi.register(
|
|
1076
|
+
(uniffiHandle) => uniffiMqttAuthorizerRegistry.remove(uniffiHandle),
|
|
1077
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceFree),
|
|
1078
|
+
);
|
|
1079
|
+
registrations.push(uniffiFree);
|
|
1080
|
+
const uniffiClone = koffi.register(
|
|
1081
|
+
(uniffiHandle) => uniffiMqttAuthorizerRegistry.cloneHandle(uniffiHandle),
|
|
1082
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceClone),
|
|
1083
|
+
);
|
|
1084
|
+
registrations.push(uniffiClone);
|
|
1085
|
+
const uniffiVtable = koffi.alloc(bindings.ffiStructs.VTableCallbackInterfaceMqttAuthorizer, 1);
|
|
1086
|
+
koffi.encode(uniffiVtable, bindings.ffiStructs.VTableCallbackInterfaceMqttAuthorizer, {
|
|
1087
|
+
uniffi_free: uniffiFree,
|
|
1088
|
+
uniffi_clone: uniffiClone,
|
|
1089
|
+
"authorize": authorizeCallback,
|
|
1090
|
+
|
|
1091
|
+
});
|
|
1092
|
+
vtableReferences.push(uniffiVtable);
|
|
1093
|
+
bindings.ffiFunctions.uniffi_mqtt_broker_fn_init_callback_vtable_mqttauthorizer(uniffiVtable);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
const FfiConverterMqttAuthorizer = Object.freeze({
|
|
1097
|
+
lower(value) {
|
|
1098
|
+
if (uniffiMqttAuthorizerFactory.isInstance(value)) {
|
|
1099
|
+
return uniffiMqttAuthorizerFactory.cloneHandle(value);
|
|
1100
|
+
}
|
|
1101
|
+
return uniffiMqttAuthorizerRegistry.register(value);
|
|
1102
|
+
},
|
|
1103
|
+
lift(handle) {
|
|
1104
|
+
return uniffiMqttAuthorizerFactory.create(handle);
|
|
1105
|
+
},
|
|
1106
|
+
write(value, writer) {
|
|
1107
|
+
writer.writeUInt64(this.lower(value));
|
|
1108
|
+
},
|
|
1109
|
+
read(reader) {
|
|
1110
|
+
return this.lift(reader.readUInt64());
|
|
1111
|
+
},
|
|
1112
|
+
allocationSize() {
|
|
1113
|
+
return UNIFFI_OBJECT_HANDLE_SIZE;
|
|
1114
|
+
},
|
|
1115
|
+
});
|
|
868
1116
|
class UniffiMqttBrokerEventListenerProxy extends UniffiObjectBase {
|
|
869
1117
|
|
|
870
1118
|
on_client_connected(client_id) {
|
|
@@ -1194,21 +1442,142 @@ const FfiConverterMqttEnhancedAuthProvider = Object.freeze({
|
|
|
1194
1442
|
return UNIFFI_OBJECT_HANDLE_SIZE;
|
|
1195
1443
|
},
|
|
1196
1444
|
});
|
|
1445
|
+
class UniffiMqttMessageObserverProxy extends UniffiObjectBase {
|
|
1446
|
+
|
|
1447
|
+
on_message(client_id, message) {
|
|
1448
|
+
const loweredSelf = uniffiMqttMessageObserverFactory.cloneHandle(this);
|
|
1449
|
+
const ffiMethod =
|
|
1450
|
+
uniffiMqttMessageObserverFactory.usesGenericAbi(this)
|
|
1451
|
+
? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttmessageobserver_on_message_generic_abi
|
|
1452
|
+
: ffiFunctions.uniffi_mqtt_broker_fn_method_mqttmessageobserver_on_message;
|
|
1453
|
+
const loweredClientId = uniffiLowerString(client_id);
|
|
1454
|
+
const loweredMessage = uniffiLowerIntoRustBuffer(FfiConverterObservedMessage, message);
|
|
1455
|
+
uniffiRustCaller.rustCall(
|
|
1456
|
+
(status) => ffiMethod(loweredSelf, loweredClientId, loweredMessage, status),
|
|
1457
|
+
uniffiRustCallOptions(),
|
|
1458
|
+
);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
const uniffiMqttMessageObserverFactory = createObjectFactory({
|
|
1463
|
+
typeName: "MqttMessageObserver",
|
|
1464
|
+
createInstance: () => Object.create(UniffiMqttMessageObserverProxy.prototype),
|
|
1465
|
+
cloneHandle(handle) {
|
|
1466
|
+
return uniffiRustCaller.rustCall(
|
|
1467
|
+
(status) => ffiFunctions.uniffi_mqtt_broker_fn_clone_mqttmessageobserver(handle, status),
|
|
1468
|
+
uniffiRustCallOptions(),
|
|
1469
|
+
);
|
|
1470
|
+
},
|
|
1471
|
+
freeHandle(handle) {
|
|
1472
|
+
uniffiRustCaller.rustCall(
|
|
1473
|
+
(status) => ffiFunctions.uniffi_mqtt_broker_fn_free_mqttmessageobserver(handle, status),
|
|
1474
|
+
uniffiRustCallOptions(),
|
|
1475
|
+
);
|
|
1476
|
+
},
|
|
1477
|
+
});
|
|
1478
|
+
|
|
1479
|
+
function uniffiValidateMqttMessageObserverImplementation(implementation) {
|
|
1480
|
+
if ((typeof implementation !== "object" && typeof implementation !== "function") || implementation == null) {
|
|
1481
|
+
throw new TypeError(`${"MqttMessageObserver"} implementations must be objects with callable methods.`);
|
|
1482
|
+
}
|
|
1483
|
+
if (typeof implementation.on_message !== "function") {
|
|
1484
|
+
throw new TypeError(`${"MqttMessageObserver"} is missing required method on_message().`);
|
|
1485
|
+
}
|
|
1486
|
+
return implementation;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
const uniffiMqttMessageObserverRegistry = createCallbackRegistry({
|
|
1490
|
+
interfaceName: "MqttMessageObserver",
|
|
1491
|
+
validate: uniffiValidateMqttMessageObserverImplementation,
|
|
1492
|
+
});
|
|
1493
|
+
|
|
1494
|
+
function uniffiRegisterMqttMessageObserverVtable(bindings, registrations, vtableReferences) {
|
|
1495
|
+
const on_messageCallback = koffi.register(
|
|
1496
|
+
(uniffiHandle, client_id, message, uniffiOutReturn, callStatus) => {
|
|
1497
|
+
const uniffiStatus = callStatus == null
|
|
1498
|
+
? createRustCallStatus()
|
|
1499
|
+
: koffi.decode(callStatus, bindings.ffiTypes.RustCallStatus);
|
|
1500
|
+
const uniffiResult = invokeCallbackMethod({
|
|
1501
|
+
registry: uniffiMqttMessageObserverRegistry,
|
|
1502
|
+
handle: uniffiHandle,
|
|
1503
|
+
methodName: "on_message",
|
|
1504
|
+
args: [
|
|
1505
|
+
uniffiLiftStringFromRustBuffer(client_id),
|
|
1506
|
+
uniffiLiftFromRustBuffer(FfiConverterObservedMessage, message),
|
|
1507
|
+
],
|
|
1508
|
+
lowerString: (value) => uniffiLowerString(value),
|
|
1509
|
+
status: uniffiStatus,
|
|
1510
|
+
});
|
|
1511
|
+
if (callStatus != null) {
|
|
1512
|
+
koffi.encode(callStatus, bindings.ffiTypes.RustCallStatus, uniffiStatus);
|
|
1513
|
+
}
|
|
1514
|
+
if (uniffiStatus.code !== CALL_SUCCESS) {
|
|
1515
|
+
return;
|
|
1516
|
+
}
|
|
1517
|
+
},
|
|
1518
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceMqttMessageObserverMethod0),
|
|
1519
|
+
);
|
|
1520
|
+
registrations.push(on_messageCallback);
|
|
1521
|
+
const uniffiFree = koffi.register(
|
|
1522
|
+
(uniffiHandle) => uniffiMqttMessageObserverRegistry.remove(uniffiHandle),
|
|
1523
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceFree),
|
|
1524
|
+
);
|
|
1525
|
+
registrations.push(uniffiFree);
|
|
1526
|
+
const uniffiClone = koffi.register(
|
|
1527
|
+
(uniffiHandle) => uniffiMqttMessageObserverRegistry.cloneHandle(uniffiHandle),
|
|
1528
|
+
koffi.pointer(bindings.ffiCallbacks.CallbackInterfaceClone),
|
|
1529
|
+
);
|
|
1530
|
+
registrations.push(uniffiClone);
|
|
1531
|
+
const uniffiVtable = koffi.alloc(bindings.ffiStructs.VTableCallbackInterfaceMqttMessageObserver, 1);
|
|
1532
|
+
koffi.encode(uniffiVtable, bindings.ffiStructs.VTableCallbackInterfaceMqttMessageObserver, {
|
|
1533
|
+
uniffi_free: uniffiFree,
|
|
1534
|
+
uniffi_clone: uniffiClone,
|
|
1535
|
+
"on_message": on_messageCallback,
|
|
1536
|
+
|
|
1537
|
+
});
|
|
1538
|
+
vtableReferences.push(uniffiVtable);
|
|
1539
|
+
bindings.ffiFunctions.uniffi_mqtt_broker_fn_init_callback_vtable_mqttmessageobserver(uniffiVtable);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
const FfiConverterMqttMessageObserver = Object.freeze({
|
|
1543
|
+
lower(value) {
|
|
1544
|
+
if (uniffiMqttMessageObserverFactory.isInstance(value)) {
|
|
1545
|
+
return uniffiMqttMessageObserverFactory.cloneHandle(value);
|
|
1546
|
+
}
|
|
1547
|
+
return uniffiMqttMessageObserverRegistry.register(value);
|
|
1548
|
+
},
|
|
1549
|
+
lift(handle) {
|
|
1550
|
+
return uniffiMqttMessageObserverFactory.create(handle);
|
|
1551
|
+
},
|
|
1552
|
+
write(value, writer) {
|
|
1553
|
+
writer.writeUInt64(this.lower(value));
|
|
1554
|
+
},
|
|
1555
|
+
read(reader) {
|
|
1556
|
+
return this.lift(reader.readUInt64());
|
|
1557
|
+
},
|
|
1558
|
+
allocationSize() {
|
|
1559
|
+
return UNIFFI_OBJECT_HANDLE_SIZE;
|
|
1560
|
+
},
|
|
1561
|
+
});
|
|
1197
1562
|
|
|
1198
1563
|
const uniffiRegisteredCallbackPointers = [];
|
|
1199
1564
|
const uniffiRegisteredCallbackVtables = [];
|
|
1200
1565
|
|
|
1201
1566
|
function uniffiRegisterCallbackVtables(bindings) {
|
|
1202
1567
|
uniffiRegisterMqttAuthProviderVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
|
|
1568
|
+
uniffiRegisterMqttAuthorizerVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
|
|
1203
1569
|
uniffiRegisterMqttBrokerEventListenerVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
|
|
1204
1570
|
uniffiRegisterMqttEnhancedAuthProviderVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
|
|
1571
|
+
uniffiRegisterMqttMessageObserverVtable(bindings, uniffiRegisteredCallbackPointers, uniffiRegisteredCallbackVtables);
|
|
1205
1572
|
}
|
|
1206
1573
|
|
|
1207
1574
|
function uniffiUnregisterCallbackVtables() {
|
|
1208
1575
|
clearPendingForeignFutures();
|
|
1209
1576
|
uniffiMqttAuthProviderRegistry.clear();
|
|
1577
|
+
uniffiMqttAuthorizerRegistry.clear();
|
|
1210
1578
|
uniffiMqttBrokerEventListenerRegistry.clear();
|
|
1211
1579
|
uniffiMqttEnhancedAuthProviderRegistry.clear();
|
|
1580
|
+
uniffiMqttMessageObserverRegistry.clear();
|
|
1212
1581
|
while (uniffiRegisteredCallbackPointers.length > 0) {
|
|
1213
1582
|
koffi.unregister(uniffiRegisteredCallbackPointers.pop());
|
|
1214
1583
|
}
|
|
@@ -1453,6 +1822,23 @@ export class MqttBroker extends UniffiObjectBase {
|
|
|
1453
1822
|
);
|
|
1454
1823
|
}
|
|
1455
1824
|
|
|
1825
|
+
/**
|
|
1826
|
+
* Register topic authorisation (see [`MqttAuthorizer`](crate::MqttAuthorizer)); may be replaced at any time. With
|
|
1827
|
+
* none registered every authenticated client may use every topic.
|
|
1828
|
+
*/
|
|
1829
|
+
set_authorizer(authorizer) {
|
|
1830
|
+
const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
|
|
1831
|
+
const ffiMethod =
|
|
1832
|
+
uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
|
|
1833
|
+
? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_authorizer_generic_abi
|
|
1834
|
+
: ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_authorizer;
|
|
1835
|
+
const loweredAuthorizer = FfiConverterMqttAuthorizer.lower(authorizer);
|
|
1836
|
+
uniffiRustCaller.rustCall(
|
|
1837
|
+
(status) => ffiMethod(loweredSelf, loweredAuthorizer, status),
|
|
1838
|
+
uniffiRustCallOptions(),
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1456
1842
|
/**
|
|
1457
1843
|
* Register the MQTT 5.0 enhanced-authentication provider (multi-round
|
|
1458
1844
|
* challenge/response during CONNECT). Without one, a CONNECT that names
|
|
@@ -1487,6 +1873,23 @@ export class MqttBroker extends UniffiObjectBase {
|
|
|
1487
1873
|
);
|
|
1488
1874
|
}
|
|
1489
1875
|
|
|
1876
|
+
/**
|
|
1877
|
+
* Register an observer that sees every accepted message with its payload (see
|
|
1878
|
+
* [`MqttMessageObserver`](crate::MqttMessageObserver)), so an embedding program needs no client of its own.
|
|
1879
|
+
*/
|
|
1880
|
+
set_message_observer(observer) {
|
|
1881
|
+
const loweredSelf = uniffiMqttBrokerObjectFactory.cloneHandle(this);
|
|
1882
|
+
const ffiMethod =
|
|
1883
|
+
uniffiMqttBrokerObjectFactory.usesGenericAbi(this)
|
|
1884
|
+
? ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_message_observer_generic_abi
|
|
1885
|
+
: ffiFunctions.uniffi_mqtt_broker_fn_method_mqttbroker_set_message_observer;
|
|
1886
|
+
const loweredObserver = FfiConverterMqttMessageObserver.lower(observer);
|
|
1887
|
+
uniffiRustCaller.rustCall(
|
|
1888
|
+
(status) => ffiMethod(loweredSelf, loweredObserver, status),
|
|
1889
|
+
uniffiRustCallOptions(),
|
|
1890
|
+
);
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1490
1893
|
/**
|
|
1491
1894
|
* Bind the listening socket(s) and start accepting connections. Also
|
|
1492
1895
|
* binds a second, MQTT-over-WebSocket listener on `config.ws_port` and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stem-mqtt",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "MQTT 3.1.1 / 5.0 client and broker (Rust core, UniFFI Node bindings)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"optionalDependencies": {
|
|
47
|
-
"stem-mqtt-darwin-arm64": "0.9.
|
|
48
|
-
"stem-mqtt-darwin-x64": "0.9.
|
|
49
|
-
"stem-mqtt-linux-arm64-gnu": "0.9.
|
|
50
|
-
"stem-mqtt-linux-x64-gnu": "0.9.
|
|
51
|
-
"@greenspand/stem-mqtt-win32-x64-msvc": "0.9.
|
|
47
|
+
"stem-mqtt-darwin-arm64": "0.9.2",
|
|
48
|
+
"stem-mqtt-darwin-x64": "0.9.2",
|
|
49
|
+
"stem-mqtt-linux-arm64-gnu": "0.9.2",
|
|
50
|
+
"stem-mqtt-linux-x64-gnu": "0.9.2",
|
|
51
|
+
"@greenspand/stem-mqtt-win32-x64-msvc": "0.9.2"
|
|
52
52
|
},
|
|
53
53
|
"os": [
|
|
54
54
|
"darwin",
|