Ejemplo n.º 1
0
            public void RemovePresence(Presence p, PresenceManager handler)
            {
                JID    from = p.From;
                string res  = from.Resource;

                Debug.Assert(p.Type == PresenceType.unavailable);

                gen.LinkedListNode <Presence> n = Find(res);

                // unavail for a resource we haven't gotten presence from.
                if (n == null)
                {
                    return;
                }

                gen.LinkedListNode <Presence> last = m_all.Last;
                m_all.Remove(n);

                if (last == n)
                {
                    // current high-pri.
                    if ((m_all.Last != null) && (m_all.Last.Value.IntPriority >= 0))
                    {
                        Primary(m_all.Last.Value, handler);
                    }
                    else
                    {
                        // last non-negative presence went away
                        if (n.Value.IntPriority >= 0)
                        {
                            Primary(null, handler);
                        }
                    }
                }
            }
Ejemplo n.º 2
0
        public void TestAdd()
        {
            PresenceManager pp = new PresenceManager();
            Presence pres = new Presence(doc);
            JID f = new JID("foo", "bar", "baz");
            pres.From = f;
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/baz", pp[f].From.ToString());
            f.Resource = null;
            Assert.AreEqual("foo@bar/baz", pp[f].From.ToString());

            pres = new Presence(doc);
            pres.Status = "wandering";
            pres.From = new JID("foo", "bar", "baz");
            pp.AddPresence(pres);
            Assert.AreEqual("wandering", pp[f].Status);
        }
Ejemplo n.º 3
0
        public void TestRetrieve()
        {
            PresenceManager pp = new PresenceManager();
            Presence pres = new Presence(doc);
            JID f = new JID("foo", "bar", "baz");
            pres.From = f;
            pres.Priority = "0";
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/baz", pp[f.Bare].From.ToString());

            pres = new Presence(doc);
            f = new JID("foo", "bar", "bay");
            pres.From = f;
            pres.Priority = "1";
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/bay", pp[f.Bare].From.ToString());

            pres = new Presence(doc);
            pres.From = f;
            pres.Type = PresenceType.unavailable;
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/baz", pp[f.Bare].From.ToString());
        }
Ejemplo n.º 4
0
            public void AddPresence(Presence p, PresenceManager handler)
            {
                JID    from = p.From;
                string res  = from.Resource;

                Debug.Assert(p.Type == PresenceType.available);

                // If this is an update, remove the existing one.
                // we'll add the new one back in, in the correct place.
                gen.LinkedListNode <Presence> n = Find(res);
                if (n != null)
                {
                    m_all.Remove(n);
                }


                gen.LinkedListNode <Presence> inserted = new gen.LinkedListNode <Presence>(p);
                for (n = m_all.First; n != null; n = n.Next)
                {
                    if (p < n.Value)
                    {
                        m_all.AddBefore(n, inserted);
                        break;
                    }
                }

                // This is the highest one.
                if (inserted.List == null)
                {
                    m_all.AddLast(inserted);
                    if (p.IntPriority >= 0)
                    {
                        Primary(p, handler);
                    }
                }
            }
Ejemplo n.º 5
0
 private void Primary(Presence p, PresenceManager handler)
 {
     Debug.Assert((p == null) ? true : (p.IntPriority >= 0), "Primary presence is always positive priority");
     handler.FireOnPrimarySessionChange(m_jid);
 }
Ejemplo n.º 6
0
            public void RemovePresence(Presence p, PresenceManager handler)
            {
                JID from = p.From;
                string res = from.Resource;
                Debug.Assert(p.Type == PresenceType.unavailable);

                gen.LinkedListNode<Presence> n = Find(res);

                // unavail for a resource we haven't gotten presence from.
                if (n == null)
                    return;

                gen.LinkedListNode<Presence> last = m_all.Last;
                m_all.Remove(n);

                if (last == n)
                {
                    // current high-pri.
                    if ((m_all.Last != null) && (m_all.Last.Value.IntPriority >= 0))
                        Primary(m_all.Last.Value, handler);
                    else
                    {
                        // last non-negative presence went away
                        if (n.Value.IntPriority >= 0)
                            Primary(null, handler);
                    }
                }
            }
