Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AgentXmppPostResource.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
11using Waher.Script;
13
15{
20 {
26 public AgentXmppPostResource(string AgentResourceName,
27 params KeyValuePair<Type, Expression>[] PatternMatches)
28 : base(AgentResourceName, PatternMatches)
29 {
30 }
31
37 protected static bool IsValidBareJID(string JID)
38 {
39 return IsValidJID(JID, false, true, false);
40 }
41
47 protected static bool IsValidFullJID(string JID)
48 {
49 return IsValidJID(JID, false, false, true);
50 }
51
57 protected static bool IsValidJID(string JID)
58 {
59 return IsValidJID(JID, true, true, true);
60 }
61
67 protected static bool IsValidJID(string JID, bool AllowDomainJID, bool AllowBareJID, bool AllowFullJID)
68 {
70 {
71 if (JID.EndsWith("@"))
72 JID += "example.com";
73 else
74 {
75 int i = JID.IndexOf("@/");
76 if (i > 0)
77 JID = JID.Insert(i + 1, "example.com");
78 }
79 }
80
81 if (AllowBareJID && XmppClient.BareJidRegEx.IsMatch(JID))
82 return true;
83
84 if (AllowFullJID && XmppClient.FullJidRegEx.IsMatch(JID))
85 return true;
86
87 if (AllowDomainJID && XmppClient.DomainJidRegEx.IsMatch(JID))
88 return true;
89
90 return false;
91 }
92
99 protected static async Task<string> GetApprovedLegalIDXml(string Account)
100 {
101 DateTime Now = DateTime.Now;
102
103 LegalIdentity ID = await Database.FindFirstIgnoreRest<LegalIdentity>(new FilterAnd(
104 new FilterFieldEqualTo("Account", Account),
105 new FilterFieldEqualTo("State", IdentityState.Approved),
106 new FilterFieldLesserOrEqualTo("From", Now),
107 new FilterFieldGreaterOrEqualTo("To", Now)), "-Created");
108
109 if (ID is null)
110 return string.Empty;
111
112 StringBuilder Xml = new StringBuilder();
113 LegalIDXml(ID, Xml);
114
115 return Xml.ToString();
116 }
117
118 private static string LegalIDXml(LegalIdentity ID, StringBuilder Xml)
119 {
120 string BareJid = null;
121
122 foreach (Property P in ID.Properties)
123 {
124 if (P.Name == "JID")
125 {
126 BareJid = P.Value;
127 break;
128 }
129 }
130
131 if (string.IsNullOrEmpty(BareJid))
132 return string.Empty;
133
134 Xml.Append("<qlRef xmlns='");
136 Xml.Append("' bareJid='");
137 Xml.Append(XML.Encode(BareJid));
138 Xml.Append("'>");
139
140 ID.Serialize(Xml, true, true, true, true, true, true, true, null, XmppServerModule.Legal);
141
142 Xml.Append("</qlRef>");
143
144 return string.Empty;
145 }
146 }
147}
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:27
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static CaseInsensitiveString Domain
Domain name.
Definition: Gateway.cs:2354
Abstract base class for XMPP client connections
const string QuickLoginNamespace
http://waher.se/Schema/QL.xsd
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
static readonly Regex DomainJidRegEx
Regular expression for Domain JIDs
Definition: XmppClient.cs:193
static readonly Regex FullJidRegEx
Regular expression for Full JIDs
Definition: XmppClient.cs:183
static readonly Regex BareJidRegEx
Regular expression for Bare JIDs
Definition: XmppClient.cs:188
Represents a case-insensitive string.
static readonly CaseInsensitiveString Empty
Empty case-insensitive string
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:19
This filter selects objects that conform to all child-filters provided.
Definition: FilterAnd.cs:10
This filter selects objects that have a named field equal to a given value.
This filter selects objects that have a named field greater or equal to a given value.
This filter selects objects that have a named field lesser or equal to a given value.
Abstract base class for agent resources supporting the POST method.
Abstract base class for XMPP resources.
static bool IsValidJID(string JID)
Checks if a string is a valid Bare or Full JID.
static bool IsValidFullJID(string JID)
Checks if a string is a valid Full JID.
static bool IsValidBareJID(string JID)
Checks if a string is a valid Bare JID.
static bool IsValidJID(string JID, bool AllowDomainJID, bool AllowBareJID, bool AllowFullJID)
Checks if a string is a valid Bare or Full JID.
static async Task< string > GetApprovedLegalIDXml(string Account)
Gets XML containing the latest approvied Legal ID for an account, for inclusion in requests to peers.
AgentXmppPostResource(string AgentResourceName, params KeyValuePair< Type, Expression >[] PatternMatches)
Abstract base class for XMPP resources.
Service Module hosting the XMPP broker and its components.