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);        
        }
        /// <summary>
        /// Analyses an IQ paquet and chooses to handle it or not
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="iq"></param>
        private void GotIQ(object sender, IQ iq)
        {
            if (!iq.Handled &&
                iq.Query != null && iq.Type == IQType.get &&
                iq.Query.NamespaceURI == URI.PING)
            {
                iq.Handled = true;

                this.Write(iq.GetAcknowledge(m_stream.Document));
            }
        }
Beispiel #3
0
        public void Create()
        {
            Element.ResetID();

            IQ iq = new IQ(doc);
            Assert.AreEqual("<iq id=\"JN_1\" type=\"get\" />", iq.ToString());
            iq = new IQ(doc);
            Assert.AreEqual("<iq id=\"JN_2\" type=\"get\" />", iq.ToString());
            iq.Query = new Auth(doc);
            Assert.AreEqual("<iq id=\"JN_2\" type=\"get\"><query xmlns=\"jabber:iq:auth\" /></iq>", iq.ToString());
        }
Beispiel #4
0
 void AddRosterItemComplete(object sender, IQ response, object data)
 {
     if (response.Type == IQType.set) {
         QApplication.Invoke(delegate {
             Gui.MainWindow.HideLightbox();
         });
     } else {
         QApplication.Invoke(delegate {
             QMessageBox.Critical(base.TopLevelWidget(), "Failed to add user", "Server returned an error.");
         });
     }
 }
 /// <summary>
 /// An authorization exception from an IQ.
 /// TODO: Add constructor for code/message
 /// TODO: understand v1 errors
 /// </summary>
 /// <param name="iq"></param>
 public IQException(IQ iq)
 {
     if (iq == null)
     {
         //timeout
         m_code = 504;
         m_message = "Request timed out";
     }
     else
     {
         Error e = iq.Error;
         m_code = e.Code;
         m_message = e.InnerText;
     }
 }
        public void DiscoverCapabilities()
        {
            IQ              requestIq 	= new IQ();
            ServiceQuery    request 	= new ServiceQuery();

            request.Node    = this.DiscoveryInfoNode;
            requestIq.From  = this.Session.UserId.ToString();
            requestIq.ID    = XmppIdentifierGenerator.Generate();
            requestIq.To    = this.resource.ResourceId.ToString();
            requestIq.Type  = IQType.Get;

            requestIq.Items.Add(request);

            this.pendingMessages.Add(requestIq.ID);

            this.Session.Send(requestIq);
        }
Beispiel #7
0
        public void Publish(string node, XmlElement item)
        {
            IQ iq = new IQ(m_Account.Client.Document);
            iq.Type = IQType.set;
            PubSub pubsub = new PubSub(m_Account.Client.Document);
            pubsub.SetAttribute("xmlns", "http://jabber.org/protocol/pubsub");
            Publish publish = new Publish(m_Account.Client.Document);
            publish.SetAttribute("node", node);
            publish.AddChild(item);
            pubsub.AddChild(publish);
            iq.AddChild(pubsub);

            if (m_Account.ConnectionState == AccountConnectionState.Connected) {
                m_Account.Send(iq);
            } else {
                lock (m_Queue) {
                    m_Queue.Enqueue(iq);
                }
            }
        }
Beispiel #8
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(IQ iq, int timeout)
        {
            synchronousResponse = null;
            var are = new AutoResetEvent(false);

            SendIq(iq, 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);
        }
Beispiel #9
0
        /// <summary>
        ///   Stops user tune publications
        /// </summary>
        public IXmppSession StopTunePublication()
        {
            var iq      = new IQ();
            var pubsub  = new PubSub();
            var publish = new PubSubPublish();
            var item    = new PubSubItem();
            var tune    = new Tune();

            iq.Items.Add(pubsub);
            pubsub.Items.Add(publish);
            publish.Items.Add(item);

            iq.From      = UserId.ToString();
            iq.ID        = XmppIdentifierGenerator.Generate();
            iq.Type      = IQType.Set;
            publish.Node = XmppFeatures.UserMood;
            item.Item    = tune;

            Send(iq);

            return(this);
        }
Beispiel #10
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);
        }
Beispiel #11
0
        private void GotIQ(Elements.IQ iq)
        {
            switch (iq.IQType)
            {
            case IQType.error:
            case IQType.result:
                int no;
                if (iq.ID.StartsWith("n") && int.TryParse(iq.ID.Substring(1), out no))
                {
                    IQReply repl = null;

                    lock (fIQReplies)
                    {
                        if (fIQReplies.TryGetValue(no, out repl))
                        {
                            fIQReplies.Remove(no);
                        }
                    }
                    if (repl.Callback != null)
                    {
                        repl.Callback(iq);
                    }
                }
                break;     // else it's not one of ours

            default:
                // TODO: any known iq items here
                if (OnIQ(iq))
                {
                    return;
                }

                Elements.IQ replyiq = new IQ();
                replyiq.ID     = iq.ID;
                replyiq.IQType = IQType.error;

                break;
            }
        }
        protected virtual IQ GetDiscoInfo(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            if (((DiscoInfo)iq.Query).Node != null)
            {
                return(XmppStanzaError.ToServiceUnavailable(iq));
            }

            var service = ServiceManager.GetService(Jid);

            if (service == null)
            {
                return(XmppStanzaError.ToItemNotFound(iq));
            }

            var answer = new IQ(IqType.result);

            answer.Id    = iq.Id;
            answer.From  = Jid;
            answer.To    = iq.From;
            answer.Query = service.DiscoInfo;
            return(answer);
        }
 public IDayProbableCases_ResultElement Calculate(
     FhirDateTime t_IndexElement,
     II I,
     IJ J,
     IQ Q,
     IR R)
 {
     return(new C19M.M.C.A.Gumel2004.Classes.ResultElements.DayProbableCases.DayProbableCases_ResultElement(
                t_IndexElement,
                new FhirDecimal(
                    I.GetElementAtAsdecimal(
                        t_IndexElement)
                    +
                    J.GetElementAtAsdecimal(
                        t_IndexElement)
                    +
                    Q.GetElementAtAsdecimal(
                        t_IndexElement)
                    +
                    R.GetElementAtAsdecimal(
                        t_IndexElement))));
 }
