Exemplo n.º 1
0
        //  on Successfull Login
        
        //  When someone checks our client details through requesting iq
        private void dbcon_oniq(object sender, IQ iq)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new IqHandler(dbcon_oniq), new object[] { sender, iq });
                return;
            }

            if (iq.Query != null)
            {
                if (iq.Query.GetType() == typeof(agsXMPP.protocol.iq.version.Version))
                {
                    agsXMPP.protocol.iq.version.Version vers = (agsXMPP.protocol.iq.version.Version)iq.Query;
                    if (iq.Type == agsXMPP.protocol.client.IqType.get)
                    {
                        iq.SwitchDirection();
                        iq.Type = agsXMPP.protocol.client.IqType.result;
                        vers.Name = "Nimbuzz Profile Changer Coded by db~@NC";
                        vers.Ver = "1.0.1";
                        vers.Os = "Coded By db~@NC\nFor More Visit: http://dbh4ck.blogspot.in";
                        ((XmppClientConnection)sender).Send(iq);
                    }
                }
            }

        }
        private void OnRequestResult(object sender, IQ iq, object data)
        {
            if (iq.Error != null)
            {
                EventError eventError = new EventError("Request for bookmarks on server failed", iq.Error);
                Events.Instance.OnEvent(this, eventError);
            }
            else if (iq.Type == IqType.result)
            {
                Private privateData = iq.Query as Private;

                if (privateData != null && privateData.Storage != null)
                {
                    Conference[] conferences = privateData.Storage.GetConferences();

                    lock (MucMarks.Instance._syncObject)
                    {
                        MucMarks.Instance.Clear();

                        foreach (Conference conference in conferences)
                        {
                            MucMarks.Instance.AddBookmark(conference);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public IQEventArgs(IQ iq)
 {
     if (iq == null) {
         throw new ArgumentNullException("iq");
     }
     IQ = iq;
 }
Exemplo n.º 4
0
        private void con_OnIq(object sender, IQ iq)
        {
            if (iq.Query != null)
            {
                if (iq.Query is DiscoInfo && iq.Type == IqType.get)
                {
                    /*
                    <iq type='get'
                        from='[email protected]/orchard'
                        to='plays.shakespeare.lit'
                        id='info1'>
                      <query xmlns='http://jabber.org/protocol/disco#info'/>
                    </iq>
                    */
                    iq.SwitchDirection();
                    iq.Type = IqType.result;

                    DiscoInfo di = iq.Query as DiscoInfo;

                    if (ClientName != null)
                        di.AddIdentity(new DiscoIdentity(ClientCategory.ToString(), this.ClientName, "client"));

                    foreach (string feature in ClientFeatures)
                    {
                        di.AddFeature(new DiscoFeature(feature));
                    }

                    xmppCon.Send(iq);

                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// An IQ Element is received. Now check if its one we are looking for and
        /// raise the event in this case.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnIq(object sender, agsXMPP.protocol.client.IQ iq)
        {
            if (iq == null)
            {
                return;
            }

            // the tracker handles on iq responses, which are either result or error
            if (iq.Type != IqType.error && iq.Type != IqType.result)
            {
                return;
            }

            string id = iq.Id;

            if (id == null)
            {
                return;
            }

            TrackerData td;

            lock (m_grabbing)
            {
                td = (TrackerData)m_grabbing[id];

                if (td == null)
                {
                    return;
                }
                m_grabbing.Remove(id);
            }

            td.cb(this, iq, td.data);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sends an Iq synchronous and return the response or null on timeout
        /// </summary>
        /// <param name="iq">The IQ to send</param>
        /// <param name="timeout"></param>
        /// <returns>The response IQ or null on timeout</returns>
        public IQ SendIq(agsXMPP.protocol.client.IQ iq, int timeout)
        {
            synchronousResponse = null;
            AutoResetEvent are = new AutoResetEvent(false);

            SendIq(iq,
                   delegate(object sender, IQEventArgs e)
            {
                e.Handled = true;
                are.Set();
            }
                   );

            if (!are.WaitOne(timeout, true))
            {
                // Timed out
                lock (m_grabbing)
                {
                    if (m_grabbing.ContainsKey(iq.Id))
                    {
                        m_grabbing.Remove(iq.Id);
                    }
                }
                return(null);
            }

            return(synchronousResponse);
        }
Exemplo n.º 7
0
        public FileTransfer(XmppClientConnection xmppCon, IQ iq, IContact from)
            : base(from)
        {
            _siIq = iq;
            _si = iq.SelectSingleElement(typeof (SI)) as SI;

            if (_si != null)
            {
                // get SID for file transfer
                _sid = _si.Id;
                _file = _si.File;

                Contact = from;

                if (_file != null)
                {
                    _fileLength = _file.Size;

                    FileDescription = _file.Description;
                    FileName = _file.Name;
                }

                _xmppConnection = xmppCon;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Send message to HarmonyHub to request Configuration.
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetConfig()
        {
            EnsureConnection();

            var iqToSend = new IQ { Type = IqType.get, Namespace = "", From = "1", To = "guest" };
            iqToSend.AddChild(HarmonyDocuments.ConfigDocument());
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            var iq = iqGrabber.SendIq(iqToSend, 10000);

            if (iq != null)
            {
                var match = IdentityRegex.Match(iq.InnerXml);
                if (match.Success)
                {
                    RawConfig = match.Groups[1].ToString();
                    Config = null;
                    try
                    {
                        Config = new JavaScriptSerializer().Deserialize<HarmonyConfigResult>(RawConfig);
                    }
                    catch { }
                }
            }
        }
Exemplo n.º 9
0
		private void VcardResult(object sender, IQ iq, object data)
		{
			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 IqCB(VcardResult), new object[] { sender, iq, data });
				return;
			}

			if (iq.Type == IqType.result)
			{
				Vcard vcard = iq.Vcard;
				if (vcard != null)
				{
					txtFullname.Text = vcard.Fullname;
					txtNickname.Text = vcard.Nickname;
					txtBirthday.Text = vcard.Birthday.ToString();
					txtDescription.Text = vcard.Description;
                    Photo photo = vcard.Photo;
                    if (photo != null)
                        picPhoto.Image = vcard.Photo.Image;						
				}
			}
		}
Exemplo n.º 10
0
        public frmFileTransfer(XmppClientConnection XmppCon, IQ iq)
        {
            InitializeComponent();
            cmdSend.Enabled = false;
            this.Text = "Receive File from " + iq.From.ToString();

            siIq = iq;
            si = iq.SelectSingleElement(typeof(agsXMPP.protocol.extensions.si.SI)) as agsXMPP.protocol.extensions.si.SI;
            // get SID for file transfer
            m_Sid = si.Id;
            m_From = iq.From;

            file = si.File;

            if (file != null)
            {
                m_lFileLength = file.Size;

                this.lblDescription.Text    = file.Description;
                this.lblFileName.Text       = file.Name;
                this.lblFileSize.Text       = HRSize(m_lFileLength);
                this.txtDescription.Visible = false;
            }

            m_XmppCon = XmppCon;

            this.progress.Maximum = 100;
            //this.Text += iq.From.ToString();

            //this.tbFileSize.Text = FileTransferUtils.ConvertToByteString(m_lFileLength);

            XmppCon.OnIq += new IqHandler(XmppCon_OnIq);
        }
Exemplo n.º 11
0
        /// <summary>
        /// An IQ Element is received. Now check if its one we are looking for and
        /// raise the event in this case.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnIq(object sender, agsXMPP.protocol.client.IQ iq)
        {
            if (iq == null)
            {
                return;
            }

            string id = iq.Id;

            if (id == null)
            {
                return;
            }

            TrackerData td;

            lock (m_grabbing)
            {
                td = (TrackerData)m_grabbing[id];

                if (td == null)
                {
                    return;
                }
                m_grabbing.Remove(id);
            }

            td.cb(this, iq, td.data);
        }
Exemplo n.º 12
0
        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);
                    }
                }
            }
        }
Exemplo n.º 13
0
        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 StreamHandler(XmppCon_OnIq), new object[] { sender, e });
            //    return;
            //}

            // <iq xmlns="jabber:client" from="[email protected]/Psi" to="[email protected]/SharpIM" type="set" id="aac9a">
            //  <query xmlns="http://jabber.org/protocol/bytestreams" sid="s5b_8596bde0de321957" 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>


            if (iq.Query != null && iq.Query.GetType() == typeof(agsXMPP.protocol.extensions.bytestreams.ByteStream))
            {
                agsXMPP.protocol.extensions.bytestreams.ByteStream bs = iq.Query as agsXMPP.protocol.extensions.bytestreams.ByteStream;
                // check is this is for the correct file
                if (bs.Sid == m_Sid)
                {
                    Thread t = new Thread(
                        delegate() { HandleStreamHost(bs, iq); }
                        );
                    t.Name = "LoopStreamHosts";
                    t.Start();
                }
            }
        }
Exemplo n.º 14
0
        public void CheckServerFeatures()
        {
            var iq = new agsXMPP.protocol.client.IQ(agsXMPP.protocol.client.IqType.get, conn.MyJID, new Jid(conn.MyJID.Server));

            iq.AddChild(new agsXMPP.protocol.iq.disco.DiscoInfo()); iq.GenerateId();
            conn.IqGrabber.SendIq(iq, delegate(object a, agsXMPP.protocol.client.IQ b, object c) {
                serverFeatures.Clear();
                foreach (Element child in b.SelectSingleElement("query").SelectElements("feature"))
                {
                    serverFeatures.Add(child.GetAttribute("var"));
                }
                SendCarbonsEnableIq();
                if (OnServerFeaturesUpdated != null)
                {
                    OnServerFeaturesUpdated(this, EventArgs.Empty);
                }
            });
            var iq2 = new agsXMPP.protocol.client.IQ(agsXMPP.protocol.client.IqType.get, conn.MyJID, new Jid(conn.MyJID.Server));

            iq2.AddChild(new agsXMPP.protocol.iq.disco.DiscoItems()); iq2.GenerateId();
            conn.IqGrabber.SendIq(iq2, delegate(object a, agsXMPP.protocol.client.IQ b, object c) {
                var queryResult = b.SelectSingleElement("query");
                Console.WriteLine("server items: " + queryResult);
            });
        }
Exemplo n.º 15
0
 private void OnStoreResult(object sender, IQ iq, object data)
 {
     if (iq.Error != null)
     {
         EventError eventError = new EventError("Saving for bookmarks on server failed", iq.Error);
         Events.Instance.OnEvent(this, eventError);
     }
 }
Exemplo n.º 16
0
 private void OnIqError(agsXMPP.protocol.client.IQ iq)
 {
     ts.TraceInformation("OnIqError {0} error type {1}, code: {2}",
                         this.Jid.ToString(), iq.Error.Type, iq.Error.Code);
     if (IqErrorHandler != null)
     {
         IqErrorHandler(this, this.Jid, iq.Error);
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// XEP-0280, Message Carbons
 /// </summary>
 private void SendCarbonsEnableIq()
 {
     if (serverFeatures.Contains(JabberService.URN_CARBONS))
     {
         var iq = new agsXMPP.protocol.client.IQ(agsXMPP.protocol.client.IqType.set);
         iq.From = conn.MyJID; iq.GenerateId();
         iq.AddChild(new agsXMPP.Xml.Dom.Element("enable", "", JabberService.URN_CARBONS));
         conn.Send(iq);
     }
 }
Exemplo n.º 18
0
        private void ProcessDiscoInfo(IQ iq)
        {            
            IQ diiq = new IQ();
            diiq.To = iq.From;
            diiq.Id = iq.Id;
            diiq.Type = IqType.result;

            diiq.Query = xmppConnection.DiscoInfo;

            xmppConnection.Send(diiq);        
        }
Exemplo n.º 19
0
        public static IQ ConstructConfigurationRequest()
        {
            Element query = new Element(Constants.XmppQueryActionElement, string.Empty, Constants.LogitechConnectNamespace);
            query.Attributes.Add(Constants.XmppMimeAttribute, Constants.ConfigurationRequestPath);

            IQ message = new IQ(IqType.get);
            message.Id = agsXMPP.Id.GetNextId();
            message.Query = query;

            return message;
        }
Exemplo n.º 20
0
        private void DiscoverItemsDone(object sender, IQ iq, object data)
        {
            var discoItems = iq.Query as DiscoItems;
            if(discoItems == null)
                return;

            var items = discoItems.GetDiscoItems();
            foreach(var item in items)
                search.Enqueue(item.Jid);

            Search();
        }
Exemplo n.º 21
0
        public static IQ ConstructSessionInfoRequest(string authenticationToken)
        {
            string token = string.Format(Constants.SessionTokenRequestFormat, authenticationToken, Constants.SessionName, Constants.SessionOs, Constants.SessionDevice);

            Element query = new Element(Constants.XmppQueryActionElement, token, Constants.LogitechConnectNamespace);
            query.Attributes.Add(Constants.XmppMimeAttribute, Constants.SessionRequestPath);

            IQ message = new IQ(IqType.get);
            message.Id = agsXMPP.Id.GetNextId();
            message.Query = query;

            return message;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Send message to HarmonyHub with UserAuthToken, wait for SessionToken
        /// </summary>
        /// <param name="userAuthToken"></param>
        /// <returns></returns>
        public string SwapAuthToken(string userAuthToken)
        {
            var iqToSend = new IQ { Type = IqType.get, Namespace = "", From = "1", To = "guest" };
            iqToSend.AddChild(HarmonyDocuments.LogitechPairDocument(userAuthToken));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            iqGrabber.SendIq(iqToSend, 10);

            WaitForData(5);

            return _sessionToken;
        }
 private void OnIq(object sender, IQ iq)
 {
     if (iq.Type == IqType.get)
     {
         var ping = iq.SelectSingleElement("ping", "urn:xmpp:ping");
         if (ping != null)
         {
             var pong = new agsXMPP.protocol.client.IQ(agsXMPP.protocol.client.IqType.result, iq.To, iq.From);
             pong.Id = iq.Id;
             _xmpp.Send(pong);
         }
     }
 }
Exemplo n.º 24
0
 private void XmppCon_OnIq(object sender, agsXMPP.protocol.client.IQ iq)
 {
     if (iq.Query != null && iq.Query.GetType() == typeof(agsXMPP.protocol.extensions.bytestreams.ByteStream))
     {
         agsXMPP.protocol.extensions.bytestreams.ByteStream bs = iq.Query as agsXMPP.protocol.extensions.bytestreams.ByteStream;
         // check is this is for the correct file
         if (bs.Sid == m_Sid)
         {
             Thread t = new Thread(
                 delegate() { HandleStreamHost(bs, iq); }
                 );
             t.Name = "LoopStreamHosts";
             t.Start();
         }
     }
 }
        public EventInfoFileTransfer(IQ iq)
            : base(string.Empty, EventSeverity.Info)
        {
            _iq = iq;

            agsXMPP.protocol.extensions.si.SI si = iq.SelectSingleElement(typeof(agsXMPP.protocol.extensions.si.SI)) as agsXMPP.protocol.extensions.si.SI;

            if (si != null)
            {
                _file = si.File;

                _contact = Roster.Instance.FindContactOrGetNew(iq.From);
            }

            _message = string.Format("Incoming file '{0}' from {1}", FileName, Contact.DisplayName);
        }
Exemplo n.º 26
0
        private void OnIqVersion(agsXMPP.protocol.client.IQ iq, Element query)
        {
            ts.TraceInformation("OnIqVersion {0}", this.Jid.ToString());
            // its a version IQ VersionIQ
            agsXMPP.protocol.iq.version.Version version = query as agsXMPP.protocol.iq.version.Version;
            if (iq.Type == IqType.get)
            {
                iq.SwitchDirection();
                iq.Type = IqType.result;

                version.Name = "StateForgeClient";
                version.Ver  = "0.1";
                version.Os   = Environment.OSVersion.ToString();

                this.xmppClientConnection.Send(iq);
            }
        }
Exemplo n.º 27
0
        private void DiscoverInformationDone(object sender, IQ iq, object data)
        {
            var info = iq.Query as DiscoInfo;
            if(info == null)
                return;

            var identity = info.GetIdentities();
            var features = info.GetFeatures();

            if(features.Any(feature => feature.Var.EndsWith("muc")))
            {
                callback(iq.From);
                return;
            }

            discoManager.DiscoverItems(iq.From, DiscoverItemsDone);
        }
Exemplo n.º 28
0
        void OnIq(object sender, IQ iq)
        {
            if (iq.HasTag("oa"))
            {
                if (iq.InnerXml.Contains("errorcode=\"200\""))
                {
                    const string identityRegEx = "identity=([A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{12}):status";
                    var regex = new Regex(identityRegEx, RegexOptions.IgnoreCase | RegexOptions.Singleline);
                    var match = regex.Match(iq.InnerXml);
                    if (match.Success)
                    {
                        _sessionToken = match.Groups[1].ToString();
                    }

                    Wait = false;
                }
            }
        }
Exemplo n.º 29
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);
                        }
                    }
                }
            }
        }
        void TransferOpenUI(IQ iq)
        {
            FileTransfer fileTransfer = new FileTransfer(Account.Instance.XmppConnection, iq,
                                                            Roster.Instance.FindContactOrGetNew(iq.From));
            FileTransfer.FileTransfers.Add(fileTransfer);

            try
            {
                FileTransferWindow fileTransferWindow = new FileTransferWindow();

                fileTransferWindow.Show();
                fileTransferWindow.Activate();
            }

            catch (WindowExistsException e)
            {
                e.ActivateControl();
            }
        }
        /// <summary>
        /// Send message to HarmonyHub with UserAuthToken, wait for SessionToken
        /// </summary>
        /// <param name="userAuthToken"></param>
        /// <returns></returns>
        public string SwapAuthToken(string userAuthToken)
        {
            EnsureConnection();

            var iqToSend = new IQ { Type = IqType.get, Namespace = "", From = "1", To = "guest" };
            iqToSend.AddChild(HarmonyDocuments.LogitechPairDocument(userAuthToken));
            iqToSend.GenerateId();

            var iqGrabber = new IqGrabber(Xmpp);
            var iq = iqGrabber.SendIq(iqToSend, 5000);

            if (iq != null)
            {
                var match = IdentityRegex.Match(iq.InnerXml);
                if (match.Success)
                {
                    return match.Groups[1].ToString();
                }
            }

            return null;
        }
