mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-27 00:40:01 +08:00
v4.0.0 (#1357)
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttAuthenticateReasonCode
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttConnectReasonCode
|
||||
{
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
using MQTTnet.Exceptions;
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public class MqttConnectReasonCodeConverter
|
||||
{
|
||||
public MqttConnectReturnCode ToConnectReturnCode(MqttConnectReasonCode reasonCode)
|
||||
{
|
||||
switch (reasonCode)
|
||||
{
|
||||
case MqttConnectReasonCode.Success:
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionAccepted;
|
||||
}
|
||||
|
||||
case MqttConnectReasonCode.NotAuthorized:
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedNotAuthorized;
|
||||
}
|
||||
|
||||
case MqttConnectReasonCode.BadUserNameOrPassword:
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword;
|
||||
}
|
||||
|
||||
case MqttConnectReasonCode.ClientIdentifierNotValid:
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedIdentifierRejected;
|
||||
}
|
||||
|
||||
case MqttConnectReasonCode.UnsupportedProtocolVersion:
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedUnacceptableProtocolVersion;
|
||||
}
|
||||
|
||||
case MqttConnectReasonCode.ServerUnavailable:
|
||||
case MqttConnectReasonCode.ServerBusy:
|
||||
case MqttConnectReasonCode.ServerMoved:
|
||||
{
|
||||
return MqttConnectReturnCode.ConnectionRefusedServerUnavailable;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
throw new MqttProtocolViolationException("Unable to convert connect reason code (MQTTv5) to return code (MQTTv3).");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MqttConnectReasonCode ToConnectReasonCode(MqttConnectReturnCode returnCode)
|
||||
{
|
||||
switch (returnCode)
|
||||
{
|
||||
case MqttConnectReturnCode.ConnectionAccepted:
|
||||
{
|
||||
return MqttConnectReasonCode.Success;
|
||||
}
|
||||
|
||||
case MqttConnectReturnCode.ConnectionRefusedUnacceptableProtocolVersion:
|
||||
{
|
||||
return MqttConnectReasonCode.UnsupportedProtocolVersion;
|
||||
}
|
||||
|
||||
case MqttConnectReturnCode.ConnectionRefusedBadUsernameOrPassword:
|
||||
{
|
||||
return MqttConnectReasonCode.BadUserNameOrPassword;
|
||||
}
|
||||
|
||||
case MqttConnectReturnCode.ConnectionRefusedIdentifierRejected:
|
||||
{
|
||||
return MqttConnectReasonCode.ClientIdentifierNotValid;
|
||||
}
|
||||
|
||||
case MqttConnectReturnCode.ConnectionRefusedServerUnavailable:
|
||||
{
|
||||
return MqttConnectReasonCode.ServerUnavailable;
|
||||
}
|
||||
|
||||
case MqttConnectReturnCode.ConnectionRefusedNotAuthorized:
|
||||
{
|
||||
return MqttConnectReasonCode.NotAuthorized;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
throw new MqttProtocolViolationException("Unable to convert connect reason code (MQTTv5) to return code (MQTTv3).");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttConnectReturnCode
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttControlPacketType
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttDisconnectReasonCode
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttPayloadFormatIndicator
|
||||
{
|
||||
|
||||
+7
-1
@@ -1,7 +1,13 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttPropertyId
|
||||
{
|
||||
None = 0,
|
||||
|
||||
PayloadFormatIndicator = 1,
|
||||
MessageExpiryInterval = 2,
|
||||
ContentType = 3,
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttPubAckReasonCode
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttPubCompReasonCode
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttPubRecReasonCode
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttPubRelReasonCode
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttQualityOfServiceLevel
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttRetainHandling
|
||||
{
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttSubscribeReasonCode
|
||||
{
|
||||
GrantedQoS0 = 0,
|
||||
GrantedQoS1 = 1,
|
||||
GrantedQoS2 = 2,
|
||||
UnspecifiedError = 128,
|
||||
// Compatible with MQTTv3.1.1.
|
||||
GrantedQoS0 = 0x00,
|
||||
GrantedQoS1 = 0x01,
|
||||
GrantedQoS2 = 0x02,
|
||||
UnspecifiedError = 0x80,
|
||||
|
||||
// New in MQTTv5.
|
||||
ImplementationSpecificError = 131,
|
||||
NotAuthorized = 135,
|
||||
TopicFilterInvalid = 143,
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttSubscribeReturnCode
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using System;
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using MQTTnet.Exceptions;
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
@@ -9,17 +13,10 @@ namespace MQTTnet.Protocol
|
||||
{
|
||||
if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage));
|
||||
|
||||
if (!applicationMessage.TopicAlias.HasValue)
|
||||
if (applicationMessage.TopicAlias == 0)
|
||||
{
|
||||
ThrowIfInvalid(applicationMessage.Topic);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (applicationMessage.TopicAlias.Value == 0)
|
||||
{
|
||||
throw new MqttProtocolViolationException("The topic alias cannot be 0.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ThrowIfInvalid(string topic)
|
||||
@@ -50,7 +47,11 @@ namespace MQTTnet.Protocol
|
||||
throw new MqttProtocolViolationException("Topic should not be empty.");
|
||||
}
|
||||
|
||||
if (topic.IndexOf("#") != -1 && topic.IndexOf("#") != topic.Length - 1) throw new MqttProtocolViolationException("The character '#' is only allowed as last character");
|
||||
var indexOfHash = topic.IndexOf("#", StringComparison.Ordinal);
|
||||
if (indexOfHash != -1 && indexOfHash != topic.Length - 1)
|
||||
{
|
||||
throw new MqttProtocolViolationException("The character '#' is only allowed as last character");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace MQTTnet.Protocol
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace MQTTnet.Protocol
|
||||
{
|
||||
public enum MqttUnsubscribeReasonCode
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user