Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
Filter BlacklistedTopics (topics where only Bridge can publish)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaskueffel committed May 27, 2021
1 parent f85512f commit a97d100
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/Ctrl2MqttBridge/Classes/BlacklistedTopics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ctrl2MqttBridge.Classes
{
static class BlacklistedTopics
{
private static readonly string[] ReservedTopics = {
"/bridgeStatus",
"/writeresult",
"/readresult",
"/subscriptionnotification",
"/alarmnotification",
"/writevalue"
};

public static bool ContainsBlacklisted(string topic)
{
bool result = false;
foreach(var blacklistedTopic in ReservedTopics)
{
if (topic.ToLower().Contains(blacklistedTopic.ToLower()))
result = true;
}
return result;
}

}
}
4 changes: 3 additions & 1 deletion src/Ctrl2MqttBridge/Ctrl2MqttBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ async Task initMqttServer()
})
.WithApplicationMessageInterceptor(m =>
{
if (ClientRights.ContainsKey(m.ClientId)) //Sollte immer true sein...
if (m.ClientId != ClientId && BlacklistedTopics.ContainsBlacklisted(m.ApplicationMessage.Topic))
m.AcceptPublish = false;
else if (ClientRights.ContainsKey(m.ClientId)) //Sollte immer true sein...
m.AcceptPublish = ClientRights[m.ClientId];
else
m.AcceptPublish = false;
Expand Down

0 comments on commit a97d100

Please sign in to comment.