2using System.Collections;
3using System.Collections.Generic;
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.")]
62 [DefaultValueStringEmpty]
66 set => this.password = value;
73 [Header(17,
"Password Hash Mechanism:")]
74 [ToolTip(18,
"Mechanism used for password hash.")]
75 [DefaultValueStringEmpty]
78 get => this.passwordMechanism;
79 set => this.passwordMechanism = value;
86 [Header(19,
"Trust Server Certificate")]
87 [ToolTip(20,
"If the server certificate should be trusted, even if it does not validate.")]
91 get => this.trustServer;
92 set => this.trustServer = value;
99 [Header(21,
"Allow Insecure Mechanisms")]
100 [ToolTip(22,
"If insecure mechanisms are permitted during authentication.")]
101 [DefaultValue(
false)]
104 get => this.allowInsecureMechanisms;
105 set => this.allowInsecureMechanisms = value;
111 [Page(28,
"Roster", 110)]
112 [Header(32,
"Auto-accept Pattern:")]
113 [ToolTip(33,
"If a presence subscription comes from a JID that matches this regular expression, it will be automatically accepted.")]
142 if (!
string.IsNullOrEmpty(this.brokerKey))
145 return base.DestroyAsync();
156 string PrevKey = this.brokerKey;
159 if (PrevKey != this.brokerKey && !
string.IsNullOrEmpty(PrevKey))
162 return this.brokerKey;
173 return base.NodeUpdated();
176 internal Task<XmppBroker> GetBroker()
179 this.passwordMechanism, this.trustServer, this.allowInsecureMechanisms);
182 #region ICommunicationLayer
195 this.GetBroker().Result?.Client?.Add(Sniffer);
203 this.GetBroker().Result?.Client?.AddRange(
Sniffers);
211 return this.GetBroker().Result?.Client?.Remove(Sniffer) ??
false;
219 get {
return this.GetBroker().Result?.Client?.Sniffers ??
new ISniffer[0]; }
227 get {
return this.GetBroker().Result?.Client?.HasSniffers ??
false; }
238 IEnumerator IEnumerable.GetEnumerator()
240 return this.GetBroker().Result?.Client?.GetEnumerator() ??
new ISniffer[0].GetEnumerator();
259 public async Task
ReceiveText(
string Text) => await ((await this.GetBroker()).Client?.
ReceiveText(Text) ?? Task.CompletedTask);
271 public async Task
Information(
string Comment) => await ((await this.GetBroker()).Client?.
Information(Comment) ?? Task.CompletedTask);
283 public async Task
Error(
string Error) => await ((await this.GetBroker()).Client?.
Error(
Error) ?? Task.CompletedTask);
289 public async Task
Exception(Exception Exception) => await ((await this.GetBroker()).Client?.
Exception(Exception) ?? Task.CompletedTask);
295 public async Task
Exception(
string Exception) => await ((await this.GetBroker()).Client?.
Exception(Exception) ?? Task.CompletedTask);
302 public async Task
ReceiveBinary(DateTime Timestamp,
byte[] Data) => await ((await this.GetBroker()).Client?.
ReceiveBinary(Timestamp, Data) ?? Task.CompletedTask);
309 public async Task
TransmitBinary(DateTime Timestamp,
byte[] Data) => await ((await this.GetBroker()).Client?.
TransmitBinary(Timestamp, Data) ?? Task.CompletedTask);
316 public async Task
ReceiveText(DateTime Timestamp,
string Text) => await ((await this.GetBroker()).Client?.
ReceiveText(Timestamp, Text) ?? Task.CompletedTask);
323 public async Task
TransmitText(DateTime Timestamp,
string Text) => await ((await this.GetBroker()).Client?.
TransmitText(Timestamp, Text) ?? Task.CompletedTask);
330 public async Task
Information(DateTime Timestamp,
string Comment) => await ((await this.GetBroker()).Client?.
Information(Timestamp, Comment) ?? Task.CompletedTask);
337 public async Task
Warning(DateTime Timestamp,
string Warning) => await ((await this.GetBroker()).Client?.
Warning(Timestamp,
Warning) ?? Task.CompletedTask);
344 public async Task
Error(DateTime Timestamp,
string Error) => await ((await this.GetBroker()).Client?.
Error(Timestamp,
Error) ?? Task.CompletedTask);
351 public async Task
Exception(DateTime Timestamp,
string Exception) => await ((await this.GetBroker()).Client?.
Exception(Timestamp, Exception) ?? Task.CompletedTask);
358 public async Task
Exception(DateTime Timestamp, Exception Exception) => await ((await this.GetBroker()).Client?.
Exception(Timestamp, Exception) ?? Task.CompletedTask);
373 List<ICommand> Result =
new List<ICommand>();
375 Result.AddRange(await base.Commands);
389 LinkedList<Parameter> Result = await base.GetDisplayableParametersAsync(
Language, Caller) as LinkedList<Parameter>;
393 Broker.Client.
State.ToString() ??
string.Empty));
406 public async Task<RosterItemNode>
GetRosterItem(
string BareJID,
bool CreateIfNotExists)
413 if (this.roster.TryGetValue(BareJID, out Result))
416 Load = this.roster.Count == 0;
421 IEnumerable<INode> Children = await this.
ChildNodes;
425 foreach (
INode Node
in Children)
431 if (this.roster.TryGetValue(BareJID, out Result))
436 if (CreateIfNotExists)
458 await base.AddAsync(Child);
464 this.roster[Item.BareJID] = Item;
475 if (!Extension.IsRegisteredExtension(Client))
492 if (!await base.RemoveAsync(Child))
499 this.roster.Remove(Item.BareJID);
510 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 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.
bool TrustServer
If broker server should be trusted
ISniffer[] Sniffers
Registered sniffers.
async Task Warning(string Warning)
Called to inform the viewer of a warning state.
override async Task AddAsync(INode Child)
Adds a new child to the node.
string PasswordMechanism
Password authentication mechanism
async override Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
async Task ReceiveBinary(DateTime Timestamp, byte[] Data)
Called when binary data has been received.
override Task< IEnumerable< ICommand > > Commands
Available command objects. If no commands are available, null is returned.
async Task Exception(string Exception)
Called to inform the viewer of an exception state.
bool AllowInsecureMechanisms
If insecure authentication mechanisms should be trusted
bool Remove(ISniffer Sniffer)
ICommunicationLayer.Remove
void Add(ISniffer Sniffer)
ICommunicationLayer.Add
async Task ReceiveText(string Text)
Called when text has been received.
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.
async Task ReceiveBinary(byte[] Data)
Called when binary data has been received.
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
async Task Information(string Comment)
Called to inform the viewer of something.
async Task ReceiveText(DateTime Timestamp, string Text)
Called when text has been received.
void AddRange(IEnumerable< ISniffer > Sniffers)
ICommunicationLayer.AddRange
async Task Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
async Task Exception(Exception Exception)
Called to inform the viewer of an exception state.
override Task NodeUpdated()
Persists changes to the node, and generates a node updated event.
IEnumerator< ISniffer > GetEnumerator()
IEnumerable<ISniffer>.GetEnumerator
async Task TransmitBinary(byte[] Data)
Called when binary data has been transmitted.
async Task Error(string Error)
Called to inform the viewer of an error state.
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 ...
async Task Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
string AutoAcceptPattern
Partition ID
XmppBrokerNode()
Node representing an XMPP broker.
async Task Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
string Key
Key representing the node.
async Task TransmitBinary(DateTime Timestamp, byte[] Data)
Called when binary data has been transmitted.
override Task DestroyAsync()
Destroys the node. If it is a child to a parent node, it is removed from the parent first.
async Task TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
async Task< RosterItemNode > GetRosterItem(string BareJID, bool CreateIfNotExists)
Gets a roster item.
async Task TransmitText(string Text)
Called when text has been transmitted.
bool HasSniffers
If there are sniffers registered on the object.
async Task< IEnumerable< ICommand > > GetCommands()
Gets available commands.
async Task Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
async Task Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
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 nodes that are published through the concentrator interface.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.