Exemplo n.º 32
0
        /// <summary>
        /// Sends an Iq synchronous and return the response or null on timeout
        /// </summary>
        /// <param name="iq">The IQ to send</param>
        /// <param name="timeout"></param>
        /// <returns>The response IQ or null on timeout</returns>
        public IQ SendIq(agsXMPP.protocol.client.IQ iq, int timeout)
        {
            synchronousResponse = null;
            AutoResetEvent are = new AutoResetEvent(false);

            SendIq(iq, new IqCB(SynchronousIqResult), are);

            if (!are.WaitOne(timeout, true))
            {
                // Timed out
                lock (m_grabbing)
                {
                    if (m_grabbing.ContainsKey(iq.Id))
                    {
                        m_grabbing.Remove(iq.Id);
                    }
                }
                return(null);
            }

            return(synchronousResponse);
        }
Exemplo n.º 33
0
 private void OnIq(object arg1, IQ arg2)
 {
     if (arg2.Id != _id || arg2.Type != IqType.result)
     {
         return;
     }
     _connection.OnIq -= _onIq.Exec;
     var vcard = arg2.Vcard;
     if (vcard == null)
     {
         _task.SetResult(null);
         return;
     }
     var description = vcard.Description;
     var birthday = vcard.Birthday;
     var fullname = vcard.Fullname;
     var url = vcard.Url;
     var photoType = vcard
             .With(vcard1 => vcard.Photo)
             .With(p => p.GetTag("TYPE"));
     var photoBin = vcard
             .With(vcard1 => vcard.Photo)
             .With(p => p.GetTag("BINVAL"))
             .With(p => p.Split('\r', '\n'))
             .With(p => p.FirstOrDefault())
             .With(Convert.FromBase64String);
     var conactDetails = new ContactDetails()
     {
         Fullname = fullname,
         Birthday = birthday,
         PhotoType = photoType,
         PhotoBin = photoBin,
         Description = description,
         Url =  url
     };
     _task.SetResult(conactDetails);
 }
