Exemple #1
0
        void objXmpp_OnIq(object sender, IQ iq)
        {
            if (iq != null)
            {
                // No Iq with query
                if (iq.HasTag(typeof(agsXMPP.protocol.extensions.si.SI)))
                {
                    if (iq.Type == IqType.set)
                    {
                        agsXMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(agsXMPP.protocol.extensions.si.SI)) as agsXMPP.protocol.extensions.si.SI;

                        agsXMPP.protocol.extensions.filetransfer.File file = si.File;
                        if (file != null)
                        {
                            // somebody wants to send a file to us
                            //frmFileTransfer frmFile = new frmFileTransfer(XmppCon, iq);
                            //frmFile.Show();
                            Console.WriteLine(file.Description);
                            FileTransfer FT = new FileTransfer(objXmpp, iq);
                        }
                    }
                }
                else
                {
                    Element query = iq.Query;

                    if (query != null)
                    {
                        if (query.GetType() == typeof(agsXMPP.protocol.iq.version.Version))
                        {
                            // its a version IQ VersionIQ
                            agsXMPP.protocol.iq.version.Version version = query as agsXMPP.protocol.iq.version.Version;
                            if (iq.Type == IqType.get)
                            {
                                // Somebody wants to know our client version, so send it back
                                iq.SwitchDirection();
                                iq.Type = IqType.result;

                                version.Name = "MiniClient";
                                version.Ver  = "0.5";
                                version.Os   = Environment.OSVersion.ToString();

                                objXmpp.Send(iq);
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
 private void _connection_OnIq(object sender, IQ iq)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new IqHandler(_connection_OnIq), new[] { sender, iq });
         return;
     }
     if (iq != null)
     {
         if (iq.HasTag(typeof(SI)))
         {
             if (iq.Type == IqType.set)
             {
                 SI si = iq.SelectSingleElement(typeof(SI)) as SI;
                 if (si != null)
                 {
                     XMPPFile file = si.File;
                     if (file != null)
                     {
                         //todo:文件传输
                     }
                 }
             }
         }
         else
         {
             Element query = iq.Query;
             if (query != null)
             {
                 if (query.GetType() == typeof(XMPPVersion))
                 {
                     XMPPVersion version = query as XMPPVersion;
                     if (iq.Type == IqType.get && version != null)
                     {
                         iq.SwitchDirection();
                         iq.Type      = IqType.result;
                         version.Name = "XMPP";
                         version.Ver  = "1.0";
                         version.Os   = Environment.OSVersion.ToString();
                         _connection.Send(iq);
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
        private void OnIq(object sender, agsXMPP.protocol.client.IQ iq)
        {
            if (iq != null)
            {
                if (iq.Error != null)
                {
                    OnIqError(iq);
                }

                // No Iq with Query
                if (iq.HasTag(typeof(agsXMPP.protocol.extensions.si.SI)))
                {
                    if (iq.Type == IqType.set)
                    {
                        agsXMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(agsXMPP.protocol.extensions.si.SI)) as agsXMPP.protocol.extensions.si.SI;

                        agsXMPP.protocol.extensions.filetransfer.File file = si.File;
                        if (file != null)
                        {
                            // somebody wants to send a file to us
                            Console.WriteLine(file.Size.ToString());
                            Console.WriteLine(file.Name);
                        }
                    }
                }
                else
                {
                    Element query = iq.Query;

                    if (query != null)
                    {
                        if (query.GetType() == typeof(agsXMPP.protocol.iq.version.Version))
                        {
                            OnIqVersion(iq, query);
                        }
                        else if (query.GetType() == typeof(agsXMPP.protocol.iq.register.Register))
                        {
                            OnIqRegister(iq, query);
                        }
                    }
                }
            }
        }
Exemple #4
0
        public void SwitchIQ(agsXMPP.protocol.client.IQ iq)
        {
            if (iq == null)
            {
                return;
            }


            // No Iq with query
            if (iq.HasTag(typeof(SI)))
            {
                if (iq.Type == IqType.set)
                {
                    SI si = iq.SelectSingleElement(typeof(SI)) as SI;

                    agsXMPP.protocol.extensions.filetransfer.File file = si.File;
                    if (file != null)
                    {
                        // somebody wants to send a file to us
                        AddLog(string.Concat("Alguien esta enviando un archivo Size:", file.Size.ToString(), " nombre: ", file.Name));

                        //frmFileTransfer frmFile = new frmFileTransfer(XmppCon, iq);
                        //frmFile.Show();
                    }
                }
            }

            if (iq.Type == IqType.error)
            {
                //if (iq.Error.Code == agsXMPP.protocol.client.ErrorCode.NotFound)
                //{
                string msg = string.Concat(iq.From, " ", iq.Error.Condition);
                AddLog(msg);
                //}
            }

            if (iq.Type == IqType.get)
            {
                if (iq.Query != null)
                {
                    if (iq.Query is DiscoInfo)
                    {
                        //iq.SwitchDirection();
                        //iq.Type = IqType.result;
                        //DiscoInfo di = getDiscoInfo();
                        //iq.Query = di;
                        //XmppCon.Send(iq);
                    }
                    else if (iq.Query is DiscoItems)
                    {
                        //iq.SwitchDirection();
                        //iq.Type = IqType.error;
                        //iq.Error = new Error(ErrorType.cancel, ErrorCondition.FeatureNotImplemented);
                        //XmppCon.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.version.Version)
                    {
                        //Suichea  from y to
                        iq.SwitchDirection();
                        iq.Type = IqType.result;//indica retorno o respuesta

                        agsXMPP.protocol.iq.version.Version version = iq.Query as agsXMPP.protocol.iq.version.Version;
                        version.Name = Assembly.GetExecutingAssembly().GetName().Name;
                        version.Ver  = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                        version.Os   = Environment.OSVersion.ToString();
                        Util.XmppServices.XmppCon.Send(iq);
                        //frmMain.AddLog("IQ: tipo vesion");
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.last.Last)
                    {
                        //iq.SwitchDirection();
                        //iq.Type = IqType.result;
                        //agsXMPP.protocol.iq.last.Last last = iq.Query as agsXMPP.protocol.iq.last.Last;
                        //last.Seconds = new TimeSpan(Jabber._presence.getLastActivityTicks()).Seconds;
                        //Jabber.xmpp.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.time.Time)
                    {
                        iq.SwitchDirection();
                        iq.Type = IqType.result;
                        agsXMPP.protocol.iq.time.Time time = iq.Query as agsXMPP.protocol.iq.time.Time;
                        time.Display = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString();
                        time.Tz      = TimeZone.CurrentTimeZone.StandardName;
                        time.Utc     = agsXMPP.util.Time.ISO_8601Date(DateTime.Now);
                        Util.XmppServices.XmppCon.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.extensions.ping.Ping)
                    {
                        iq.SwitchDirection();
                        iq.Type = IqType.result;
                        agsXMPP.protocol.extensions.ping.Ping ping = iq.Query as agsXMPP.protocol.extensions.ping.Ping;
                        Util.XmppServices.XmppCon.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.avatar.Avatar)
                    {
                        iq.SwitchDirection();
                        iq.Type = IqType.result;
                        agsXMPP.protocol.iq.avatar.Avatar avatar = iq.Query as agsXMPP.protocol.iq.avatar.Avatar;
                        avatar.Data = null;
                        if (Jabber._identity.photo != null && Jabber._identity.photoFormat != null)
                        {
                            MemoryStream ms = new MemoryStream();
                            Jabber._identity.photo.Save(ms, Jabber._identity.photoFormat);
                            avatar.Data     = ms.ToArray();
                            avatar.MimeType = "image/" + Jabber._identity.photoFormat.ToString();
                            ms.Close();
                            ms.Dispose();
                        }
                        Jabber.xmpp.Send(iq);
                    }
                    else if (iq.Query is agsXMPP.protocol.iq.vcard.Vcard)
                    {
                        iq.SwitchDirection();
                        iq.Type  = IqType.result;
                        iq.Query = Jabber._identity.toVcard();
                        Jabber.xmpp.Send(iq);
                    }
                }
            }
        }