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 Paiwise;
2using System;
4using System.Text;
5using System.Threading.Tasks;
12using Waher.Script;
14
16{
21 {
27 public AgentXmppPostResource(string AgentResourceName,
28 params KeyValuePair<Type, Expression>[] PatternMatches)
29 : base(AgentResourceName, PatternMatches)
30 {
31 }
32
38 protected static bool IsValidBareJID(string JID)
39 {
40 return IsValidJID(JID, false, true, false);
41 }
42
48 protected static bool IsValidFullJID(string JID)
49 {
50 return IsValidJID(JID, false, false, true);
51 }
52
58 protected static bool IsValidJID(string JID)
59 {
60 return IsValidJID(JID, true, true, true);
61 }
62
68 protected static bool IsValidJID(string JID, bool AllowDomainJID, bool AllowBareJID, bool AllowFullJID)
69 {
70 if (!Gateway.HasDomain)
71 {
72 if (JID.EndsWith("@"))
73 JID += "example.com";
74 else
75 {
76 int i = JID.IndexOf("@/");
77 if (i > 0)
78 JID = JID.Insert(i + 1, "example.com");
79 }
80 }
81
82 if (AllowBareJID && XmppClient.BareJidRegEx.IsMatch(JID))
83 return true;
84
85 if (AllowFullJID && XmppClient.FullJidRegEx.IsMatch(JID))
86 return true;
87
88 if (AllowDomainJID && XmppClient.DomainJidRegEx.IsMatch(JID))
89 return true;
90
91 return false;
92 }
93
100 protected static async Task<string> GetApprovedLegalIDXml(string Account)
101 {
102 DateTime Now = DateTime.Now;
103
104 LegalIdentity ID = await Database.FindFirstIgnoreRest<LegalIdentity>(new FilterAnd(
105 new FilterFieldEqualTo("Account", Account),
106 new FilterFieldEqualTo("State", IdentityState.Approved),
107 new FilterFieldLesserOrEqualTo("From", Now),
108 new FilterFieldGreaterOrEqualTo("To", Now)), "-Created");
109
110 if (ID is null)
111 return string.Empty;
112
113 StringBuilder Xml = new StringBuilder();
114 LegalIDXml(ID, Xml);
115
116 return Xml.ToString();
117 }
118
119 private static string LegalIDXml(LegalIdentity ID, StringBuilder Xml)
120 {
121 string BareJid = null;
122
123 foreach (Property P in ID.Properties)
124 {
126 {
127 BareJid = P.Value;
128 break;
129 }
130 }
131
132 if (string.IsNullOrEmpty(BareJid))
133 return string.Empty;
134
135 Xml.Append("<qlRef xmlns='");
137 Xml.Append("' bareJid='");
138 Xml.Append(XML.Encode(BareJid));
139 Xml.Append("'>");
140
141 ID.Serialize(Xml, true, true, true, true, true, true, true, null, XmppServerModule.Legal);
142
143 Xml.Append("</qlRef>");
144
145 return string.Empty;
146 }
147 }
148}
Contains personal information found in a legal identity.
Helps with common XML-related tasks.
Definition: XML.cs:21
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:29
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static bool HasDomain
If a domain name is configured.
Definition: Gateway.cs:3093
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:58
static readonly Regex DomainJidRegEx
Regular expression for Domain JIDs
Definition: XmppClient.cs:192
static readonly Regex FullJidRegEx
Regular expression for Full JIDs
Definition: XmppClient.cs:182
static readonly Regex BareJidRegEx
Regular expression for Bare JIDs
Definition: XmppClient.cs:187
static readonly CaseInsensitiveString Empty
Empty case-insensitive string
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
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.