Ejemplo n.º 7
0
            public void AddPresence(Presence p, PresenceManager handler)
            {
                JID from = p.From;
                string res = from.Resource;
                Debug.Assert(p.Type == PresenceType.available);

                // If this is an update, remove the existing one.
                // we'll add the new one back in, in the correct place.
                gen.LinkedListNode<Presence> n = Find(res);
                if (n != null)
                    m_all.Remove(n);


                gen.LinkedListNode<Presence> inserted = new gen.LinkedListNode<Presence>(p);
                for (n = m_all.First; n != null; n = n.Next)
                {
                    if (p < n.Value)
                    {
                        m_all.AddBefore(n, inserted);
                        break;
                    }
                }

                // This is the highest one.
                if (inserted.List == null)
                {
                    m_all.AddLast(inserted);
                    if (p.IntPriority >= 0)
                        Primary(p, handler);
                }
            }
Ejemplo n.º 8
0
 private void Primary(Presence p, PresenceManager handler)
 {
     Debug.Assert((p == null) ? true : (p.IntPriority >= 0), "Primary presence is always positive priority");
     handler.FireOnPrimarySessionChange(m_jid);
 }
Ejemplo n.º 9
0
 public void TestHost()
 {
     PresenceManager pp = new PresenceManager();
     Presence pres = new Presence(doc);
     JID f = new JID("bar");
     pres.From = f;
     pp.AddPresence(pres);
     Assert.AreEqual("bar", pp[f.Bare].From.ToString());
 }
Ejemplo n.º 10
0
        public void TestCaps()
        {
            PresenceManager pp = new PresenceManager();
            Presence pres = new Presence(doc);
            pres.From = baz;

            CapsManager cm = new CapsManager();
            pp.CapsManager = cm;

            cm.FileName = "caps.xml";
            cm.Node = "http://cursive.net/clients/PresenceManagerTest";
            cm.AddFeature(URI.DISCO_INFO);
            cm.AddFeature(URI.DELAY);
            cm.AddIdentity("client", "pc", null, "Presence Manager Test");

            DiscoInfo info = new DiscoInfo(doc);
            cm.FillInInfo(info);
            cm[cm.Ver] = info;

            pres.AddChild(cm.GetCaps(pres.OwnerDocument));
            pp.AddPresence(pres);

            JID dij = pp.GetFeatureJID(bare, URI.DISCO_INFO);
            Assert.AreEqual(baz, dij);
            dij = pp.GetFeatureJID(bare, URI.DISCO_ITEMS);
            Assert.IsNull(dij);
            dij = pp.GetFeatureJID(baz, URI.DISCO_INFO);
            Assert.AreEqual(baz, dij);

            StringSet fs = pp.GetFeatures(bare);
            Assert.IsTrue(fs[URI.DISCO_INFO]);
            Assert.IsFalse(fs[URI.DISCO_ITEMS]);
        }
Ejemplo n.º 11
0
 public void Test_Create()
 {
     PresenceManager pp = new PresenceManager();
     Assert.AreEqual("jabber.client.PresenceManager", pp.GetType().FullName);
 }
Ejemplo n.º 12
0
        public void TestComparisons()
        {
            PresenceManager pp = new PresenceManager();

            Presence pres = new Presence(doc);
            pres.From = baz;
            pres.IntPriority = -1;
            pp.AddPresence(pres);
            Assert.AreEqual(null, pp[bare]);

            pres = new Presence(doc);
            pres.From = boo;
            pres.IntPriority = 0;
            pres.Show = "away";
            pp.AddPresence(pres);
            Assert.AreEqual(boo, pp[bare].From);

            pres = new Presence(doc);
            pres.From = baz;
            pres.IntPriority = 0;
            pres.Show = "xa";
            pp.AddPresence(pres);
            Assert.AreEqual(boo, pp[bare].From);

            pres = new Presence(doc);
            pres.From = boo;
            pres.IntPriority = 1;
            pp.AddPresence(pres);
            Assert.AreEqual(boo, pp[bare].From);
        }