Beispiel #14
0
        public void DeleteEvents()
        {
            // use alternate table def for methods that alter data during testing
            var opts = IQ.GetQueryOptions(tableName: tempTable);

            var dog = new EventDog();

            dog.Name = "SomeDog";
            dog.Age  = 10;
            IQ.Save(dog, opts);

            var id = dog.PK;

            dog.Events.Clear();
            bool deleted = dog.Delete(opts);

            Assert.IsTrue(deleted);
            Assert.AreEqual(2, dog.Events.Count, "Two events on delete");

            Assert.Throws <InvalidOperationException>(() =>
            {
                dog.Delete();
            }, "Can't delete with zero-valued primary key");



            dog.Save(opts);
            Assert.AreEqual(id + 1, dog.PK, "ID incremented by one for a new save");

            dog.RejectNextEvent = IQEventType.BeforeDelete;
            deleted             = dog.Delete(opts);

            Assert.IsFalse(deleted, "Was not actually deleted");
            dog.RejectNextEvent = IQEventType.OnDelete;
            Assert.Throws <InvalidOperationException>(() =>
            {
                dog.Delete();
            }, "Rejecting the after-delete event throws an exception");
        }
Beispiel #15
0
        private void OnIgnorelistUpdated(object sender, IQ iq, object data)
        {
            if (iq.Query == null)
            {
                return;
            }

            if (iq.Type == IqType.error)
            {
                if (iq.Error.Code == ErrorCode.NotFound)
                {
                    this.IgnoreList = new List <Item>();
                }
                return;
            }

            if (iq.Type != IqType.result)
            {
                return;
            }

            var privacy = iq.Query as Privacy;

            if (privacy != null)
            {
                var list = privacy.GetList().FirstOrDefault(x => x.Name == "ignore");
                if (list != null)
                {
                    this.IgnoreList = list.GetItems().ToList();
                }
            }

            this.Ignorees.Clear();

            foreach (var item in this.IgnoreList)
            {
                this.Ignorees.Add(new User(item.Val));
            }
        }
Beispiel #16
0
 private void SiIqResult2(object sender, IQ iq, object data)
 {
     if (iq.Type == IqType.result)
     {
         if (iq.Query != null && iq.Query.Namespace == "http://jabber.org/protocol/bytestreams")
         {
             //发送streamHost  地址给目标客户端
             IQ iqNew = new IQ();
             iqNew.Type = IqType.set;
             iqNew.Id   = iq.Id;
             iqNew.To   = m_To;
             //iqNew.From = m_XmppCon.MyJID;
             iqNew.InnerXml = "<query xmlns=\"http://jabber.org/protocol/bytestreams\" mode=\"tcp\" />";
             //iqNew.Query.Namespace = "http://jabber.org/protocol/bytestreams";
             //iqNew.Query.Attributes["mode"] = "tcp";
             iqNew.Query.Attributes["sid"] = m_Sid;
             iqNew.Query.InnerXml          = iq.Query.InnerXml;
             //"<streamhost jid=\"proxy.10.185.1.56\" port=\"7777\" host=\"10.185.1.56\" />
             m_XmppCon.IqGrabber.SendIq2(iqNew, new IqCB(SendStreamHostsResult), null);
         }
     }
 }
Beispiel #17
0
        private void ProcessIQ(IQ iq)
        {
            if (iq.Query.GetType() == typeof(Auth))
            {
                Auth auth = iq.Query as Auth;
                switch (iq.Type)
                {
                //响应用户验证请求
                case IqType.get:
                    iq.SwitchDirection();
                    iq.Type = IqType.result;
                    auth.AddChild(new Element("password"));
                    auth.AddChild(new Element("digest"));
                    Send(iq);
                    break;

                //进行用户验证
                case IqType.set:
                    //认证完成后,将建立的socket连接保存到集合
                    OnlineUser.Users.Add(new User
                    {
                        UserName   = auth.Username,
                        UserId     = 0,
                        ConnSocket = m_Sock,
                        Address    = m_Sock.RemoteEndPoint.ToString()
                    });
                    iq.SwitchDirection();
                    iq.Type  = IqType.result;
                    iq.Query = null;
                    Send(iq);
                    break;
                }
            }
            else if (iq.Query.GetType() == typeof(Roster))
            {
                ProcessRosterIQ(iq);
            }
        }
        async void InitGarmin()
        {
            var commStrategy = IQ.IQConnectType.Wireless;

            _iq = IQ.GetInstance(this, commStrategy);
            var initStatus = await _iq.InitializeAsync(this, autoUI : true);

            if (initStatus.HasError)
            {
                Log.Error("BindingTest", $"Received garmin SDK error {initStatus.ErrorStatus}");
                return;
            }

            var knownDevices = _iq.KnownDevices;

            _device = knownDevices.First(dev => dev.FriendlyName == "vivoactive HR");
            IQDevice.IQDeviceStatus status = _iq.GetDeviceStatus(_device);
            if (status != IQDevice.IQDeviceStatus.Connected)
            {
                return;
            }

            var appInfo = await _iq.GetApplicationInfoAsync("fc4cdb94-9339-44e4-ad86-2d235312f0e7", _device);

            if (!appInfo.Installed)
            {
                Log.Error("BindingTest", "Application not installed");
                return;
            }

            _app = appInfo.App;
            var javaMap = new Java.Util.HashMap();

            javaMap.Put(1, 6);
            var messageStatus = await _iq.SendMessageAsync(_device, _app, javaMap);

            Log.Info("BindingTest", $"Message status {messageStatus.MessageStatus}");
        }
Beispiel #19
0
 public static void ProcessRosterIQSet(string username, IQ iq)
 {
     if (iq.Query.HasChildElements)
     {
         BLL.Users api = new BLL.Users();
         foreach (Node r in iq.Query.ChildNodes)
         {
             Element el = r as Element;
             if (el != null)
             {
                 RosterItem ri = el as RosterItem;
                 if (el.HasAttribute("subscription"))
                 {
                     if (ri.Subscription == SubscriptionType.remove)
                     {
                         api.DeleteFriend(username, ri.Jid.User);
                     }
                 }
                 if (el.HasChildElements)
                 {
                     NodeList    li        = el.ChildNodes;
                     ElementList eli       = ri.GetGroups();
                     string      groupName = null;
                     if (eli.Count > 0)
                     {
                         groupName = eli.Item(0).Value;
                     }
                     if (li.Count > 0)
                     {
                         api.ChangeFriendStatus(username, ri.Jid.User, groupName, null, true);
                     }
                 }
             }
         }
         iq.Type = IqType.get;
         ProcessRosterIQGet(username, iq);
     }
 }
        private IQ SetVCardSearch(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            var answer = new IQ(IqType.result);

            answer.Id   = iq.Id;
            answer.To   = iq.From;
            answer.From = iq.To;

            var search = (Search)iq.Query;

            var pattern = new Vcard();

            pattern.Nickname = search.Nickname;
            pattern.Name     = new Name(search.Lastname, search.Firstname, null);
            //pattern.AddEmailAddress(new Email() { UserId = search.Email });

            search = new Search();
            foreach (var vcard in context.StorageManager.VCardStorage.Search(pattern))
            {
                var item = new SearchItem();
                item.Jid      = vcard.JabberId;
                item.Nickname = vcard.Nickname;
                if (vcard.Name != null)
                {
                    item.Firstname = vcard.Name.Given;
                    item.Lastname  = vcard.Name.Family;
                }
                var email = vcard.GetPreferedEmailAddress();
                if (email != null)
                {
                    item.Email = email.UserId;
                }
                search.AddChild(item);
            }

            answer.Query = search;
            return(answer);
        }
