This commit is contained in:
Christian
2022-02-20 21:10:46 +01:00
committed by GitHub
parent 47e674e4d3
commit 2ce9b94ec9
608 changed files with 22364 additions and 19420 deletions
@@ -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
{
@@ -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
{
+11 -10
View File
@@ -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
{