2using System.Collections.Generic;
4using System.Threading.Tasks;
15 public const string NamespaceServiceRegistration =
"http://waher.se/Schema/ServiceRegistration.xsd";
20 this.
RegisterMessageHandler(
"register", NamespaceServiceRegistration, this.RegistrationMessageHandler,
true);
21 this.
RegisterIqSetHandler(
"register", NamespaceServiceRegistration, this.RegistrationIqSetHandler,
false);
39 private async Task RegistrationIqSetHandler(
object Sender,
IqEventArgs e)
43 await this.RegistrationHandler(e.
Query, e.
From);
52 private async Task RegistrationHandler(XmlElement E,
XmppAddress From)
55 if (
string.IsNullOrEmpty(BareJid) || BareJid != From.
BareJid)
57 Log.
Error(
"Invalid registration received:\r\r\n" + E.OuterXml, BareJid, From.
BareJid);
61 ServiceRegistration Registration = await
Database.FindFirstDeleteRest<ServiceRegistration>(
new FilterFieldEqualTo(
"BareJid", BareJid));
62 bool Created = Registration is
null;
66 Registration =
new ServiceRegistration()
72 Registration.ClientName =
XML.
Attribute(E,
"clientName");
73 Registration.ClientVersion =
XML.
Attribute(E,
"clientVersion");
78 Registration.Created =
XML.
Attribute(E,
"created", DateTime.MinValue);
79 Registration.Updated =
XML.
Attribute(E,
"updated", DateTime.MinValue);
81 List<string> Features =
new List<string>();
82 List<string> Assemblies =
new List<string>();
83 List<Annotation> Annotations =
new List<Annotation>();
85 foreach (XmlNode N
in E.ChildNodes)
90 Features.Add(N.InnerText);
94 Assemblies.Add(N.InnerText);
98 XmlElement E2 = (XmlElement)N;
100 string Value = N.InnerText;
102 Annotations.Add(
new Annotation(Tag, Value));
107 Registration.Features = Features.ToArray();
108 Registration.Assemblies = Assemblies.ToArray();
109 Registration.Annotations = Annotations.ToArray();
119 return GetRegistrationAsync(BareJid).Result;
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Static class managing the application event log. Applications and services log events on this static ...
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
Base class for components.
bool UnregisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool RemoveNamespaceAsFeature)
Unregisters a message handler.
void RegisterIqSetHandler(string LocalName, string Namespace, EventHandlerAsync< IqEventArgs > Handler, bool PublishNamespaceAsFeature)
Registers an IQ-Set handler.
CaseInsensitiveString Subdomain
Subdomain name.
string Name
Component name.
XmppServer Server
XMPP Server.
void RegisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool PublishNamespaceAsFeature)
Registers a message handler.
Event arguments for IQ queries.
XmppAddress From
From address attribute
Task IqResult(string Xml, string From)
Returns a response to the current request.
XmlElement Query
Query element, if found, null otherwise.
XmppAddress To
To address attribute
async Task IqError(string ErrorType, string Xml, XmppAddress From, string ErrorText, string Language)
Returns an error response to the current request.
Event arguments for Messages.
XmppAddress From
From address attribute
XmlElement Content
Content element, if found, null otherwise.
Contains information about one XMPP address.
CaseInsensitiveString BareJid
Bare JID
Represents a case-insensitive string.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task InsertLazy(object Object)
Inserts an object into the database, if unlocked. If locked, object will be inserted at next opportun...
static async Task UpdateLazy(object Object)
Updates an object in the database, if unlocked. If locked, object will be updated at next opportunity...
This filter selects objects that have a named field equal to a given value.
override void Dispose()
IDisposable.Dispose
override bool SupportsAccounts
If the component supports accounts (true), or if the subdomain name is the only valid address.