Beispiel #21
0
        public void SaveVCard()
        {
            IQ iq = new IQ(m_Client.Document);

            iq.Type = IQType.set;

            var vcard = m_Client.Document.ImportNode(m_MyVCard, true);

            iq.AppendChild(vcard);

            m_IQTracker.BeginIQ(iq, delegate(object o, IQ result, object cbArg) {
                if (result.Type == IQType.error)
                {
                    Console.WriteLine("Failed to set VCard!");
                }
            }, null);


            if (MyVCardUpdated != null)
            {
                MyVCardUpdated(this, EventArgs.Empty);
            }
        }
Beispiel #22
0
        /// <summary>
        /// Send message to HarmonyHub to request current activity
        /// Result is parsed by OnIq based on ClientCommandType
        /// </summary>
        public void GetCurrentActivity()
        {
            EnsureConnection();

            var iqToSend = new IQ {
                Type = IqType.get, Namespace = "", From = "1", To = "guest"
            };

            iqToSend.AddChild(HarmonyDocuments.GetCurrentActivityDocument());
            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)
                {
                    CurrentActivity = match.Groups[1].ToString().Split('=')[1];
                }
            }
        }
Beispiel #23
0
 private void OnDiscoInfoResult(object sender, IQ iq, object data)
 {
     // <iq from='proxy.cachet.myjabber.net' to='[email protected]/Exodus' type='result' id='jcl_19'>
     // <query xmlns='http://jabber.org/protocol/disco#info'>
     // <identity category='proxy' name='SOCKS5 Bytestreams Service' type='bytestreams'/>
     // <feature var='http://jabber.org/protocol/bytestreams'/>
     // <feature var='http://jabber.org/protocol/disco#info'/>
     // </query>
     // </iq>
     if (iq.Type == IqType.result)
     {
         if (iq.Query is DiscoInfo)
         {
             DiscoInfo di = iq.Query as DiscoInfo;
             if (di.HasFeature(agsXMPP.Uri.MUC))
             {
                 Jid jid = iq.From;
                 listView1.Groups.Add(jid.ToString(), jid.ToString());
                 discoManager.DiscoverItems(jid, new IqCB(OnDiscoRoomlist), null);
             }
         }
     }
 }
Beispiel #24
0
 private void OnVcardResult(object sender, IQ iq, object data)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new IqCB(OnVcardResult), new[] { sender, iq, data });
         return;
     }
     if (iq.Type == IqType.result && iq.HasTag(typeof(Vcard)))
     {
         Vcard vcard = iq.Vcard;
         if (vcard != null)
         {
             if (iq.Id == _packetId)
             {
                 pictureHead.Image     = vcard.Photo.Image;
                 labelControlName.Text = vcard.Nickname;
             }
             else
             {
                 ChatListItem item =
                     chatListBoxFriend.Items.Cast <ChatListItem>().FirstOrDefault(c => c.Text == data.ToString());
                 if (item != null)
                 {
                     ChatListSubItem subItem =
                         item.SubItems.Cast <ChatListSubItem>().FirstOrDefault(sub => sub.JidUser == iq.From.Bare);
                     if (subItem != null)
                     {
                         subItem.HeadImage   = vcard.Photo.Image;
                         subItem.NicName     = vcard.Name.Given;
                         subItem.DisplayName = vcard.Nickname;
                         subItem.PersonalMsg = null;
                     }
                 }
             }
         }
     }
 }
Beispiel #25
0
        public void AddRosterItem(JID jid, string name, string[] groups, IqCB callback)
        {
            var iq = new IQ(m_Client.Document);

            iq.Type = IQType.set;

            var item = new Item(m_Client.Document);

            item.JID      = jid;
            item.Nickname = name;

            if (groups != null)
            {
                foreach (var groupName in groups)
                {
                    var group = new Group(m_Client.Document);
                    group.GroupName = groupName;
                    item.AppendChild(group);
                }
            }

            iq.AppendChild(item);

            m_IQTracker.BeginIQ(iq, delegate(object sender, IQ response, object data) {
                if (response.Type != IQType.error)
                {
                    Presence presence = new Presence(m_Client.Document);
                    presence.To       = jid;
                    presence.Type     = PresenceType.subscribe;
                    m_Client.Write(presence);
                }
                if (callback != null)
                {
                    callback(sender, iq, data);
                }
            }, this);
        }
Beispiel #26
0
        private void OnRequestConfiguration(object sender, IQ iq, object obj)
        {
            agsXMPP.protocol.x.muc.iq.owner.OwnerIq oIq = new agsXMPP.protocol.x.muc.iq.owner.OwnerIq();
            oIq.Type = IqType.set;
            oIq.To   = iq.From;
            agsXMPP.protocol.x.data.Data data = new agsXMPP.protocol.x.data.Data(XDataFormType.submit);

            addFieldInDataIQ(data, "FORM_TYPE", "http://jabber.org/protocol/muc#roomconfig");
            addFieldInDataIQ(data, "muc#roomconfig_roomname", roomName);
            addFieldInDataIQ(data, "muc#roomconfig_roomdesc", roomDesc);
            addFieldInDataIQ(data, "muc#roomconfig_persistentroom", persistRoom);
            addFieldInDataIQ(data, "muc#roomconfig_publicroom", "1");
            addFieldInDataIQ(data, "public_list", "1");
            addFieldInDataIQ(data, "muc#roomconfig_passwordprotectedroom", (password == "") ? "0" : "1");
            addFieldInDataIQ(data, "muc#roomconfig_roomsecret", "");
            addFieldInDataIQ(data, "muc#roomconfig_maxusers", "1000");
            addFieldInDataIQ(data, "muc#roomconfig_whois", "moderators");
            addFieldInDataIQ(data, "muc#roomconfig_membersonly", "0");
            addFieldInDataIQ(data, "muc#roomconfig_moderatedroom", "1");
            addFieldInDataIQ(data, "members_by_default", "0");
            addFieldInDataIQ(data, "muc#roomconfig_membersonly", "0");
            addFieldInDataIQ(data, "muc#roomconfig_membersonly", "0");
            addFieldInDataIQ(data, "muc#roomconfig_changesubject", "1");
            addFieldInDataIQ(data, "allow_private_messages", "1");
            addFieldInDataIQ(data, "allow_private_messages_from_visitors", "anyone");
            addFieldInDataIQ(data, "allow_query_users", "1");
            addFieldInDataIQ(data, "muc#roomconfig_allowinvites", "0");
            addFieldInDataIQ(data, "muc#roomconfig_allowvisitorstatus", "1");
            addFieldInDataIQ(data, "muc#roomconfig_allowvisitornickchange", "0");
            addFieldInDataIQ(data, "muc#roomconfig_allowvoicerequests", "1");
            addFieldInDataIQ(data, "muc#roomconfig_voicerequestmininterval", "1800");
            addFieldInDataIQ(data, "muc#roomconfig_captcha_whitelist", "");
            addFieldInDataIQ(data, "muc#roomconfig_enablelogging", savingHistory);

            oIq.Query.AddChild(data);
            Settings.xmpp.IqGrabber.SendIq(oIq, new IqCB(OnGetFieldsResult), null);
        }