Exemplo n.º 34
0
		/// <summary>
		/// An IQ Element is received. Now check if its one we are looking for and
		/// raise the event in this case.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		public void OnIq(object sender, IQ iq)
		{			
			if (iq == null)
				return;

			string id = iq.Id;
			if(id == null)
				return;

			TrackerData td;

			lock (m_grabbing)
			{
				td = (TrackerData) m_grabbing[id];

				if (td == null)
				{
					return;
				}
				m_grabbing.Remove(id);
			}
                       
            td.cb(this, iq, td.data);           
		}
Exemplo n.º 35
0
 /// <summary>
 ///     Get the data from the IQ response object
 /// </summary>
 /// <param name="iq">IQ response object</param>
 /// <returns>string with the data of the element</returns>
 private string GetData(IQ iq)
 {
     if (iq.HasTag("oa"))
     {
         var oaElement = iq.SelectSingleElement("oa");
         // Keep receiving messages until we get a 200 status
         // Activity commands send 100 (continue) until they finish
         var errorCode = oaElement.GetAttribute("errorcode");
         if ("200".Equals(errorCode))
         {
             return oaElement.GetData();
         }
     }
     return null;
 }
Exemplo n.º 36
0
        /// <summary>
        ///     Generate an IQ for the supplied Document
        /// </summary>
        /// <param name="document">Document</param>
        /// <returns>IQ</returns>
        private static IQ GenerateIq(Document document)
        {
            // Create the IQ to send
            var iqToSend = new IQ
            {
                Type = IqType.get,
                Namespace = "",
                From = "1",
                To = "guest"
            };

            // Add the real content for the Harmony
            iqToSend.AddChild(document);

            // Generate an unique ID, this is used to correlate the reply to the request
            iqToSend.GenerateId();
            return iqToSend;
        }
