-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathInteroperabilityServer.cs
More file actions
84 lines (72 loc) · 2.78 KB
/
InteroperabilityServer.cs
File metadata and controls
84 lines (72 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Waher.Content.Xml;
using Waher.Events;
using Waher.Networking.XMPP.Events;
namespace Waher.Networking.XMPP.Interoperability
{
/// <summary>
/// Implements the server-side for Interoperability interfaces, as defined in:
///
/// https://github.com/joachimlindborg/XMPP-IoT/blob/master/xep-0000-IoT-Interoperability.html
/// http://htmlpreview.github.io/?https://github.com/joachimlindborg/XMPP-IoT/blob/master/xep-0000-IoT-Interoperability.html
/// </summary>
public class InteroperabilityServer : XmppExtension
{
/// <summary>
/// urn:xmpp:iot:interoperability
/// </summary>
public const string NamespaceInteroperability = "urn:xmpp:iot:interoperability";
/// <summary>
/// Implements the server-side for Interoperability interfaces, as defined in:
///
/// https://github.com/joachimlindborg/XMPP-IoT/blob/master/xep-0000-IoT-Interoperability.html
/// http://htmlpreview.github.io/?https://github.com/joachimlindborg/XMPP-IoT/blob/master/xep-0000-IoT-Interoperability.html
/// </summary>
/// <param name="Client">XMPP Client</param>
public InteroperabilityServer(XmppClient Client)
: base(Client)
{
this.client.RegisterIqGetHandler("getInterfaces", NamespaceInteroperability, this.GetInterfacesHandler, true);
}
/// <inheritdoc/>
public override void Dispose()
{
base.Dispose();
this.client.UnregisterIqGetHandler("getInterfaces", NamespaceInteroperability, this.GetInterfacesHandler, true);
}
/// <summary>
/// Implemented extensions.
/// </summary>
public override string[] Extensions => new string[0];
private async Task GetInterfacesHandler(object Sender, IqEventArgs e)
{
XmlElement E = e.Query;
string NodeId = XML.Attribute(E, "id");
string SourceId = XML.Attribute(E, "src");
string Partition = XML.Attribute(E, "pt");
string ServiceToken = XML.Attribute(E, "st");
string DeviceToken = XML.Attribute(E, "dt");
string UserToken = XML.Attribute(E, "ut");
InteroperabilityServerEventArgs e2 = new InteroperabilityServerEventArgs(NodeId, SourceId, Partition, ServiceToken, DeviceToken, UserToken);
await this.OnGetInterfaces.Raise(this, e2, false);
StringBuilder Xml = new StringBuilder();
Xml.Append("<getInterfacesResponse xmlns='");
Xml.Append(NamespaceInteroperability);
Xml.Append("'>");
foreach (string Interface in e2.Interfaces)
{
Xml.Append("<interface name='");
Xml.Append(XML.Encode(Interface));
Xml.Append("'/>");
}
Xml.Append("</getInterfacesResponse>");
await e.IqResult(Xml.ToString());
}
/// <summary>
/// Event raised when a client requests supported interoperability interfaces.
/// </summary>
public event EventHandlerAsync<InteroperabilityServerEventArgs> OnGetInterfaces = null;
}
}