Beispiel #27
0
        private void SendStreamHostsResult(object sender, IQ iq, object data)
        {
            //  <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>
            if (iq.Type == IqType.result)
            {
                ByteStream bs = iq.Query as ByteStream;
                if (bs != null)
                {
                    Jid sh = bs.StreamHostUsed.Jid;
                    if (sh != null & sh.Equals(m_XmppCon.MyJID, new agsXMPP.Collections.FullJidComparer()))
                    {
                        // direct connection
                        SendFile(null);
                    }
                    if (sh != null & sh.Equals(new Jid(PROXY), new agsXMPP.Collections.FullJidComparer()))
                    {
                        _p2pSocks5Socket                = new JEP65Socket();
                        _p2pSocks5Socket.Address        = PROXY;
                        _p2pSocks5Socket.Port           = 7777;
                        _p2pSocks5Socket.Target         = m_To;
                        _p2pSocks5Socket.Initiator      = m_XmppCon.MyJID;
                        _p2pSocks5Socket.SID            = m_Sid;
                        _p2pSocks5Socket.ConnectTimeout = 5000;
                        _p2pSocks5Socket.SyncConnect();

                        if (_p2pSocks5Socket.Connected)
                        {
                            ActivateBytestream(new Jid(PROXY));
                        }
                    }
                }
            }
        }
Beispiel #28
0
        private void GotItems(object sender, IQ iq, object state)
        {
            if (iq.Type != IQType.result)
            {
                FireError(Op.ITEMS, "Error retrieving items", iq);
                return;
            }

            PubSub ps = iq["pubsub", URI.PUBSUB] as PubSub;

            if (ps == null)
            {
                FireError(Op.ITEMS, "Invalid pubsub protocol", iq);
                return;
            }
            PubSubItemCommand items = ps["items", URI.PUBSUB] as PubSubItemCommand;

            if (items == null)
            {
                // That doesn't really hurt us, I guess.  No items.  Keep going.
                this[Op.ITEMS] = STATE.Running;
                return;
            }

            if (items.Node != m_node)
            {
                FireError(Op.ITEMS, "Non-matching node.  Probably a server bug.", iq);
                return;
            }

            foreach (PubSubItem item in items.GetItems())
            {
                m_items.Add(item);
            }

            this[Op.ITEMS] = STATE.Running;
        }
        private void OnServiceDiscoveryMessage(IQ message)
        {
            pendingMessages.Remove(message.ID);

            Capabilities.Identities.Clear();
            Capabilities.Features.Clear();

            // Reponse to our capabilities query
            foreach (object item in message.Items)
            {
                if (item is ServiceQuery)
                {
                    var query = (ServiceQuery)item;

                    foreach (ServiceIdentity identity in query.Identities)
                    {
                        Capabilities.Identities.Add
                        (
                            new XmppServiceIdentity(identity.Name, identity.Category, identity.Type)
                        );
                    }

                    foreach (ServiceFeature supportedFeature in query.Features)
                    {
                        Capabilities.Features.Add(new XmppServiceFeature(supportedFeature.Name));
                    }
                }
            }

            if (!session.ClientCapabilitiesStorage.Exists(capabilities.Node, capabilities.VerificationString))
            {
                session.ClientCapabilitiesStorage.ClientCapabilities.Add(Capabilities);
                session.ClientCapabilitiesStorage.Save();
            }

            // NotifyPropertyChanged(() => Capabilities);
        }
Beispiel #30
0
 public static void GetUserPicture(string username, Presence pren)
 {
     if (Config.AppSetting.access.changepic)
     {
         Element             av = pren.SelectSingleElement("x");
         NetTalk.DAL.TbUsers user;
         NetTalk.BLL.Users   api = new NetTalk.BLL.Users();
         user = api.Find(username);
         if (user != null)
         {
             if (av.HasTag("hash"))
             {
                 if (user.TbVcard != null)
                 {
                     Element elhash = av.SelectSingleElement("hash");
                     if (!elhash.Value.Equals(user.TbVcard.VcardPhoto))
                     {
                         IQ uav = new IQ();
                         uav.Vcard = new Vcard();
                         uav.Type  = IqType.get;
                         int Index;
                         ThreadTools.Users.Online.IsAuthenticated(username, out Index);
                         if (Index > -1)
                         {
                             ThreadTools.Users.Online[Index].Send(uav);
                         }
                     }
                 }
             }
             else
             {
                 api.ChangeUserPicture(username, null);
             }
         }
     }
 }
Beispiel #31
0
        /// <summary>
        /// Sends an IQ request and waits for the response.
        /// </summary>
        /// <param name="iqp">An IQ packet to send, and wait for.</param>
        /// <param name="millisecondsTimeout">Time to wait for response, in milliseconds</param>
        /// <returns>An IQ in reponse to the sent IQ.</returns>
        public IQ IQ(IQ iqp, int millisecondsTimeout)
        {
            AutoResetEvent are = new AutoResetEvent(false);
            TrackerData    td  = new TrackerData(SignalEvent, are, iqp.To, iqp.ID);
            string         id  = iqp.ID;

            lock (m_pending)
            {
                m_pending[id] = td;
            }
            m_cli.Write(iqp);

            if (!are.WaitOne(millisecondsTimeout, true))
            {
                throw new Exception("Timeout waiting for IQ response");
            }

            lock (m_pending)
            {
                IQ resp = td.Response;
                m_pending.Remove(id);
                return(resp);
            }
        }
