Exemplo n.º 1
0
 private void xmppOnIq(object sender, IQ iq)
 {
     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;
                 Jabber.xmpp.Send(iq);
             }
             else if (iq.Query is DiscoItems)
             {
                 iq.SwitchDirection();
                 iq.Type  = IqType.error;
                 iq.Error = new Error(ErrorType.cancel, ErrorCondition.FeatureNotImplemented);
                 Jabber.xmpp.Send(iq);
             }
             else if (iq.Query is agsXMPP.protocol.iq.version.Version)
             {
                 iq.SwitchDirection();
                 iq.Type = IqType.result;
                 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();
                 Jabber.xmpp.Send(iq);
             }
             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);
                 Jabber.xmpp.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;
                 Jabber.xmpp.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);
             }
         }
     }
 }
Exemplo n.º 2
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);
                    }
                }
            }
        }