mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Add validations of variable byte integers (#2214)
* Add validations and add docs * Update release notes * Fix build
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
// ReSharper disable MemberCanBeMadeStatic.Local
|
||||
|
||||
using MQTTnet.Internal;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Samples.Server;
|
||||
@@ -42,4 +43,32 @@ public static class Server_Intercepting_Samples
|
||||
Console.ReadLine();
|
||||
await mqttServer.StopAsync();
|
||||
}
|
||||
|
||||
public static async Task Intercept_Subscription()
|
||||
{
|
||||
/*
|
||||
* This sample starts a simple MQTT server which does not allow to subscribe to '#'
|
||||
* Start the server and try to subscribe to '#' with a client of choice.
|
||||
*/
|
||||
|
||||
var mqttServerFactory = new MqttServerFactory();
|
||||
var mqttServerOptions = new MqttServerOptionsBuilder().WithDefaultEndpoint().Build();
|
||||
|
||||
using var mqttServer = mqttServerFactory.CreateMqttServer(mqttServerOptions);
|
||||
mqttServer.InterceptingSubscriptionAsync += args =>
|
||||
{
|
||||
if (args.TopicFilter.Topic.Equals("#", StringComparison.Ordinal))
|
||||
{
|
||||
args.Response.ReasonCode = MqttSubscribeReasonCode.NotAuthorized;
|
||||
}
|
||||
|
||||
return CompletedTask.Instance;
|
||||
};
|
||||
|
||||
await mqttServer.StartAsync();
|
||||
|
||||
Console.WriteLine("Press Enter to exit.");
|
||||
Console.ReadLine();
|
||||
await mqttServer.StopAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user