Beispiel #32
0
        /// <summary>
        ///   Adds to group.
        /// </summary>
        /// <param name = "groupName">Name of the group.</param>
        public void AddToGroup(string groupName)
        {
            var iq    = new IQ();
            var query = new RosterQuery();
            var item  = new RosterItem();

            if (!Groups.Contains(groupName))
            {
                Groups.Add(groupName);
            }

            iq.Type = IQType.Set;

            item.Jid          = ContactId.BareIdentifier;
            item.Name         = Name;
            item.Subscription = (RosterSubscriptionType)Subscription;

            item.Groups.Add(groupName);

            query.Items.Add(item);
            iq.Items.Add(query);

            session.Send(iq);
        }
Beispiel #33
0
        /// <summary>
        /// Retorna los campos de la consulta
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="iq"></param>
        /// <param name="data"></param>
        private void OnSearchFieldsResult(object sender, IQ iq, object data)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new IqCB(OnSearchFieldsResult), new object[] { sender, iq, data });
                return;
            }

            if (iq.Type == IqType.result)
            {
                if (iq.Query is Search)
                {
                    Search search = iq.Query as Search;
                    if (search.Data != null)
                    {
                        xDataControl.CreateForm(search.Data);
                    }
                    else
                    {
                        // no xdata form returned from the search service.
                        // TODO should we add the old jabber search without xdata too? I don't think so.
                        //toolStripLabelForm.Text = String.Format("{0} returned no data form", iq.From.ToString());
                        xDataControl.CreateForm(search);
                        _IsOldSearch = true;
                    }
                    xDataControl.From = iq.From;
                    cmdSearch.Enabled = true;

                    toolStripStatusLabel1.Text = String.Format("search form from {0}", iq.From.ToString());
                }
            }
            else if (iq.Type == IqType.error)
            {
                toolStripStatusLabel1.Text = String.Format("{0} returned an error", iq.From.ToString());
            }
        }
Beispiel #34
0
        protected virtual IQ GetDiscoItems(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            if (((DiscoItems)iq.Query).Node != null)
            {
                return(XmppStanzaError.ToServiceUnavailable(iq));
            }

            var answer = new IQ(IqType.result);

            answer.Id   = iq.Id;
            answer.From = Jid;
            answer.To   = iq.From;
            var items = new DiscoItems();

            answer.Query = items;
            foreach (var service in ServiceManager.GetChildServices(Jid))
            {
                if (service.DiscoItem != null)
                {
                    items.AddDiscoItem(service.DiscoItem);
                }
            }
            return(answer);
        }
Beispiel #35
0
        public void DiscoItemsQuery(jabber.JID to, string node, bool refresh, QueryCallback callback, object state)
        {
            if (!refresh)
            {
                IQ cache_version = XmppGlobal.InternalQueryCache.DiscoItems[to.ToString() + "!!!!!" + node];

                if (cache_version != null)
                {
                    callback.Invoke(this, cache_version, state);
                    return;
                }
            }

            DiscoItemsIQ iq = XmppGlobal.Queries.CreateDiscoItemsQuery();

            iq.To = to;

            if (!string.IsNullOrEmpty(node))
            {
                iq.Node = node;
            }

            XmppGlobal.Queries.SendQuery(iq, callback, state);
        }
 public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
 {
     if (iq.Query is PrivateLog && iq.Type == IqType.get)
     {
         return(GetPrivateLog(stream, iq, context));
     }
     if (iq.Query is PrivateLog && iq.Type == IqType.set)
     {
         return(SetPrivateLog(stream, iq, context));
     }
     if (iq.Query is PrivateLog && (iq.Type == IqType.result || iq.Type == IqType.error))
     {
         return(null);
     }
     if (iq.Query is History && iq.Type == IqType.get)
     {
         return(GetHistory(stream, iq, context));
     }
     if (iq.Query is Chatmarkers && iq.Type == IqType.get)
     {
         return(ClearUnreadMessages(stream, iq, context, _serviceProvider));
     }
     return(XmppStanzaError.ToServiceUnavailable(iq));
 }
Beispiel #37
0
        /// <summary>
        ///   Deletes a user from the roster list
        /// </summary>
        public XmppRoster RemoveContact(XmppJid jid)
        {
            var query = new RosterQuery();
            var iq    = new IQ();

            iq.ID   = XmppIdentifierGenerator.Generate();
            iq.Type = IQType.Set;
            iq.From = connection.UserId;

            var item = new RosterItem();

            item.Jid          = jid.BareIdentifier;
            item.Subscription = RosterSubscriptionType.Remove;

            query.Items.Add(item);

            iq.Items.Add(query);

            pendingMessages.Add(iq.ID);

            connection.Send(iq);

            return(this);
        }
Beispiel #38
0
        private void FireOnIQ(object sender, IQ iq)
        {
            // We know we're on the GUI thread.
            if (OnIQ != null)
                OnIQ(this, iq);

            if (AutoIQErrors)
            {
                if (!iq.Handled &&
                    iq.HasAttribute("from") &&   // Belt.  Suspenders.  Don't respond to roster pushes.
                    ((iq.Type == IQType.Get) || (iq.Type == IQType.Set)))
                {
                    Write(iq.GetErrorResponse(Document, Error.FeatureNotImplemented));
                }
            }
        }
        private IQ CreateDiscoInfoResponse(string id)
        {
            IQ returnIq = new IQ(doc);
            returnIq.SetAttribute("id", id);
            returnIq.SetAttribute("from", jid);
            returnIq.SetAttribute("type", "result");

            DiscoInfo info = new DiscoInfo(doc);
            info.AddIdentity("server", "im", "jabber2 4.2.16.6", null);
            info.AddFeature(URI.DISCO_ITEMS);
            info.AddFeature(URI.DISCO_INFO);

            returnIq.Query = info;

            return returnIq;
        }
Beispiel #40
0
 ///<summary>
 /// Does an asynchronous IQ call.
 /// If the from address hasn't been set, and an OverrideFrom has been set,
 /// the from address will be set to the value of OverrideFrom.
 ///</summary>
 ///<param name="iq">IQ packet to send.</param>
 ///<param name="cb">Callback to execute when the result comes back.</param>
 ///<param name="cbArg">Arguments to pass to the callback.</param>
 public void BeginIQ(IQ iq, IqCB cb, object cbArg)
 {
     if ((m_overrideFrom != null) && (iq.From == null))
         iq.From = m_overrideFrom;
     m_stream.Tracker.BeginIQ(iq, cb, cbArg);
 }
