private void XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq) { if (InvokeRequired) { // Windows Forms are not Thread Safe, we need to invoke this :( // We're not in the UI thread, so we need to call BeginInvoke BeginInvoke(new IqHandler(XmppCon_OnIq), new object[] { sender, iq }); return; } 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 Console.WriteLine(file.Size.ToString()); Console.WriteLine(file.Name); frmFileTransfer frmFile = new frmFileTransfer(XmppCon, iq); frmFile.Show(); } } } 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(); XmppCon.Send(iq); } } } } } }
private void XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq) { if (InvokeRequired) { // Windows Forms are not Thread Safe, we need to invoke this :( // We're not in the UI thread, so we need to call BeginInvoke BeginInvoke(new IqHandler(XmppCon_OnIq), new object[]{sender, iq}); return; } 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(); XmppCon.Send(iq); } } } }
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); } } } }