示例#1
0
 private void SiIqResult(object sender, IQ iq, object data)
 {
     // Parse the result of the form
     if (iq.Type == IqType.result)
     {
         // <iq xmlns="jabber:client" id="aab4a" to="[email protected]/Psi" type="result"><si
         // xmlns="http://jabber.org/protocol/si" id="s5b_405645b6f2b7c681"><feature
         // xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="submit"><field
         // var="stream-
         // method"><value>http://jabber.org/protocol/bytestreams</value></field></x></feature></si></iq>
         SI si = iq.SelectSingleElement(typeof(SI)) as SI;
         if (si != null)
         {
             FeatureNeg fNeg = si.FeatureNeg;
             if (SelectedByteStream(fNeg))
             {
                 SendStreamHosts();
             }
         }
     }
     else if (iq.Type == IqType.error)
     {
         agsXMPP.protocol.client.Error err = iq.Error;
         if (err != null)
         {
             switch ((int)err.Code)
             {
             case 403:
                 Console.WriteLine("The file was rejected by the remote user", "Error");
                 break;
             }
         }
     }
 }
示例#2
0
        private void SiIqResult(object sender, IQ iq, object data)
        {
            // Parse the result of the form
            if (iq.Type == IqType.result)
            {
                // <iq xmlns="jabber:client" id="aab4a" to="[email protected]/Psi" type="result"><si
                // xmlns="http://jabber.org/protocol/si" id="s5b_405645b6f2b7c681"><feature
                // xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="submit"><field
                // var="stream-
                // method"><value>http://jabber.org/protocol/bytestreams</value></field></x></feature></si></iq>
                //if (iq.Query != null && iq.Query.Namespace == "http://jabber.org/protocol/disco#items")
                //{
                //    Proxy = true;
                //}

                SI si = iq.SelectSingleElement(typeof(SI)) as SI;
                if (si != null)
                {
                    FeatureNeg fNeg = si.FeatureNeg;

                    if (SelectedByteStream(fNeg))
                    {
                        //添加申请传输代理服务器
                        if (!Proxy)
                        {
                            IQ iq1 = new IQ();
                            iq1.Id = iq.Id;
                            //iq1.Namespace = "jabber:client";
                            iq1.Type = IqType.get;
                            //iq1.From = m_XmppCon.MyJID;
                            //iq1.To = m_To;
                            iq1.InnerXml = "<query xmlns=\"http://jabber.org/protocol/disco#items\" sid=\"" + m_Sid + "\" />";
                            //iq1.AddChild(new agsXMPP.Xml.Dom.Node(""));
                            //iq1.Query.Namespace = "http://jabber.org/protocol/disco#items";
                            // m_XmppCon.Send(iq1);
                            m_XmppCon.IqGrabber.SendIq2(iq1, new IqCB(SiIqResult1), null);
                        }
                    }
                }

                //if (Proxy)
                //{
                //    SendStreamHosts();
                //}
            }
            else if (iq.Type == IqType.error)
            {
                agsXMPP.protocol.client.Error err = iq.Error;
                if (err != null)
                {
                    switch ((int)err.Code)
                    {
                    case 403:
                        MessageBox.Show("The file was rejected by the remote user", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        break;
                    }
                }
            }
        }
示例#3
0
        private bool IsForm(FeatureNeg fn)
        {
            bool bRetVal = false;

            if ((fn != null) && (fn.Data != null))
            {
                if (fn.Data.Type == XDataFormType.form)
                {
                    bRetVal = true;
                }
            }
            return(bRetVal);
        }
示例#4
0
 private bool SelectedByteStream(FeatureNeg fn)
 {
     if (fn != null)
     {
         Data data = fn.Data;
         if (data != null)
         {
             foreach (Field field in data.GetFields())
             {
                 if (field != null && field.Var == "stream-method")
                 {
                     if (field.GetValue() == agsXMPP.Uri.BYTESTREAMS)
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
示例#5
0
        public FileTransfer(XmppClientConnection XmppCon, Jid m_To)
        {
            m_XmppCon = XmppCon;
            SIIq iq = new SIIq();

            iq.To   = m_To;
            iq.Type = IqType.set;

            m_lFileLength = new FileInfo(@"c:\\ping.txt").Length;

            agsXMPP.protocol.extensions.filetransfer.File file;
            file = new agsXMPP.protocol.extensions.filetransfer.File(Path.GetFileName(@"c:\\ping.txt"), m_lFileLength);
            //if (m_DescriptionChanged)
            //    file.Description = txtDescription.Text;
            file.Range = new Range();


            FeatureNeg fNeg = new FeatureNeg();

            Data  data = new Data(XDataFormType.form);
            Field f    = new Field(FieldType.List_Single);

            f.Var = "stream-method";
            f.AddOption().SetValue(agsXMPP.Uri.BYTESTREAMS);
            data.AddField(f);

            fNeg.Data = data;

            iq.SI.File       = file;
            iq.SI.FeatureNeg = fNeg;
            iq.SI.Profile    = agsXMPP.Uri.SI_FILE_TRANSFER;

            m_Sid    = Guid.NewGuid().ToString();
            iq.SI.Id = m_Sid;

            m_XmppCon.IqGrabber.SendIq(iq, new IqCB(SiIqResult), null);
        }
示例#6
0
        private void SendSiIq()
        {
            /*
             * Recv:
             * <iq xmlns="jabber:client" from="[email protected]/Psi" to="[email protected]/SharpIM"
             * type="set" id="aab4a"> <si xmlns="http://jabber.org/protocol/si"
             * profile="http://jabber.org/protocol/si/profile/file-transfer" id="s5b_405645b6f2b7c681"> <file
             * xmlns="http://jabber.org/protocol/si/profile/file-transfer" size="719" name="Kunden.dat"> <range />
             * </file> <feature xmlns="http://jabber.org/protocol/feature-neg"> <x xmlns="jabber:x:data" type="form">
             * <field type="list-single" var="stream-method"> <option>
             * <value>http://jabber.org/protocol/bytestreams</value> </option> </field> </x> </feature> </si> </iq>
             *
             * Send: <iq xmlns="jabber:client" id="agsXMPP_5" to="[email protected]/Psi" type="set">
             * <si xmlns="http://jabber.org/protocol/si" id="af5a2e8d-58d4-4038-8732-7fb348ff767f">
             * <file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="ALEX1.JPG" size="22177"><range /></file>
             * <feature xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="form">
             * <field type="list-single" var="stream-method"><option>http://jabber.org/protocol/bytestreams</option></field></x></feature></si></iq>
             *
             *
             * Send:
             * <iq xmlns="jabber:client" id="aab4a" to="[email protected]/Psi" type="result"><si
             * xmlns="http://jabber.org/protocol/si" id="s5b_405645b6f2b7c681"><feature
             * xmlns="http://jabber.org/protocol/feature-neg"><x xmlns="jabber:x:data" type="submit"><field
             * var="stream-
             * method"><value>http://jabber.org/protocol/bytestreams</value></field></x></feature></si></iq>
             *
             *
             * Recv:
             * <iq xmlns="jabber:client" from="[email protected]/Psi" to="[email protected]/SharpIM"
             * type="set" id="aab6a"> <query xmlns="http://jabber.org/protocol/bytestreams" sid="s5b_405645b6f2b7c681"
             * mode="tcp"> <streamhost port="8010" jid="[email protected]/Psi" host="192.168.74.142" /> <streamhost
             * port="7777" jid="proxy.ag-software.de" host="82.165.34.23"> <proxy
             * xmlns="http://affinix.com/jabber/stream" /> </streamhost> <fast xmlns="http://affinix.com/jabber/stream"
             * /> </query> </iq>
             *
             *
             * Send:
             * <iq xmlns="jabber:client" type="result" to="[email protected]/Psi" id="aab6a"><query
             * xmlns="http://jabber.org/protocol/bytestreams"><streamhost-used jid="[email protected]/Psi"
             * /></query></iq>
             */

            SIIq iq = new SIIq();

            iq.To   = m_To;
            iq.Type = IqType.set;

            m_lFileLength = new FileInfo(m_FileName).Length;

            agsXMPP.protocol.extensions.filetransfer.File file;
            file = new agsXMPP.protocol.extensions.filetransfer.File(
                Path.GetFileName(m_FileName), m_lFileLength);
            if (m_DescriptionChanged)
            {
                file.Description = txtDescription.Text;
            }
            file.Range = new Range();


            FeatureNeg fNeg = new FeatureNeg();

            Data  data = new Data(XDataFormType.form);
            Field f    = new Field(FieldType.List_Single);

            f.Var = "stream-method";
            f.AddOption().SetValue(agsXMPP.Uri.BYTESTREAMS);
            data.AddField(f);

            fNeg.Data = data;

            iq.SI.File       = file;
            iq.SI.FeatureNeg = fNeg;
            iq.SI.Profile    = agsXMPP.Uri.SI_FILE_TRANSFER;

            m_Sid    = Guid.NewGuid().ToString();
            iq.SI.Id = m_Sid;

            m_XmppCon.IqGrabber.SendIq(iq, new IqCB(SiIqResult), null);
        }