Beispiel #41
0
 private void OnSetAuth(object sender, IQ i, object data)
 {
     if ((i == null) || (i.Type != IQType.Result))
         FireAuthError(i);
     else
         IsAuthenticated = true;
 }
Beispiel #42
0
        private void OnGetAuth(object sender, IQ i, object data)
        {
            if ((i == null) || (i.Type != IQType.Result))
            {
                FireAuthError(i);
                return;
            }

            Auth res = i.Query as Auth;
            if (res == null)
            {
                FireOnError(new InvalidOperationException("Invalid IQ result type"));
                return;
            }

            AuthIQ aiq = new AuthIQ(Document) {Type = IQType.Set};
            Auth a = aiq.Instruction;

            if ((res["sequence"] != null) && (res["token"] != null))
            {
                a.SetZeroK(User, Password, res.Token, res.Sequence);
            }
            else if (res["digest"] != null)
            {
                a.SetDigest(User, Password, StreamID);
            }
            else if (res["password"] != null)
            {
                if (!SSLon && !PlaintextAuth)
                {
                    FireOnError(new AuthenticationFailedException("Plaintext authentication forbidden."));
                    return;
                }
                a.SetAuth(User, Password);
            }
            else
            {
                FireOnError(new NotImplementedException("Authentication method not implemented for:\n" + i));
                return;
            }
            if (res["resource"] != null)
                a.Resource = Resource;
            a.Username = User;

            lock (StateLock)
            {
                State = SetAuthState.Instance;
            }
            Tracker.BeginIQ(aiq, OnSetAuth, null);
        }
Beispiel #43
0
 private void GotSession(object sender, IQ iq, object state)
 {
     if ((iq != null) && (iq.Type == IQType.Result))
         IsAuthenticated = true;
     else
         FireOnError(new AuthenticationFailedException());
 }
        // We got back our disco#info query result
        private void GotInfoQuery(object sender, IQ iq, object state)
        {
            // If the user clicked stop, ignore this result
            if (was_stopped)
                return;

            try {
                if (iq.Type == IQType.result) {
                    DiscoInfo info = (DiscoInfo)iq.Query;

                    // If there is an <identity> node, display the data
                    if (info.GetIdentities ().Length > 0) {
                        DiscoIdentity i = info.GetIdentities ()[0];

                        IdentityNameLabel.Text = i.Named.Trim ();
                        IdentityAddressLabel.Text = iq.From.ToString ();
                        IdentityCategoryTypeLabel.Text = string.Format ("{0} - {1}", i.Category.Trim (), i.Type.Trim ());

                        Label4.Visible = true;
                    }

                    // Create the actions menu button
                    PopulateActions (iq);

                    // Track how many responses we have gotten back
                    TurnOffSpinner ();
                } else if (iq.Type == IQType.error)
                    GotErrorBack (iq);
            } catch (Exception) {
                GotErrorBack (iq);
                MessageBox.Show (string.Format ("Had a problem with Info response: {0}", iq.OuterXml));
            }
        }
 // There was an error, stop everything and display error image
 private void GotErrorBack(IQ iq)
 {
     StopButton.Enabled = false;
     Spinner.Visible = false;
     ErrorPicture.Visible = true;
     ErrorPicture.Tag = iq.OuterXml;
 }
        // We got back our disco#items commands query result
        private void GotCommandItemsQuery(object sender, IQ iq, object state)
        {
            // If the user clicked stop, ignore this result
            if (was_stopped)
                return;

            try {
                if (iq.Type == IQType.result) {
                    DiscoItems item = (DiscoItems)iq.Query;

                    foreach (ToolStripItem tsi in ActionMenu.Items) {
                        if (tsi.Text == "More Commands") {
                            ToolStripMenuItem mi = (ToolStripMenuItem)tsi;

                            mi.DropDownItems.Clear ();

                            foreach (DiscoItem i in item.GetItems ())
                                mi.DropDownItems.Add (i.Named, null, new EventHandler (GetCommandAction_Click)).Tag = new ItemNode (iq.From, i.Node);

                            if (mi.DropDownItems.Count == 0)
                                mi.DropDownItems.Add ("None");
                        }
                    }
                } else if (iq.Type == IQType.error)
                    MessageBox.Show ("Commands error");
            } catch (Exception) {
                GotErrorBack (iq);
                MessageBox.Show (string.Format ("Had a problem with Commands response: {0}", iq.OuterXml));
                throw;
            }
        }
Beispiel #47
0
 private void jc_OnRegistered(object sender, IQ iq)
 {
     if (iq.Type == IQType.result)
         jc.Login();
     else
         pnlCon.Text = "Registration error";
 }
Beispiel #48
0
        private void jc_OnIQ(object sender, IQ iq)
        {
            if (iq.Type != IQType.get)
                return;

            XmlElement query = iq.Query;
            if (query == null)
                return;

            // <iq id="jcl_8" to="me" from="you" type="get"><query xmlns="jabber:iq:version"/></iq>
            if (query is jabber.protocol.iq.Version)
            {
                iq = iq.GetResponse(jc.Document);
                jabber.protocol.iq.Version ver = iq.Query as jabber.protocol.iq.Version;
                if (ver != null)
                {
                    ver.OS = Environment.OSVersion.ToString();
                    ver.EntityName = Application.ProductName;
                    ver.Ver = Application.ProductVersion;
                }
                jc.Write(iq);
                return;
            }

            if (query is Time)
            {
                iq = iq.GetResponse(jc.Document);
                Time tim = iq.Query as Time;
                if (tim != null) tim.SetCurrentTime();
                jc.Write(iq);
                return;
            }

            if (query is Last)
            {
                iq = iq.GetResponse(jc.Document);
                Last last = iq.Query as Last;
                if (last != null) last.Seconds = (int)IdleTime.GetIdleTime();
                jc.Write(iq);
                return;
            }
        }
Beispiel #49
0
        private IQ muc_OnRoomConfig(Room room, IQ parent)
        {
            muzzle.XDataForm form = new muzzle.XDataForm(parent);
            if (form.ShowDialog() != DialogResult.OK)
                return null;

            return (IQ)form.GetResponse();
        }
Beispiel #50
0
        private void GotDiscoInfo(object sender, IQ iq, object state)
        {
            bool error = false;
            if (iq.Type == IQType.Error)
                error = true;
            else
            {
                DiscoInfo info = iq.Query as DiscoInfo;
                if (info == null)
                    error = true;
                else
                {
                    if (!info.HasFeature(URI.DISCO_ITEMS))
                        error = true;  // wow.  weird server.

                    // TODO: stash away features for this node in discomanager?
                }
            }

            if (error)
            {
                // TODO: check the error type that jabberd1.4 or XCP 2.x return
            }
        }
