private async void CachedIqCallback(object Sender, IqResultEventArgs e) { try { object[] P = (object[])e.State; IqResultEventHandler Callback = (IqResultEventHandler)P[0]; object State = P[1]; string Xml = (string)P[2]; string Method = (string)P[3]; CachedQuery Query = new CachedQuery() { Xml = Xml, Method = Method, Response = e.Response.OuterXml, LastUsed = DateTime.Now }; await Database.Insert(Query); if (Callback != null) { e.State = State; Callback(Sender, e); } await this.DeleteOld(); } catch (Exception ex) { Log.Critical(ex); } }
private bool Respond(bool CanRead, string RuleXml, IqResultEventHandler Callback, object State) { StringBuilder Xml = new StringBuilder(); Xml.Append("<canReadRule xmlns='"); Xml.Append(ProvisioningClient.NamespaceProvisioningOwner); Xml.Append("' jid='"); Xml.Append(XML.Encode(this.JID)); Xml.Append("' remoteJid='"); Xml.Append(XML.Encode(this.RemoteJID)); Xml.Append("' key='"); Xml.Append(XML.Encode(this.Key)); Xml.Append("' result='"); Xml.Append(CommonTypes.Encode(CanRead)); Xml.Append("'>"); Xml.Append(RuleXml); Xml.Append("</canRaedRule>"); RosterItem Item = this.Client[this.FromBareJID]; if (Item.HasLastPresence && Item.LastPresence.IsOnline) { this.Client.SendIqSet(Item.LastPresenceFullJid, Xml.ToString(), Callback, State); return(true); } else { return(false); } }
/// <summary> /// Unregisters a thing from the thing registry. /// </summary> /// <param name="NodeId">Node ID of thing, if behind a concentrator.</param> /// <param name="SourceId">Source ID of thing, if behind a concentrator.</param> /// <param name="Partition">Partition of thing, if behind a concentrator.</param> /// <param name="Callback">Callback method.</param> /// <param name="State">State object passed on to callback method.</param> public void Unregister(string NodeId, string SourceId, string Partition, IqResultEventHandler Callback, object State) { StringBuilder Request = new StringBuilder(); Request.Append("<unregister xmlns='"); Request.Append(NamespaceDiscovery); this.AddNodeInfo(Request, NodeId, SourceId, Partition); Request.Append("'/>"); this.client.SendIqSet(this.thingRegistryAddress, Request.ToString(), (sender, e) => { if (Callback != null) { try { Callback(this, e); } catch (Exception ex) { Log.Critical(ex); } } }, null); }
private void CallCallback(IqResultEventHandler Callback, object State, IqResultEventArgs e) { if (Callback != null) { try { Callback(this, e); } catch (Exception ex) { Log.Critical(ex); } } }
internal PendingRequest(uint SeqNr, PresenceEventHandler Callback, object State, int RetryTimeout, int NrRetries, bool DropOff, int MaxRetryTimeout, string To) { this.seqNr = SeqNr; this.iqCallback = null; this.presenceCallback = Callback; this.state = State; this.retryTimeout = RetryTimeout; this.nrRetries = NrRetries; this.maxRetryTimeout = MaxRetryTimeout; this.dropOff = DropOff; this.to = To; this.timeout = DateTime.Now.AddMilliseconds(RetryTimeout); }
/// <summary> /// Clears the rule cache of a device. /// </summary> /// <param name="DeviceJID">Bare JID of device whose rule cache is to be cleared. /// If null, all owned devices will get their rule caches cleared.</param> /// <param name="Callback">Method to call when response is returned.</param> /// <param name="State">State object to pass on to callback method.</param> public void ClearDeviceCache(string DeviceJID, IqResultEventHandler Callback, object State) { StringBuilder Xml = new StringBuilder(); Xml.Append("<clearCache xmlns='"); Xml.Append(NamespaceProvisioningOwner); if (!string.IsNullOrEmpty(DeviceJID)) { Xml.Append("' jid='"); Xml.Append(XML.Encode(DeviceJID)); } Xml.Append("'/>"); this.client.SendIqSet(this.provisioningServerAddress, Xml.ToString(), Callback, State); }
private async Task CachedIq(string Xml, string Method, IqResultEventHandler Callback, object State) { CachedQuery Query = await Database.FindFirstDeleteRest <CachedQuery>(new FilterAnd( new FilterFieldEqualTo("Xml", Xml), new FilterFieldEqualTo("Method", Method))); if (Query != null) { Query.LastUsed = DateTime.Now; await Database.Update(Query); if (Callback != null) { try { XmlDocument Doc = new XmlDocument(); Doc.LoadXml(Query.Response); XmlElement E = Doc.DocumentElement; string Type = XML.Attribute(E, "type"); string Id = XML.Attribute(E, "id"); string To = XML.Attribute(E, "to"); string From = XML.Attribute(E, "from"); bool Ok = (Type == "result"); IqResultEventArgs e = new IqResultEventArgs(E, Id, To, From, Ok, State); Callback(this.client, e); } catch (Exception ex) { Log.Critical(ex); } } } else { this.client.SendIq(null, this.provisioningServerAddress, Xml, "get", this.CachedIqCallback, new object[] { Callback, State, Xml, Method }, this.client.DefaultRetryTimeout, this.client.DefaultNrRetries, this.client.DefaultDropOff, this.client.DefaultMaxRetryTimeout); } }
/// <summary> /// Unblocks all JIDs /// </summary> /// <param name="Callback">Callback method.</param> /// <param name="State">State object to pass on to callback method.</param> public void UnblockAll(IqResultEventHandler Callback, object State) { if (this.supportsBlocking) { this.client.SendIqSet(this.client.Domain, "<unblock xmlns='" + NamespaceBlocking + "'/>", (sender, e) => { if (e.Ok) { lock (this.blockList) { this.blockList.Clear(); } } this.CallCallback(Callback, State, e); }, null); } else { this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, false, State)); } }
private void BeginSearchSupport() { Client.SendServiceDiscoveryRequest(Client.Domain, (sender, e) => { if (e.Ok) { this.supportsBlocking = e.HasFeature(NamespaceBlocking); this.supportsReporting = e.HasFeature(NamespaceReporting); this.supportsSpamReason = e.HasFeature(NamespaceSpamReason); this.supportsAbuseReason = e.HasFeature(NamespaceAbuseReason); if (this.supportsBlocking) { this.StartGetBlockList(null, null); } } else { this.supportsBlocking = false; this.supportsReporting = false; this.supportsSpamReason = false; this.supportsAbuseReason = false; } IqResultEventHandler h = this.OnSearchSupportResponse; if (h != null) { try { h(this, e); } catch (Exception ex) { Log.Critical(ex); } } }, null); }
/// <summary> /// Unblocks a JID /// </summary> /// <param name="JID">JID to unblock.</param> /// <param name="Callback">Callback method.</param> /// <param name="State">State object to pass on to callback method.</param> public void UnblockJID(string JID, IqResultEventHandler Callback, object State) { bool Blocked; lock (this.blockList) { if (!this.blockList.TryGetValue(JID, out Blocked)) { Blocked = false; } } if (!Blocked) { this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, true, State)); } else if (this.supportsBlocking) { this.client.SendIqSet(this.client.Domain, "<unblock xmlns='" + NamespaceBlocking + "'><item jid='" + JID + "'/></unblock>", (sender, e) => { if (e.Ok) { lock (this.blockList) { this.blockList.Remove(JID); } } this.CallCallback(Callback, State, e); }, null); } else { this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, false, State)); } }
/// <summary> /// Removes a publicly claimed thing from the thing registry, so that it does not appear in search results. /// </summary> /// <param name="ThingJid">JID of thing to disown.</param> /// <param name="NodeId">Optional Node ID of thing.</param> /// <param name="Callback">Method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> public void Remove(string ThingJid, string NodeId, IqResultEventHandler Callback, object State) { this.Remove(ThingJid, NodeId, string.Empty, string.Empty, Callback, State); }
private void Respond(bool IsFriend, RuleRange Range, IqResultEventHandler Callback, object State) { this.Client.IsFriendResponse(this.JID, this.RemoteJID, this.Key, IsFriend, Range, Callback, State); }
/// <summary> /// Blocks a JID /// </summary> /// <param name="JID">JID to block.</param> /// <param name="Reason">Reason for blocking JID.</param> /// <param name="Callback">Callback method.</param> /// <param name="State">State object to pass on to callback method.</param> public void BlockJID(string JID, ReportingReason Reason, IqResultEventHandler Callback, object State) { bool Blocked; lock (this.blockList) { if (!this.blockList.TryGetValue(JID, out Blocked)) { Blocked = false; } } if (Blocked) { this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, true, State)); } else if (this.supportsBlocking) { StringBuilder Xml = new StringBuilder(); Xml.Append("<block xmlns='"); Xml.Append(NamespaceBlocking); Xml.Append("'><item jid='"); Xml.Append(JID); if (!this.supportsReporting) { Xml.Append("'/></block>"); } else if (Reason == ReportingReason.Spam && this.supportsSpamReason) { Xml.Append("'><report xmlns='"); Xml.Append(NamespaceReporting); Xml.Append("'><spam/></report></item></block>"); } else if (Reason == ReportingReason.Abuse && this.supportsAbuseReason) { Xml.Append("'><report xmlns='"); Xml.Append(NamespaceReporting); Xml.Append("'><abuse/></report></item></block>"); } else { Xml.Append("'/></block>"); } this.client.SendIqSet(this.client.Domain, Xml.ToString(), (sender, e) => { if (e.Ok) { lock (this.blockList) { this.blockList[JID] = true; } } this.CallCallback(Callback, State, e); }, null); } else { this.CallCallback(Callback, State, new IqResultEventArgs(null, string.Empty, string.Empty, string.Empty, false, State)); } }
/// <summary> /// Accept partial readouts from all entities of the remote domain. /// </summary> /// <param name="Fields">Fields that can be read.</param> /// <param name="FieldTypes">Field categories that can be read.</param> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool AcceptPartialFromDomain(string[] Fields, FieldType FieldTypes, IqResultEventHandler Callback, object State) { return(this.Respond(true, this.PartialFields(Fields, FieldTypes) + "<fromDomain/>", Callback, State)); }
/// <summary> /// Accept partial readouts from this device. /// </summary> /// <param name="Fields">Fields that can be read.</param> /// <param name="FieldTypes">Field categories that can be read.</param> /// <param name="DeviceToken">Which device token is to be accepted.</param> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool AcceptPartialFromDevice(string[] Fields, FieldType FieldTypes, string DeviceToken, IqResultEventHandler Callback, object State) { return(this.Respond(true, this.PartialFields(Fields, FieldTypes) + "<fromDevice token='" + XML.Encode(DeviceToken) + "'/>", Callback, State)); }
/// <summary> /// Rejects the friendship, and similar future requests from the entire remote domain. /// </summary> public void RejectForEntireDomain(IqResultEventHandler Callback, object State) { this.Respond(false, RuleRange.Domain, Callback, State); }
/// <summary> /// Rejects the friendship. /// </summary> public void Reject(IqResultEventHandler Callback, object State) { this.Respond(false, RuleRange.Caller, Callback, State); }
/// <summary> /// Reject control operations from this remote JID. /// </summary> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool RejectAllFromJID(IqResultEventHandler Callback, object State) { return(this.Respond(false, "<fromJid/>", Callback, State)); }
/// <summary> /// Accept control operations from all entities of the remote domain. /// </summary> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool AcceptAllFromDomain(IqResultEventHandler Callback, object State) { return(this.Respond(true, "<fromDomain/>", Callback, State)); }
/// <summary> /// Accept partial control operations from all entities of the remote domain. /// </summary> /// <param name="Parameters">Parameters that can be controlled.</param> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool AcceptPartialFromDomain(string[] Parameters, IqResultEventHandler Callback, object State) { return(this.Respond(true, this.PartialParameters(Parameters) + "<fromDomain/>", Callback, State)); }
/// <summary> /// Rejects the friendship. /// </summary> /// <returns>If the response could be sent.</returns> public bool Reject(IqResultEventHandler Callback, object State) { return(this.Respond(false, Callback, State)); }
/// <summary> /// Accepts the friendship. /// </summary> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool Accept(IqResultEventHandler Callback, object State) { return(this.Respond(true, Callback, State)); }
/// <summary> /// Accepts the friendship, and all future requests. /// </summary> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> public void AcceptForAll(IqResultEventHandler Callback, object State) { this.Respond(true, RuleRange.All, Callback, State); }
/// <summary> /// Deletes a message object from the broker. /// </summary> /// <param name="ObjectId">ID of the message object to delete.</param> /// <param name="Callback">Method to call when response has been returned.</param> /// <param name="State">State object to pass on to callback method.</param> public void Delete(string ObjectId, IqResultEventHandler Callback, object State) { this.client.SendIqSet(this.client.Domain, "<delete xmlns='" + NamespaceMail + "' cid='" + XML.Encode(ObjectId) + "'/>", Callback, State); }
/// <summary> /// Accept partial control operations from this user. /// </summary> /// <param name="Parameters">Parameters that can be controlled.</param> /// <param name="UserToken">Which user token is to be accepted.</param> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool AcceptPartialFromUser(string[] Parameters, string UserToken, IqResultEventHandler Callback, object State) { return(this.Respond(true, this.PartialParameters(Parameters) + "<fromUser token='" + XML.Encode(UserToken) + "'/>", Callback, State)); }
/// <summary> /// Unregisters a thing from the thing registry. /// </summary> /// <param name="Callback">Callback method.</param> /// <param name="State">State object passed on to callback method.</param> public void Unregister(IqResultEventHandler Callback, object State) { this.Unregister(string.Empty, string.Empty, string.Empty, Callback, State); }
/// <summary> /// Reject control operations from this user. /// </summary> /// <param name="UserToken">Which user token is to be rejected.</param> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool RejectAllFromUser(string UserToken, IqResultEventHandler Callback, object State) { return(this.Respond(false, "<fromUser token='" + XML.Encode(UserToken) + "'/>", Callback, State)); }
/// <summary> /// Unregisters a thing from the thing registry. /// </summary> /// <param name="NodeId">Node ID of thing, if behind a concentrator.</param> /// <param name="SourceId">Source ID of thing, if behind a concentrator.</param> /// <param name="Callback">Callback method.</param> /// <param name="State">State object passed on to callback method.</param> public void Unregister(string NodeId, string SourceId, IqResultEventHandler Callback, object State) { this.Unregister(NodeId, SourceId, string.Empty, Callback, State); }
/// <summary> /// Accept control operations from this service. /// </summary> /// <param name="ServiceToken">Which service token is to be accepted.</param> /// <param name="Callback">Callback method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> /// <returns>If the response could be sent.</returns> public bool AcceptAllFromService(string ServiceToken, IqResultEventHandler Callback, object State) { return(this.Respond(true, "<fromService token='" + XML.Encode(ServiceToken) + "'/>", Callback, State)); }
/// <summary> /// Disowns a thing, so that it can be claimed by another. /// </summary> /// <param name="ThingJid">JID of thing to disown.</param> /// <param name="NodeId">Optional Node ID of thing.</param> /// <param name="SourceId">Optional Source ID of thing.</param> /// <param name="Callback">Method to call when response is received.</param> /// <param name="State">State object to pass on to the callback method.</param> public void Disown(string ThingJid, string NodeId, string SourceId, IqResultEventHandler Callback, object State) { this.Disown(ThingJid, NodeId, SourceId, string.Empty, Callback, State); }