Exemplo n.º 37
0
        private void _xmppConnection_OnIq(object sender, IQ iq)
        {
            if (iq.Query != null && iq.Query.GetType() == typeof (ByteStream))
            {
                ByteStream bs = iq.Query as ByteStream;

                // check is this is for the correct file
                if (bs != null && bs.Sid == _sid)
                {
                    Thread t = new Thread(
                        delegate()
                            {
                                HandleStreamHost(bs, iq);
                            }
                        );
                    t.Name = "LoopStreamHosts";
                    t.Start();
                }
            }
        }
Exemplo n.º 38
0
        private void SiIqResult(object sender, IQ iq, object data)
        {
            // Parse the result of the form
            if (iq.Type == IqType.result)
            {
                SI si = iq.SelectSingleElement(typeof (SI)) as SI;
                if (si != null)
                {
                    FeatureNeg fNeg = si.FeatureNeg;
                    if (SelectedByteStream(fNeg))
                    {
                        DiscoProxy();
                    }
                }
            }
            else if (iq.Type == IqType.error)
            {
                Error err = iq.Error;
                if (err != null)
                {
                    switch ((int) err.Code)
                    {
                        case 403:
                            State = FileTransferState.Cancelled;
                            break;
                        default:
                            State = FileTransferState.Cancelled;
                            break;
                    }
                }

                OnTransferFinish(this);
            }
        }