Beispiel #51
0
        private void GotResource(object sender, IQ iq, object state)
        {
            protocol.stream.Features feat = state as protocol.stream.Features;

            if (iq == null)
            {
                FireOnError(new AuthenticationFailedException("Timeout authenticating"));
                return;
            }
            if (iq.Type != IQType.Result)
            {
                Error err = iq.Error;
                if (err == null)
                    FireOnError(new AuthenticationFailedException("Unknown error binding resource"));
                else
                    FireOnError(new AuthenticationFailedException("Error binding resource: " + err.OuterXml));
                return;
            }

            XmlElement bind = iq["bind", URI.BIND];
            if (bind == null)
            {
                FireOnError(new AuthenticationFailedException("No binding returned.  Server implementation error."));
                return;
            }
            XmlElement jid = bind["jid"];
            if (jid == null)
            {
                FireOnError(new AuthenticationFailedException("No jid returned from binding.  Server implementation error."));
                return;
            }
            this[Options.JID] = new JID(jid.InnerText);

            if (feat["session", URI.SESSION] != null)
            {
                IQ iqs = new IQ(Document) {Type = IQType.Set};
                iqs.AddChild(new protocol.stream.Session(Document));
                Tracker.BeginIQ(iqs, GotSession, feat);
            }
            else
                IsAuthenticated = true;
        }
        // We got back our disco#items query result
        private void GotItemsQuery(object sender, IQ iq, object state)
        {
            // If the user clicked stop, ignore this result
            if (was_stopped)
                return;

            try {
                if (iq.Type == IQType.result) {
                    DiscoItems item = (DiscoItems)iq.Query;

                    // Put each returned <item> into the ServiceListView
                    foreach (DiscoItem i in item.GetItems ()) {
                        string name = i.Named;

                        if (string.IsNullOrEmpty (name))
                            name = i.Jid.ToString ();

                        string node = string.Empty;

                        if (i.Node != null)
                            node = i.Node;

                        ServiceListView.Items.Add (new ListViewItem (new string[] {name, i.Jid.ToString (), node}));
                    }

                    TurnOffSpinner ();
                } else if (iq.Type == IQType.error)
                    GotErrorBack (iq);
            } catch (Exception) {
                GotErrorBack (iq);
                MessageBox.Show (string.Format ("Had a problem with Items response: {0}", iq.OuterXml));
            }
        }
Beispiel #53
0
        private void JabberClient_OnSASLEnd(Object sender, protocol.stream.Features feat)
        {
            lock (StateLock)
            {
                State = BindState.Instance;
            }
            if (feat["bind", URI.BIND] != null)
            {
                IQ iq = new IQ(Document) {Type = IQType.Set};

                protocol.stream.Bind bind = new protocol.stream.Bind(Document);
                if (!string.IsNullOrEmpty(Resource))
                    bind.Resource = Resource;

                iq.AddChild(bind);
                Tracker.BeginIQ(iq, GotResource, feat);
            }
            else if (feat["session", URI.SESSION] != null)
            {
                IQ iq = new IQ(Document) {Type = IQType.Set};
                iq.AddChild(new protocol.stream.Session(Document));
                Tracker.BeginIQ(iq, GotSession, feat);
            }
            else
                IsAuthenticated = true;
        }
        // Using the DiscoInfo we got back, find actions we support and create a menu item for them
        private void PopulateActions(IQ info)
        {
            ActionMenu.Items.Clear ();
            ActionButton.Visible = false;

            ToolStripMenuItem cmi = null;

            foreach (DiscoFeature f in (info.Query as DiscoInfo).GetFeatures ()) {
                switch (f.Var)
                {
                    case "jabber:iq:time":
                        ToolStripMenuItem tsi = new ToolStripMenuItem ("Get Time", XmppImages.Time16, new EventHandler (GetTimeAction_Click));
                        tsi.Tag = info.From;
                        ActionMenu.Items.Add (tsi);
                        break;
                    case "jabber:iq:version":
                        ToolStripMenuItem tsi2 = new ToolStripMenuItem ("Get Version", XmppImages.Properties16, new EventHandler (GetVersionAction_Click));
                        tsi2.Tag = info.From;
                        ActionMenu.Items.Add (tsi2);
                        break;
                    case "vcard-temp":
                        ToolStripMenuItem tsi3 = new ToolStripMenuItem ("Get Information", XmppImages.VCard16, new EventHandler (GetInformationAction_Click));
                        tsi3.Tag = info.From;
                        ActionMenu.Items.Add (tsi3);
                        break;
                    case "jabber:iq:search":
                        ActionMenu.Items.Add ("Search (not implemented)");
                        break;
                    case "jabber:iq:register":
                        ActionMenu.Items.Add ("Register (not implemented)");
                        break;
                    case "http://jabber.org/protocol/commands":
                        cmi = new ToolStripMenuItem ("More Commands", XmppImages.Gear16);
                        cmi.DropDownItems.Add ("Requesting Commands..");
                        XmppGlobal.Disco.DiscoItemsQuery (info.From, "http://jabber.org/protocol/commands", true, new QueryCallback (GotCommandItemsQuery), null);
                        break;
                }
            }

            // We want the More Commands menu item to be at the bottom, after a separator
            if (cmi != null) {
                if (ActionMenu.Items.Count > 0)
                    ActionMenu.Items.Add (new ToolStripSeparator ());

                ActionMenu.Items.Add (cmi);
            }

            if (ActionMenu.Items.Count > 0)
                ActionButton.Visible = true;
        }
