internal SearchFormEventArgs(XmppClient Client, IqResultEventArgs e, string Instructions, string First, string Last, string Nick, string EMail, DataForm SearchForm) : base(e) { this.client = Client; this.instructions = Instructions; this.first = First; this.last = Last; this.nick = Nick; this.email = EMail; this.searchForm = SearchForm; }
internal CertificateEventArgs(IqResultEventArgs e, object State, byte[] CertificateBlob) : base(e) { this.State = State; #if WINDOWS_UWP IBuffer Buffer = CryptographicBuffer.CreateFromByteArray(CertificateBlob); this.certificate = new Certificate(Buffer); #else this.certificate = new X509Certificate2(CertificateBlob); #endif }
private void ForwardedTokenChallengeResponse(object Sender, IqResultEventArgs e2) { IqEventArgs e = (IqEventArgs)e2.State; if (e2.Ok) { e.IqResult(e2.FirstElement.OuterXml); } else { e.IqError(e2.ErrorElement.OuterXml); } }
private void CallCallback(IqResultEventHandler Callback, object State, IqResultEventArgs e) { if (Callback != null) { try { Callback(this, e); } catch (Exception ex) { Log.Critical(ex); } } }
private void FormUpdated(object Sender, IqResultEventArgs e) { if (e.Ok && Sender is XmppClient Client && Client != null) { foreach (XmlNode N in e.Response) { if (N.LocalName == "x") { DataForm UpdatedForm = new DataForm(Client, (XmlElement)N, null, null, e.From, e.To); this.form.Join(UpdatedForm); } } } }
private async Task BlockAck(object Sender, IqResultEventArgs e) { if (this.tempFile is null || this.aborted) { return; } if (!e.Ok) { this.Dispose(); return; } if (!await this.syncObject.TryBeginWrite(10000)) { throw new TimeoutException(); } try { int Seq2 = (int)e.State; if (Seq2 <= this.seqAcknowledged) { return; // Response to a retry } this.seqAcknowledged = Seq2; long NrLeft = this.tempFile.Length - this.pos; if (NrLeft >= this.blockSize || (this.done && NrLeft > 0)) { await this.WriteBlockLocked(); } else { this.isWriting = false; if (this.done) { this.SendClose(); this.Dispose(); } } } finally { await this.syncObject.EndWrite(); } }
private async Task InitiationResponse(object Sender, IqResultEventArgs e) { InitiationRec Rec = (InitiationRec)e.State; if (e.Ok) { XmlElement E = e.FirstElement; if (E != null && E.LocalName == "query" && E.NamespaceURI == Namespace && XML.Attribute(E, "sid") == Rec.streamId) { XmlElement E2; string StreamHostUsed = null; foreach (XmlNode N in E.ChildNodes) { E2 = N as XmlElement; if (E2.LocalName == "streamhost-used" && E2.NamespaceURI == Namespace) { StreamHostUsed = XML.Attribute(E2, "jid"); break; } } if (!string.IsNullOrEmpty(StreamHostUsed) && StreamHostUsed == this.host) { Rec.stream = new Socks5Client(this.host, this.port, this.jid); Rec.stream.OnStateChange += Rec.StateChanged; lock (this.streams) { this.streams[Rec.streamId] = Rec.stream; } } else { await this.Callback(Rec.callback, Rec.state, false, null, Rec.streamId); } } else { await this.Callback(Rec.callback, Rec.state, false, null, Rec.streamId); } } else { await this.Callback(Rec.callback, Rec.state, false, null, Rec.streamId); } }
private async Task ActivationResponse(object Sender, IqResultEventArgs e) { InitiationRec Rec = (InitiationRec)e.State; if (e.Ok) { await this.Callback(Rec.callback, Rec.state, true, Rec.stream, Rec.streamId); } else { Rec.stream.Dispose(); await this.Callback(Rec.callback, Rec.state, false, null, Rec.streamId); } Rec.callback = null; }
private async Task GetFormResult(object Sender, IqResultEventArgs e) { object[] P = (object[])e.State; DataFormResultEventHandler Callback = (DataFormResultEventHandler)P[0]; if (Callback is null) { return; } object State = P[1]; ThingReference[] Nodes = (ThingReference[])P[2]; DataForm Form = null; if (e.Ok) { foreach (XmlNode N in e.Response.ChildNodes) { if (N.LocalName == "x") { Form = new DataForm(this.client, (XmlElement)N, this.SubmitForm, this.CancelForm, e.From, e.To); break; } } if (!(Form is null)) { Form.State = Nodes; } } if (!(Callback is null)) { DataFormEventArgs e2 = new DataFormEventArgs(Form, e); try { e2.State = State; await Callback(this, e2); } catch (Exception ex) { Log.Critical(ex); } } }
private Task SocksQueryResponse(object Sender, IqResultEventArgs e3) { if (e3.Ok) { XmlElement E = (XmlElement)e3.FirstElement; if (E.LocalName == "query" && E.NamespaceURI == Namespace) { E = (XmlElement)E.FirstChild; if (E.LocalName == "streamhost" && E.NamespaceURI == Namespace) { this.Proxy.jid = XML.Attribute(E, "jid"); this.Proxy.port = XML.Attribute(E, "port", 0); this.Proxy.host = XML.Attribute(E, "host"); this.Proxy.hasProxy = !string.IsNullOrEmpty(this.Proxy.jid) && !string.IsNullOrEmpty(this.Proxy.host) && this.Proxy.port > 0; if (this.Proxy.hasProxy) { this.SearchDone(); } else { this.Advance(); } } else { this.Advance(); } } else { this.Advance(); } } else { this.Advance(); } return(Task.CompletedTask); }
private async void RuleCallback(object Sender, IqResultEventArgs e) { try { if (e.Ok) { await this.Processed(this.questionView); } else { MainWindow.ErrorBox(string.IsNullOrEmpty(e.ErrorText) ? "Unable to set rule." : e.ErrorText); } } catch (Exception ex) { ex = Log.UnnestException(ex); MainWindow.ErrorBox(ex.Message); } }
public void QoS_Test_04_Timeout() { ManualResetEvent Done = new ManualResetEvent(false); IqResultEventArgs e2 = null; this.client2.RegisterIqGetHandler("test", "test", (sender, e) => { // Do nothing. Do not return result or error. }, false); this.client1.SendIqGet(this.client2.FullJID, "<test:test xmlns:test='test'/>", (sender, e) => { e2 = e; Done.Set(); }, null, 1000, 3, true, int.MaxValue); Assert.IsTrue(Done.WaitOne(20000), "Retry function not working properly."); Assert.IsFalse(e2.Ok, "Request not properly cancelled."); }
private async Task CallResponseMethod(SearchResultEventHandler Callback, object State, List <Dictionary <string, string> > Records, Field[] Headers, IqResultEventArgs e) { SearchResultEventArgs e2 = new SearchResultEventArgs(Records.ToArray(), Headers, e) { State = State }; if (!(Callback is null)) { try { await Callback(this.client, e2); } catch (Exception ex) { this.client.Exception(ex); } } }
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); } }
private void BlockAck(object Sender, IqResultEventArgs e) { if (this.tempFile == null || this.aborted) { return; } if (!e.Ok) { this.Dispose(); return; } lock (this.tempFile) { int Seq2 = (int)e.State; if (Seq2 <= this.seqAcknowledged) { return; // Response to a retry } this.seqAcknowledged = Seq2; long NrLeft = this.tempFile.Length - this.pos; if (NrLeft >= this.blockSize || (this.done && NrLeft > 0)) { this.WriteBlockLocked(); } else { this.isWriting = false; if (this.done) { this.SendClose(); this.Dispose(); } } } }
private void BooleanResponse(IqResultEventArgs e, string ExpectedElement, BooleanResponseEventHandler Callback, object State) { XmlElement E; if (!e.Ok || (E = e.FirstElement) == null || E.LocalName != ExpectedElement || !CommonTypes.TryParse(E.InnerText, out bool Response)) { e.Ok = false; Response = false; } if (Callback != null) { try { Callback(this, new BooleanResponseEventArgs(Response, e)); } catch (Exception ex) { Log.Critical(ex); } } }
private void GetInterfacesResult(object Sender, IqResultEventArgs e) { List <string> Interfaces = new List <string>(); object[] P = (object[])e.State; InteroperabilityInterfacesClientEventHandler Callback = (InteroperabilityInterfacesClientEventHandler)P[0]; object State = P[1]; if (e.Ok) { foreach (XmlNode N in e.Response.ChildNodes) { if (N.LocalName == "getInterfacesResponse") { foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "interface") { Interfaces.Add(XML.Attribute((XmlElement)N2, "name")); } } } } } InteroperabilityClientEventArgs e2 = new InteroperabilityClientEventArgs(Interfaces.ToArray(), e); if (Callback != null) { try { Callback(this, e2); } catch (Exception ex) { Log.Critical(ex); } } }
private void BooleansResponse(IqResultEventArgs e, string ExpectedElement, BooleansResponseEventHandler Callback, object State) { List <bool> Responses = new List <bool>(); XmlElement E; if (e.Ok && (E = e.FirstElement) != null && E.LocalName == ExpectedElement && E.NamespaceURI == ConcentratorServer.NamespaceConcentrator) { foreach (XmlNode N in E) { if (N is XmlElement E2 && E2.LocalName == "value") { if (CommonTypes.TryParse(E2.InnerText, out bool Value)) { Responses.Add(Value); } else { e.Ok = false; } } } } else { e.Ok = false; } if (Callback != null) { try { Callback(this, new BooleansResponseEventArgs(Responses.ToArray(), e)); } catch (Exception ex) { Log.Critical(ex); } } }
private void NodesResponse(IqResultEventArgs e, string ExpectedElement, bool Parameters, bool Messages, NodesInformationEventHandler Callback, object State) { XmlElement E; NodeInformation[] NodeInfo; if (e.Ok && (E = e.FirstElement) != null && E.LocalName == ExpectedElement) { List <NodeInformation> Nodes = new List <NodeInformation>(); foreach (XmlNode N in E.ChildNodes) { if (N is XmlElement E2 && E2.LocalName == "nd") { Nodes.Add(this.GetNodeInformation(E2, Parameters, Messages)); } } NodeInfo = Nodes.ToArray(); } else { e.Ok = false; NodeInfo = null; } if (Callback != null) { try { Callback(this, new NodesInformationEventArgs(NodeInfo, e)); } catch (Exception ex) { Log.Critical(ex); } } }
private void OldSearchResult(object Sender, IqResultEventArgs e) { object[] P = (object[])e.State; SearchResultEventHandler Callback = (SearchResultEventHandler)P[0]; object State = P[1]; List <Dictionary <string, string> > Records = new List <Dictionary <string, string> >(); if (e.Ok) { foreach (XmlNode N in e.Response.ChildNodes) { if (N.LocalName == "query") { foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "item") { Dictionary <string, string> Record = new Dictionary <string, string>(); Record["jid"] = XML.Attribute((XmlElement)N2, "jid"); foreach (XmlNode N3 in N2.ChildNodes) { XmlElement E = N3 as XmlElement; if (E != null) { Record[E.LocalName] = E.InnerText; } } Records.Add(Record); } } } } } this.CallResponseMethod(Callback, State, Records, e); }
private void FormSearchResult(object Sender, IqResultEventArgs e) { object[] P = (object[])e.State; SearchResultEventHandler Callback = (SearchResultEventHandler)P[0]; object State = P[1]; List <Dictionary <string, string> > Records = new List <Dictionary <string, string> >(); if (e.Ok) { foreach (XmlNode N in e.Response.ChildNodes) { if (N.LocalName == "query") { foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "x") { DataForm Form = new DataForm(this.client, (XmlElement)N2, null, null, e.From, e.To); Dictionary <string, string> Record = new Dictionary <string, string>(); foreach (Field[] FormRecord in Form.Records) { foreach (Field FormField in FormRecord) { Record[FormField.Var] = FormField.ValueString; } } Records.Add(Record); } } } } } this.CallResponseMethod(Callback, State, Records, e); }
private void GetTokenChallengeResponse(object Sender, IqResultEventArgs e) { object[] P = (object[])e.State; #if WINDOWS_UWP Certificate Certificate = (Certificate)P[0]; #else X509Certificate2 Certificate = (X509Certificate2)P[0]; #endif TokenCallback Callback = (TokenCallback)P[1]; object State = P[2]; XmlElement E = e.FirstElement; string Token; if (e.Ok && E != null && E.LocalName == "getTokenResponse" && E.NamespaceURI == NamespaceProvisioningToken) { Token = XML.Attribute(E, "token"); lock (this.certificates) { this.certificates[Token] = new CertificateUse(Token, Certificate); } } else { Token = null; } TokenEventArgs e2 = new TokenEventArgs(e, State, Token); try { Callback(this, e2); } catch (Exception ex) { Log.Critical(ex); } }
internal void Opened(IqResultEventArgs e) { this.opened = true; OpenStreamEventHandler h = this.OnOpened; if (h != null) { try { OpenStreamEventArgs e2 = new OpenStreamEventArgs(e, this); h(this, e2); } catch (Exception ex) { Log.Critical(ex); } } if (!this.isWriting && this.tempFile.Length - this.pos >= this.blockSize) { this.WriteBlockLocked(); } }
/// <summary> /// Event arguments for block-list response callbacks. /// </summary> /// <param name="e">IQ response.</param> /// <param name="JIDs">Blocked JIDs.</param> /// <param name="State">State object to pass on to callback method.</param> public BlockListEventArgs(IqResultEventArgs e, string[] JIDs, object State) : base(e) { this.jids = JIDs; this.State = State; }
internal JidEventArgs(IqResultEventArgs e, object State, string JID) : base(e) { this.State = State; this.jid = JID; }
internal NodesEventArgs(IqResultEventArgs e, object State, string JID, ThingReference[] Nodes) : base(e, State, JID) { this.nodes = Nodes; }
/// <summary> /// Event arguments for interoperability interface requests. /// </summary> public InteroperabilityClientEventArgs(string[] Interfaces, IqResultEventArgs e) : base(e) { this.interfaces = Interfaces; }
private void SetResultCallback(object Sender, IqResultEventArgs e) { object[] P = (object[])e.State; SetResultCallback Callback = (SetResultCallback)P[0]; if (Callback == null) { return; } object State = P[1]; XmlElement E = e.FirstElement; XmlElement E2; SetResultEventArgs e2; if (e.Ok) { if (E != null && E.LocalName == "resp" && E.NamespaceURI == NamespaceControl) { List <ThingReference> Nodes = null; List <string> ParameterNames = null; foreach (XmlNode N in E.ChildNodes) { E2 = N as XmlElement; if (E2 == null) { continue; } switch (N.LocalName) { case "nd": if (Nodes == null) { Nodes = new List <ThingReference>(); } Nodes.Add(new ThingReference( XML.Attribute(E2, "id"), XML.Attribute(E2, "src"), XML.Attribute(E2, "pt"))); break; case "p": if (ParameterNames == null) { ParameterNames = new List <string>(); } ParameterNames.Add(XML.Attribute(E2, "n")); break; } } e2 = new SetResultEventArgs(e, true, Nodes?.ToArray(), ParameterNames?.ToArray(), State); } else { e2 = new SetResultEventArgs(e, true, null, null, State); } } else { e2 = new SetResultEventArgs(e, false, null, null, State); } try { Callback(this, e2); } catch (Exception ex) { Log.Critical(ex); } }
internal CommandsEventArgs(NodeCommand[] Result, IqResultEventArgs s) : base(s) { this.result = Result; }
internal DataSourcesEventArgs(DataSourceReference[] DataSources, IqResultEventArgs Response) : base(Response) { this.dataSources = DataSources; }