Exemplo n.º 39
0
        private void SendStreamHostUsedResponse(StreamHost sh, IQ iq)
        {
            ByteStreamIq bsIQ = new ByteStreamIq(IqType.result, Contact.FullJid);
            bsIQ.Id = iq.Id;

            bsIQ.Query.StreamHostUsed = new StreamHostUsed(sh.Jid);
            _xmppConnection.Send(bsIQ);
        }
Exemplo n.º 40
0
        private void OnProxyDiscoResult(object sender, IQ iq, object data)
        {
            _streamHostProxy = null;

            if (iq.Error == null &&
                iq.Type == IqType.result)
            {
                ByteStream byteStream = iq.Query as ByteStream;

                if (byteStream != null
                    && byteStream.GetStreamHosts().Length > 0)
                {
                    _streamHostProxy = byteStream.GetStreamHosts()[0];
                }
            }

            SendStreamHosts();
        }
Exemplo n.º 41
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);
                    }
                }
            }
        }
Exemplo n.º 42
0
 protected IQ(IQ iq)
     : base(iq)
 {
 }
Exemplo n.º 43
0
 private void OnIqRegister(agsXMPP.protocol.client.IQ iq, Element query)
 {
     ts.TraceInformation("OnIqRegister {0} Query: {1}", this.Jid.ToString(), query.ToString());
 }