Beispiel #55
0
        private void OnGetRegister(object sender, IQ iq, object data)
        {
            if (iq == null)
            {
                FireOnError(new IQTimeoutException((JID) data));
                return;
            }

            if (iq.Type == IQType.Error)
            {
                if (OnRegistered != null)
                {
                    if (InvokeRequired)
                        CheckedInvoke(OnRegistered, new object[] {this, iq});
                    else
                        OnRegistered(this, iq);
                }
            }
            else if (iq.Type == IQType.Result)
            {
                JID jid = (JID) data;
                iq.Type = IQType.Set;
                iq.From = null;
                iq.To = jid.Server;
                iq.ID = Element.NextID();
                Register r = iq.Query as Register;
                if (r == null)
                    throw new BadProtocolException(iq, "Expected a register response");

                protocol.x.Data xdata = r["x", URI.XDATA] as protocol.x.Data;
                protocol.x.Field f;
                if (xdata != null)
                {
                    f = xdata.GetField("username");
                    if (f != null)
                        f.Val = jid.User;
                    f = xdata.GetField("password");
                    if (f != null)
                        f.Val = Password;
                }
                else
                {
                    r.Username = jid.User;
                    r.Password = Password;
                }

                bool res = true;
                if (OnRegisterInfo != null)
                {
                    if (InvokeRequired)
                        // Don't use CheckedInvoke, since we want this to be synchronous
                        res = (bool)InvokeControl.Invoke(OnRegisterInfo, new object[] { this, r });
                    else
                        res = OnRegisterInfo(this, r);
                    if (xdata != null)
                    {
                        f = xdata.GetField("username");
                        if (f != null)
                        {
                            User = f.Val;
                        }
                        f = xdata.GetField("password");
                        if (f != null)
                            Password = f.Val;
                    }
                    else
                    {
                        User = r.Username;
                        Password = r.Password;
                    }
                }
                if (!res)
                {
                    Close();
                    return;
                }
                if (xdata != null)
                    xdata.Type = protocol.x.XDataType.result;
                Tracker.BeginIQ(iq, OnSetRegister, jid);
            }
        }
Beispiel #56
0
        public override bool NewIQ(IQ iq)
        {
            if ((OutgoingRequestMessage != null) && (iq.ID == OutgoingRequestMessage.ID))
            {
                /// Got an ack, analyze it an tell the client what is going on
                IQResponseAction response = new IQResponseAction();
                if (iq.Type != IQType.result.ToString())
                {
                    response.AcceptIQ = false;
                    response.Error = iq.Error;
                }

                GoogleTalkSessionManager.FireNewSessionAckReceived(SessionId, response);
                return true;
            }
            if ((AcceptSessionMessage != null) && (iq.ID == AcceptSessionMessage.ID))
            {
                /// Client accept our session

                IQResponseAction response = new IQResponseAction();
                if (iq.Type != IQType.result.ToString())
                {
                    response.AcceptIQ = false;
                    response.Error = iq.Error;
                }

                GoogleTalkSessionManager.FireSessionAcceptedAck(SessionId, response);
                return true;
            }
            if ((TerminateSessionRequest != null) && (iq.ID == TerminateSessionRequest.ID))
            {
                /// Got an ack, analyze it an tell the client what is going on
                ///
                GoogleTalkSessionManager.FireSessionTerminated(SessionId);
                IsCompleted = true;
                return true;
            }

            return false;
        }
Beispiel #57
0
        private void OnSetRegister(object sender, IQ iq, object data)
        {
            if (OnRegistered == null)
                return;

            if (InvokeRequired)
                CheckedInvoke(OnRegistered, new object[] {this, iq});
            else
                OnRegistered(this, iq);
        }
Beispiel #58
0
        public void NewJingleIQ(GoogleTalkIQ gtiq)
        {
            /// New message coming in, see if it is session accept or session terminate
            ///
            if (gtiq.Type == IQType.error.ToString())
            {
                GoogleTalkSessionManager.FireSessionTerminated(this.SessionId);
                return;
            }

            if (gtiq.Type == IQType.set.ToString())
            {
                if (gtiq.Type == GoogleSession.Accept)
                {
                    IQ iqresponse = new IQ();
                    iqresponse.ID = gtiq.ID;
                    iqresponse.From = XMPPClient.JID;
                    iqresponse.To = gtiq.From;
                    iqresponse.Type = IQType.result.ToString();
                    XMPPClient.SendXMPP(iqresponse);

                    GoogleTalkSessionManager.FireSessionAcceptedReceived(this.SessionId, gtiq);
                }
                else if (gtiq.Type == GoogleSession.Terminate)
                {
                    /// Tell the user we've been terminated.  Ack and finish this logic
                    ///
                    IQ iqresponse = new IQ();
                    iqresponse.ID = gtiq.ID;
                    iqresponse.From = XMPPClient.JID;
                    iqresponse.To = gtiq.From;
                    iqresponse.Type = IQType.result.ToString();

                    XMPPClient.SendXMPP(iqresponse);
                    GoogleTalkSessionManager.FireSessionTerminated(this.SessionId);

                    this.IsCompleted = true;
                }
                else if (gtiq.Type == GoogleSession.TransportInfo)
                {

                    IQ iqresponse = new IQ();
                    iqresponse.ID = gtiq.ID;
                    iqresponse.From = XMPPClient.JID;
                    iqresponse.To = gtiq.From;
                    iqresponse.Type = IQType.result.ToString();
                    XMPPClient.SendXMPP(iqresponse);

                    GoogleTalkSessionManager.FireSessionTransportInfoReceived(this.SessionId, gtiq);
                }
                else
                {
                    IQ iqresponse = new IQ();
                    iqresponse.ID = gtiq.ID;
                    iqresponse.From = XMPPClient.JID;
                    iqresponse.To = gtiq.From;
                    iqresponse.Type = IQType.error.ToString();
                    iqresponse.Error = new Error("<Unknown action />");

                    XMPPClient.SendXMPP(iqresponse);
                }
            }
        }
Beispiel #59
0
        internal void NewIncomingSessionRequest(GoogleTalkIQ iq)
        {
            IncomingRequestMessage = iq;
            RemoteJID = iq.From;

            IQ iqresponse = new IQ();
            iqresponse.ID = IncomingRequestMessage.ID;
            iqresponse.From = XMPPClient.JID;
            iqresponse.To = IncomingRequestMessage.From;

            iqresponse.Type = IQType.result.ToString();
            XMPPClient.SendXMPP(iqresponse);

            GoogleTalkSessionManager.FireNewSession(this.SessionId, iq);
        }
Beispiel #60
0
        private void GotIQ(object sender, IQ iq)
        {
            if ((iq.Query == null) ||
                (iq.Query.NamespaceURI != jabber.protocol.URI.ROSTER) ||
                ((iq.Type != IQType.result) && (iq.Type != IQType.set)))
                return;

            iq.Handled = true;
            Roster r = (Roster) iq.Query;
            if ((iq.Type == IQType.result) && (OnRosterBegin != null))
                OnRosterBegin(this);

            foreach (Item i in r.GetItems())
            {
                lock (this)
                {
                    if (i.Subscription == Subscription.remove)
                    {
                        m_items.Remove(i.JID);
                    }
                    else
                    {
                        if (m_items.Contains(i.JID))
                            m_items.Remove(i.JID);
                        m_items[i.JID] = i;
                    }
                }
                if (OnRosterItem != null)
                    OnRosterItem(this, i);
            }

            if ((iq.Type == IQType.result) && (OnRosterEnd != null))
                OnRosterEnd(this);
        }