Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SendSubscriptionDeclined.cs
1using System;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
12using Waher.Script;
15
17{
22 {
27 : base("Xmpp/SendSubscriptionDeclined",
28 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
29 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
30 {
31 }
32
33 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(SendSubscriptionDeclined).Namespace + ".JSON.SendSubscriptionDeclined.req");
34 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(SendSubscriptionDeclined).Namespace + ".XML.SendSubscriptionDeclined.req");
35
44 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
45 {
47
48 string To = (string)Parameters["PTo"].AssociatedObjectValue;
49
50 if (string.IsNullOrEmpty(To))
51 throw new BadRequestException("Missing recipient JID.");
52
53 if (!IsValidBareJID(To))
54 throw new BadRequestException("Recpient must be a Bare JID.");
55 string Id = (string)Parameters["PId"]?.AssociatedObjectValue;
56
57 if (string.IsNullOrEmpty(Id))
58 Id = Guid.NewGuid().ToString();
59
60 bool Result;
61
62 if (XmppServerModule.Server is null)
63 {
65
66 if (Client is null)
67 {
68 if (Types.TryGetModuleParameter("XMPP", out XmppClient Client2))
69 Client = Client2;
70 }
71
72 if (Client is null)
73 throw new ServiceUnavailableException("XMPP Client not available.");
74
76 ?? throw new NotFoundException("Presence subscription request not found.");
77
78 Id = e.Id;
79
80 await e.Decline();
81 Result = true;
82 }
83 else
84 {
85 Result = await XmppServerModule.Server.Presence("unsubscribed", Id,
86 new XmppAddress(To),
87 new XmppAddress(User.UserName + "@" + XmppServerModule.Server.Domain),
88 string.Empty, string.Empty, XmppServerModule.Server);
89 }
90
91 await Response.Return(new NamedDictionary<string, object>("StanzaResult", AgentNamespace)
92 {
93 { "sent", Result },
94 { "id", Id }
95 });
96 }
97 }
98}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static XmppClient XmppClient
XMPP Client connection of gateway.
Definition: Gateway.cs:4038
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
Definition: HttpRequest.cs:22
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
Task Return(Exception ex)
Returns an error to the client.
The server has not found anything matching the Request-URI. No indication is given of whether the con...
The server is currently unable to handle the request due to a temporary overloading or maintenance of...
Event arguments for presence events.
async Task Decline()
Declines a subscription or unsubscription request.
string Id
ID attribute of presence stanza.
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
static readonly XmppAddress Empty
Empty address.
Definition: XmppAddress.cs:31
CaseInsensitiveString Domain
Domain name.
Definition: XmppServer.cs:922
async Task< bool > Presence(string Type, string Id, XmppAddress From, string Language, Stanza Stanza, ISender Sender)
Presence stanza.
Definition: XmppServer.cs:2997
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:58
PresenceEventArgs GetSubscriptionRequest(string BareJID)
Gets a presence subscription request
Definition: XmppClient.cs:4759
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:13
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:55
Static class that dynamically manages types and interfaces available in the runtime environment.
Definition: Types.cs:15
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
Definition: Types.cs:607
Class managing a script expression.
Definition: Expression.cs:41
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
Abstract base class for XMPP resources.
static bool IsValidBareJID(string JID)
Checks if a string is a valid Bare JID.
Declines a presence subscription request made to the XMPP account.
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
SendSubscriptionDeclined()
Declines a presence subscription request made to the XMPP account.
Service Module hosting the XMPP broker and its components.