Exemplo n.º 44
0
        /// <summary>
        ///     Lookup the TaskCompletionSource for the IQ message and try to set the result.
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="iq">IQ</param>
        private void OnIqResponseHandler(object sender, IQ iq)
        {
            Debug.WriteLine("Received event " + iq.Id);
            Debug.WriteLine(iq.ToString());
            TaskCompletionSource<IQ> resulTaskCompletionSource;
            if ((iq.Id != null) && _resultTaskCompletionSources.TryGetValue(iq.Id, out resulTaskCompletionSource))
            {
                // Error handling from XMPP
                if (iq.Error != null)
                {
                    var errorMessage = iq.Error.ErrorText;
                    Debug.WriteLine(errorMessage);
                    resulTaskCompletionSource.TrySetException(new Exception(errorMessage));
                    // Result task is longer needed in the lookup
                    _resultTaskCompletionSources.Remove(iq.Id);
                    return;
                }

                // Message processing (error handling)
                if (iq.HasTag("oa"))
                {
                    var oaElement = iq.SelectSingleElement("oa");

                    // Check error code
                    var errorCode = oaElement.GetAttribute("errorcode");
                    // 100 -> continue
                    if ("100".Equals(errorCode))
                    {
                        // Ignoring 100 continue
                        Debug.WriteLine("Ignoring, expecting more to come.");

                        // TODO: Insert code to handle progress updates for the startActivity
                    }
                    // 200 -> OK
                    else if ("200".Equals(errorCode))
                    {
                        resulTaskCompletionSource.TrySetResult(iq);

                        // Result task is longer needed in the lookup
                        _resultTaskCompletionSources.Remove(iq.Id);
                    }
                    else
                    {
                        // We didn't get a 100 or 200, this must mean there was an error
                        var errorMessage = oaElement.GetAttribute("errorstring");
                        Debug.WriteLine(errorMessage);
                        // Set the exception on the TaskCompletionSource, it will be picked up in the await
                        resulTaskCompletionSource.TrySetException(new Exception(errorMessage));

                        // Result task is longer needed in the lookup
                        _resultTaskCompletionSources.Remove(iq.Id);
                    }
                }
                else
                {
                    Debug.WriteLine("Unexpected content");
                }
            }
            else
            {
                Debug.WriteLine("No matching result task found.");
            }
        }
