Пример #1
0
 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;
 }
Пример #2
0
        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
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
 private void CallCallback(IqResultEventHandler Callback, object State, IqResultEventArgs e)
 {
     if (Callback != null)
     {
         try
         {
             Callback(this, e);
         }
         catch (Exception ex)
         {
             Log.Critical(ex);
         }
     }
 }
Пример #5
0
 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);
             }
         }
     }
 }
Пример #6
0
        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();
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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;
        }
Пример #9
0
        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);
                }
            }
        }
Пример #10
0
            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);
            }
Пример #11
0
 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);
     }
 }
Пример #12
0
        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.");
        }
Пример #13
0
        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);
                }
            }
        }
Пример #14
0
        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);
            }
        }
Пример #15
0
        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();
                    }
                }
            }
        }
Пример #16
0
        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);
                }
            }
        }
Пример #17
0
        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);
                }
            }
        }
Пример #18
0
        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);
                }
            }
        }
Пример #19
0
        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);
                }
            }
        }
Пример #20
0
        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);
        }
Пример #21
0
        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);
        }
Пример #22
0
        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);
            }
        }
Пример #23
0
        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();
            }
        }
Пример #24
0
 /// <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;
 }
Пример #25
0
 internal JidEventArgs(IqResultEventArgs e, object State, string JID)
     : base(e)
 {
     this.State = State;
     this.jid   = JID;
 }
Пример #26
0
 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;
 }
Пример #28
0
        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);
            }
        }
Пример #29
0
 internal CommandsEventArgs(NodeCommand[] Result, IqResultEventArgs s)
     : base(s)
 {
     this.result = Result;
 }
Пример #30
0
 internal DataSourcesEventArgs(DataSourceReference[] DataSources, IqResultEventArgs Response)
     : base(Response)
 {
     this.dataSources = DataSources;
 }