4using System.Threading.Tasks;
24 private readonly Dictionary<CaseInsensitiveString, RosterItemNode> roster =
new Dictionary<CaseInsensitiveString, RosterItemNode>();
25 private string userName =
string.Empty;
26 private string password =
string.Empty;
27 private string passwordMechanism =
string.Empty;
28 private string brokerKey =
null;
29 private bool trustServer =
false;
30 private bool allowInsecureMechanisms =
false;
46 [Header(13,
"User Name:")]
47 [ToolTip(14,
"User name used during authentication process.")]
48 [DefaultValueStringEmpty]
52 set => this.userName = value;
59 [Header(15,
"Password:")]
60 [ToolTip(16,
"Password used during authentication process.")]
66 set => this.password = value;
78 [Header(17,
"Password Hash Mechanism:")]
79 [ToolTip(18,
"Mechanism used for password hash.")]
80 [DefaultValueStringEmpty]
83 get => this.passwordMechanism;
84 set => this.passwordMechanism = value;
91 [Header(19,
"Trust Server Certificate")]
92 [ToolTip(20,
"If the server certificate should be trusted, even if it does not validate.")]
96 get => this.trustServer;
97 set => this.trustServer = value;
104 [Header(21,
"Allow Insecure Mechanisms")]
105 [ToolTip(22,
"If insecure mechanisms are permitted during authentication.")]
106 [DefaultValue(
false)]
109 get => this.allowInsecureMechanisms;
110 set => this.allowInsecureMechanisms = value;
116 [Page(28,
"Roster", 110)]
117 [Header(32,
"Auto-accept Pattern:")]
118 [ToolTip(33,
"If a presence subscription comes from a JID that matches this regular expression, it will be automatically accepted.")]
138 return Task.FromResult(
152 if (!
string.IsNullOrEmpty(this.brokerKey))
155 return base.DestroyAsync();
166 string PrevKey = this.brokerKey;
169 if (PrevKey != this.brokerKey && !
string.IsNullOrEmpty(PrevKey))
172 return this.brokerKey;
183 return base.NodeUpdated();
191 internal Task<XmppBroker> GetBroker()
194 this.passwordMechanism, this.trustServer, this.allowInsecureMechanisms);
197 #region ICommunicationLayer
210 this.GetBroker().Result?.Client?.Add(Sniffer);
218 this.GetBroker().Result?.Client?.AddRange(
Sniffers);
226 return this.GetBroker().Result?.Client?.Remove(Sniffer) ??
false;
234 get {
return this.GetBroker().Result?.Client?.Sniffers ?? Array.Empty<
ISniffer>(); }
242 get {
return this.GetBroker().Result?.Client?.HasSniffers ??
false; }
253 IEnumerator IEnumerable.GetEnumerator()
262 public void ReceiveBinary(
int Count) => this.GetCachedBroker()?.Client?.ReceiveBinary(Count);
270 public void ReceiveBinary(
bool ConstantBuffer,
byte[] Data) => this.GetCachedBroker()?.Client?.ReceiveBinary(ConstantBuffer, Data);
280 public void ReceiveBinary(
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count) => this.GetCachedBroker()?.Client?.ReceiveBinary(ConstantBuffer, Data, Offset, Count);
286 public void TransmitBinary(
int Count) => this.GetCachedBroker()?.Client?.TransmitBinary(Count);
294 public void TransmitBinary(
bool ConstantBuffer,
byte[] Data) => this.GetCachedBroker()?.Client?.TransmitBinary(ConstantBuffer, Data);
304 public void TransmitBinary(
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count) => this.GetCachedBroker()?.Client?.TransmitBinary(ConstantBuffer, Data, Offset, Count);
310 public void ReceiveText(
string Text) => this.GetCachedBroker()?.Client?.ReceiveText(Text);
316 public void TransmitText(
string Text) => this.GetCachedBroker()?.Client?.TransmitText(Text);
322 public void Information(
string Comment) => this.GetCachedBroker()?.Client?.Information(Comment);
340 public void Exception(Exception Exception) => this.GetCachedBroker()?.Client?.Exception(Exception);
346 public void Exception(
string Exception) => this.GetCachedBroker()?.Client?.Exception(Exception);
353 public void ReceiveBinary(DateTime Timestamp,
int Count) => this.GetCachedBroker()?.Client?.ReceiveBinary(Timestamp, Count);
362 public void ReceiveBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data) => this.GetCachedBroker()?.Client?.ReceiveBinary(Timestamp, ConstantBuffer, Data);
373 public void ReceiveBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count) => this.GetCachedBroker()?.Client?.ReceiveBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
380 public void TransmitBinary(DateTime Timestamp,
int Count) => this.GetCachedBroker()?.Client?.TransmitBinary(Timestamp, Count);
389 public void TransmitBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data) => this.GetCachedBroker()?.Client?.TransmitBinary(Timestamp, ConstantBuffer, Data);
400 public void TransmitBinary(DateTime Timestamp,
bool ConstantBuffer,
byte[] Data,
int Offset,
int Count) => this.GetCachedBroker()?.Client?.TransmitBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
407 public void ReceiveText(DateTime Timestamp,
string Text) => this.GetCachedBroker()?.Client?.ReceiveText(Timestamp, Text);
414 public void TransmitText(DateTime Timestamp,
string Text) => this.GetCachedBroker()?.Client?.TransmitText(Timestamp, Text);
421 public void Information(DateTime Timestamp,
string Comment) => this.GetCachedBroker()?.Client?.Information(Timestamp, Comment);
428 public void Warning(DateTime Timestamp,
string Warning) => this.GetCachedBroker()?.Client?.Warning(Timestamp,
Warning);
435 public void Error(DateTime Timestamp,
string Error) => this.GetCachedBroker()?.Client?.Error(Timestamp,
Error);
442 public void Exception(DateTime Timestamp,
string Exception) => this.GetCachedBroker()?.Client?.Exception(Timestamp, Exception);
449 public void Exception(DateTime Timestamp, Exception Exception) => this.GetCachedBroker()?.Client?.Exception(Timestamp, Exception);
464 List<ICommand> Result =
new List<ICommand>();
466 Result.AddRange(await base.Commands);
480 LinkedList<Parameter> Result = await base.GetDisplayableParametersAsync(
Language, Caller) as LinkedList<Parameter>;
484 Broker.Client.
State.ToString() ??
string.Empty));
497 public async Task<RosterItemNode>
GetRosterItem(
string BareJID,
bool CreateIfNotExists)
504 if (this.roster.TryGetValue(BareJID, out Result))
507 Load = this.roster.Count == 0;
512 IEnumerable<INode> Children = await this.
ChildNodes;
516 foreach (
INode Node
in Children)
522 if (this.roster.TryGetValue(BareJID, out Result))
527 if (CreateIfNotExists)
549 await base.AddAsync(Child);
555 this.roster[Item.BareJID] = Item;
566 if (!Extension.IsRegisteredExtension(Client))
583 if (!await base.RemoveAsync(Child))
590 this.roster.Remove(Item.BareJID);
601 if (Extension.IsRegisteredExtension(Client))
Typed enumerator of sniffers.
Maintains information about an item in the roster.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
XmppState State
Current state of connection.
bool UnregisterExtension(IXmppExtension Extension)
Unregisters an extension on the client.
void RegisterExtension(IXmppExtension Extension)
Registers an extension with the client.
Contains information about a language.
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
string Host
Host name or IP address.
Node representing a port on an IP Host machine.
bool Tls
If connection is encrypted using TLS or not.
virtual Task LogErrorAsync(string Body)
Logs an error message on the node.
static async Task< string > GetUniqueNodeId(string NodeId)
Gets a Node ID, based on NodeId that is not already available in the database.
Tokens available in request.
Reconnects to the XMPP broker.
Node representing an XMPP concentrator.
Base class for nodes in a remote concentrator.
Node representing a partition in a data source in an XMPP concentrator.
Node representing a data source in an XMPP concentrator.
Represents an XMPP broker.
Static class managing connections to XMPP brokers.
static XmppBroker GetCachedBroker(string Key)
Gets an XMPP broker object instance, if available in the cache.
static string GetKey(string Host, int Port, bool Tls, string UserName, string Password, string PasswordMechanism)
Gets sort key for XMPP broker
static async Task< XmppBroker > GetBroker(XmppBrokerNode Node, string Key, string Host, int Port, bool Tls, string UserName, string Password, string PasswordMechanism, bool TrustServer, bool AllowInsecureMechanisms)
Gets an XMPP broker object instance.
static void DestroyBroker(string Key)
Destroys a broker object instance
Node representing a roster item in the roster of an XMPP account.
Node representing an XMPP broker.
void TransmitText(string Text)
Called when text has been transmitted.
void Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
bool TrustServer
If broker server should be trusted
void Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
void Warning(string Warning)
Called to inform the viewer of a warning state.
void ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
ISniffer[] Sniffers
Registered sniffers.
void TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
override async Task AddAsync(INode Child)
Adds a new child to the node.
void TransmitBinary(int Count)
Called when binary data has been transmitted.
string PasswordMechanism
Password authentication mechanism
async override Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
override Task< IEnumerable< ICommand > > Commands
Available command objects. If no commands are available, null is returned.
void ReceiveText(string Text)
Called when text has been received.
bool AllowInsecureMechanisms
If insecure authentication mechanisms should be trusted
bool Remove(ISniffer Sniffer)
ICommunicationLayer.Remove
void Error(string Error)
Called to inform the viewer of an error state.
void ReceiveBinary(int Count)
Called when binary data has been received.
void Add(ISniffer Sniffer)
ICommunicationLayer.Add
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
override async Task< bool > RemoveAsync(INode Child)
Removes a child from the node.
void ReceiveText(DateTime Timestamp, string Text)
Called when text has been received.
void TransmitBinary(DateTime Timestamp, int Count)
Called when binary data has been transmitted.
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
void ReceiveBinary(DateTime Timestamp, int Count)
Called when binary data has been received.
void TransmitBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
string[] EncryptedProperties
Array of properties that are encrypted.
void AddRange(IEnumerable< ISniffer > Sniffers)
ICommunicationLayer.AddRange
override Task NodeUpdated()
Persists changes to the node, and generates a node updated event.
void Exception(string Exception)
Called to inform the viewer of an exception state.
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
void Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
IEnumerator< ISniffer > GetEnumerator()
IEnumerable<ISniffer>.GetEnumerator
void ReceiveBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
override Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a presumptive child, i.e. can receive as a child (if that child accepts the node ...
void Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
string AutoAcceptPattern
Partition ID
XmppBrokerNode()
Node representing an XMPP broker.
void Information(string Comment)
Called to inform the viewer of something.
string Key
Key representing the node.
void Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
override Task DestroyAsync()
Destroys the node. If it is a child to a parent node, it is removed from the parent first.
async Task< RosterItemNode > GetRosterItem(string BareJID, bool CreateIfNotExists)
Gets a roster item.
bool HasSniffers
If there are sniffers registered on the object.
async Task< IEnumerable< ICommand > > GetCommands()
Gets available commands.
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
Abstract base class for XMPP Extensions.
Interface for observable classes implementing communication protocols.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...
Interface for objects containing encrypted properties. Mark the properties that are encrypted with th...
Interface for nodes that are published through the concentrator interface.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.