Ejemplo n.º 13
0
        public void TestNewPrimaryAlgorithm()
        {
            PresenceManager pp = new PresenceManager();

            Presence pres = new Presence(doc);
            pres.From = baz;
            pres.IntPriority = 1;
            pp.AddPresence(pres);
            Assert.AreEqual(1, pp[bare].IntPriority);
            Assert.AreEqual(baz, pp[bare].From);

            pres = new Presence(doc);
            pres.From = boo;
            pres.IntPriority = 2;
            pp.AddPresence(pres);
            // duh.
            Assert.AreEqual(2, pp[bare].IntPriority);
            Assert.AreEqual(boo, pp[bare].From);

            pres = new Presence(doc);
            pres.From = boo;
            pres.IntPriority = 0;
            pp.AddPresence(pres);
            Assert.AreEqual(1, pp[bare].IntPriority);
            Assert.AreEqual(baz, pp[bare].From); // ooo

            pres = new Presence(doc);
            pres.From = boo;
            pres.Type = PresenceType.unavailable;
            pp.AddPresence(pres);
            Assert.AreEqual(1, pp[bare].IntPriority);
            Assert.AreEqual(baz, pp[bare].From);

            pres = new Presence(doc);
            pres.From = baz;
            pres.IntPriority = -1;
            pp.AddPresence(pres);
            Assert.AreEqual(null, pp[bare]);

            pres = new Presence(doc);
            pres.From = baz;
            pres.Type = PresenceType.unavailable;
            pp.AddPresence(pres);
            Assert.AreEqual(0, pp.GetAll(bare).Length);
        }
Ejemplo n.º 14
0
        public void TestGetAll()
        {
            PresenceManager pp = new PresenceManager();

            Presence pres = new Presence(doc);
            pres.From = baz;
            pp.AddPresence(pres);

            pres = new Presence(doc);
            pres.From = boo;
            pp.AddPresence(pres);

            Presence[] pa = pp.GetAll(bare);
            Assert.AreEqual(2, pa.Length);
            Assert.AreEqual(pa[0].GetType(), typeof(Presence));
        }
Ejemplo n.º 15
0
 public void TestNumeric()
 {
     PresenceManager pp = new PresenceManager();
     Presence pres = new Presence(doc);
     JID f = new JID("support", "conference.192.168.32.109", "bob");
     pres.From = f;
     pres.Status = "Working";
     pp.AddPresence(pres);
     Assert.AreEqual("[email protected]/bob", pp[f].From.ToString());
     f.Resource = null;
     Assert.AreEqual("[email protected]/bob", pp[f].From.ToString());
 }
Ejemplo n.º 16
0
        public void TestRemove()
        {
            PresenceManager pp = new PresenceManager();
            Presence pres = new Presence(doc);
            JID f = new JID("foo", "bar", "baz");
            pres.From = f;
            pres.Status = "Working";
            pres.Priority = "1";
            pp.AddPresence(pres);
            Assert.AreEqual("foo@bar/baz", pp[f].From.ToString());
            f.Resource = null;
            Assert.AreEqual("foo@bar/baz", pp[f].From.ToString());

            pres = new Presence(doc);
            pres.Status = "wandering";
            pres.From = new JID("foo", "bar", "boo");
            pp.AddPresence(pres);
            Assert.AreEqual("Working", pp[f].Status);
            pres.Priority = "2";
            pp.AddPresence(pres);
            Assert.AreEqual("wandering", pp[f].Status);
            pres.Type = PresenceType.unavailable;
            pp.AddPresence(pres);
            Assert.AreEqual("Working", pp[f].Status);
        }