Exemplo n.º 45
0
        private void XmppOnOnIq(object sender, IQ iq)
        {
            if(iq.Error != null && iq.Error.Code == ErrorCode.NotAllowed)
                if(OnLoginComplete != null)OnLoginComplete.Invoke(this,LoginResults.Failure);
            if(iq.Type == IqType.result)
            {
                if (iq.Vcard != null)
                {
                    var f = Friends.AsParallel().SingleOrDefault(x => x.User.Bare == iq.From.Bare);
                    if(f!= null)
                    {
                    	var email = DatabaseHandler.GetUser(f.User.Bare);
						if (String.IsNullOrWhiteSpace(email))
						{
							var s = iq.Vcard.GetEmailAddresses().SingleOrDefault(x => !String.IsNullOrWhiteSpace(x.UserId));
							if (s != null)
							{
								f.Email = s.UserId;
								DatabaseHandler.AddUser(f.User.Bare,f.Email);
							}
						}
						else f.Email = email;
                    }

                    if(OnDataRecieved != null)
                        OnDataRecieved.Invoke(this,DataRecType.FriendList, Friends);
                }
            }
        }
Exemplo n.º 46
0
        private void SendStreamHostsResult(object sender, IQ iq, object data)
        {
            if (iq.Type == IqType.result)
            {
                ByteStream bs = iq.Query as ByteStream;

                if (bs != null)
                {
                    Jid sh = bs.StreamHostUsed.Jid;

                    if (sh != null)
                    {
                        if (sh.Equals(Account.Instance.Self.FullJid, new FullJidComparer()))
                        {
                            // direct connection
                            SendFile(null);
                        }

                        if (_streamHostProxy != null
                            && sh.Equals(_streamHostProxy.Jid, new FullJidComparer()))
                        {
                            _p2pSocks5Socket = new JEP65Socket();
                            _p2pSocks5Socket.ConnectTimeout = ConnectionTimeout;
                            _p2pSocks5Socket.Address = _streamHostProxy.Host;
                            _p2pSocks5Socket.Port = _streamHostProxy.Port;
                            _p2pSocks5Socket.Target = Contact.FullJid;
                            _p2pSocks5Socket.Initiator = Account.Instance.Self.FullJid;
                            _p2pSocks5Socket.SID = _sid;
                            _p2pSocks5Socket.SyncConnect();

                            if (_p2pSocks5Socket.Connected)
                            {
                                ActivateBytestream(_streamHostProxy.Jid);
                            }
                        }
                    }
                }
            }
            else
            {
                State = FileTransferState.Cancelled;
            }
        }