Пример #1
0
 public void Test_Parse_4()
 {
     JID j = new JID("boo@foo/bar");
     Assert.AreEqual("boo", j.User);
     Assert.AreEqual("foo", j.Server);
     Assert.AreEqual("bar", j.Resource);
 }
Пример #2
0
 public void Test_Parse_5()
 {
     JID j = new JID("foo/bar@baz");
     Assert.AreEqual(null, j.User);
     Assert.AreEqual("foo", j.Server);
     Assert.AreEqual("bar@baz", j.Resource);
 }
Пример #3
0
        /// <summary>
        /// Returns whether the given value object is valid for this type.
        /// Empty strings are allowed, since they will map to null.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool IsValid(System.ComponentModel.ITypeDescriptorContext context, object value)
        {
            string s = value as string;
            JID    j;

            if (s != null)
            {
                if (s == "")
                {
                    return(true);
                }

                try
                {
                    j = new JID(s);
                }
                catch (JIDFormatException)
                {
                    return(false);
                }
                return(true);
            }
            j = value as JID;
            return(j != null);
        }
Пример #4
0
        /// <summary>
        /// Converts the given value to the type of this converter.
        /// Empty strings are converted to null.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="culture"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value == null)
            {
                return(null);
            }

            string s = value as string;

            if (s != null)
            {
                if (s == "")
                {
                    return(null);
                }
                return(new JID(s));
            }
            JID j = value as JID;

            if (j != null)
            {
                return(j);
            }
            return(base.ConvertFrom(context, culture, value));
        }
Пример #5
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the comparands. The return value has these meanings:
        /// Less than zero This instance is less than obj.
        /// Zero This instance is equal to obj.
        /// Greater than zero This instance is greater than obj.
        /// </returns>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                return(1);
            }
            if (obj == (object)this)
            {
                return(0);
            }

            JID oj = obj as JID;

            if (oj == null)
            {
                throw new ArgumentException("Comparison of JID to non-JID", "obj");
            }

            // hm.  How tricky to get?
            // It could be that sorting by domain first is correct...
            //return this.m_JID.CompareTo(oj.m_JID);
            this.Parse();
            oj.Parse();

            int c = this.m_server.ToLower().CompareTo(oj.m_server.ToLower());

            if (c != 0)
            {
                return(c);
            }

            if (this.m_user == null)
            {
                if (oj.m_user != null)
                {
                    return(-1);
                }
            }
            else
            {
                if (oj.m_user == null)
                {
                    return(1);
                }

                c = this.m_user.ToLower().CompareTo(oj.m_user.ToLower());
                if (c != 0)
                {
                    return(c);
                }
            }

            if (this.m_resource == null)
            {
                return((oj.m_resource == null) ? 0 : -1);
            }
            return(this.m_resource.CompareTo(oj.m_resource));
        }
Пример #6
0
        public void Setup()
        {
            mocks = new MockRepository();
            stream = mocks.DynamicMock<XmppStream>();
            tracker = mocks.DynamicMock<IIQTracker>();
            doc = new XmlDocument();

            jid = new JID("test.example.com");
        }
Пример #7
0
 public void Test_Create()
 {
     JID j = new JID("foo", "jabber.com", "there");
     Assert.AreEqual("[email protected]/there", j.ToString());
     j = new JID(null, "jabber.com", null);
     Assert.AreEqual("jabber.com", j.ToString());
     j = new JID("foo", "jabber.com", null);
     Assert.AreEqual("*****@*****.**", j.ToString());
     j = new JID(null, "jabber.com", "there");
     Assert.AreEqual("jabber.com/there", j.ToString());
 }
Пример #8
0
        public static bool TryParse(string j, out JID jid)
        {
            try
            {
                jid = new JID(j);
                return(true);
            }
            catch { }

            jid = null;

            return(false);
        }
Пример #9
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);
        }
Пример #10
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());
        }
Пример #11
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());
 }
Пример #12
0
 public void Test_Numeric()
 {
     JID j = new JID("support", "conference.192.168.32.109", "bob");
     Assert.AreEqual("conference.192.168.32.109", j.Server);
 }
Пример #13
0
 public void Test_Unescape()
 {
     string u = new JID(@"d\[email protected]/elder").Unescape();
     Assert.AreEqual("d'artagnan", u);
     u = new JID(@"space\[email protected]").Unescape();
     Assert.AreEqual("space cadet", u);
     u = new JID(@"call\20me\20\22ishmael\[email protected]").Unescape();
     Assert.AreEqual("call me \"ishmael\"", u);
     u = new JID(@"at\26t\[email protected]").Unescape();
     Assert.AreEqual("at&t guy", u);
     u = new JID(@"\[email protected]").Unescape();
     Assert.AreEqual("/.fanboy", u);
     u = new JID(@"\3a\3afoo\3a\[email protected]").Unescape();
     Assert.AreEqual("::foo::", u);
     u = new JID(@"\3cfoo\[email protected]").Unescape();
     Assert.AreEqual("<foo>", u);
     u = new JID(@"user\[email protected]").Unescape();
     Assert.AreEqual("user@host", u);
     u = new JID(@"c\3a\[email protected]").Unescape();
     Assert.AreEqual(@"c:\net", u);
     u = new JID(@"c\3a\5c\[email protected]").Unescape();
     Assert.AreEqual(@"c:\\net", u);
     u = new JID(@"c\3a\5ccool\[email protected]").Unescape();
     Assert.AreEqual(@"c:\cool stuff", u);
     u = new JID(@"c\3a\[email protected]").Unescape();
     Assert.AreEqual(@"c:\5commas", u);
     u = new JID(@"\[email protected]").Unescape();
     Assert.AreEqual(@"\c0", u);
     u = new JID(@"\[email protected]").Unescape();
     Assert.AreEqual(@"\30", u);
 }
Пример #14
0
        /// <summary>
        /// Returns whether the given value object is valid for this type.
        /// Empty strings are allowed, since they will map to null.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override bool IsValid(System.ComponentModel.ITypeDescriptorContext context, object value)
        {
            string s = value as string;
            JID j;
            if (s != null)
            {
                if (s == "")
                    return true;

                try
                {
                    j = new JID(s);
                }
                catch (JIDFormatException)
                {
                    return false;
                }
                return true;
            }
            j = value as JID;
            return (j != null);
        }
Пример #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());
 }
Пример #16
0
 public void Test_EmptyResourceUser()
 {
     try
     {
         JID j = new JID("boo@foo/");
         string u = j.User;
         Assert.IsTrue(false);
     }
     catch (JIDFormatException)
     {
         Assert.IsTrue(true);
     }
     catch (Exception)
     {
         Assert.IsTrue(false);
     }
 }
Пример #17
0
 public void Test_Parse_11()
 {
     JID j = new JID("boo//foo");
     Assert.AreEqual(null, j.User);
     Assert.AreEqual("boo", j.Server);
     Assert.AreEqual("/foo", j.Resource);
 }
Пример #18
0
        private void m_pres_OnPrimarySessionChange(object sender, JID bare)
        {
            Presence pres = m_pres[bare];
            LinkedList nodelist = m_items[bare.ToString()] as LinkedList;

            if (nodelist == null)
                return;

            foreach (ItemNode n in nodelist)
                n.ChangePresence(pres);
        }
Пример #19
0
 public void Test_Compare_Less()
 {
     JID j = new JID("foo@bar/baz");
     Assert.AreEqual(-1, j.CompareTo(new JID("foo@bas/baz")));
     Assert.AreEqual(-1, j.CompareTo(new JID("fop@bar/baz")));
     Assert.AreEqual(-1, j.CompareTo(new JID("foo@bar/bazz")));
     j = new JID("foo@bar");
     Assert.AreEqual(-1, j.CompareTo(new JID("foo@bas/baz")));
     Assert.AreEqual(-1, j.CompareTo(new JID("foo@bas")));
     Assert.AreEqual(-1, j.CompareTo(new JID("fop@bar/baz")));
     Assert.AreEqual(-1, j.CompareTo(new JID("fop@bar")));
     Assert.AreEqual(-1, j.CompareTo(new JID("foo@bar/baz")));
     j = new JID("bar");
     Assert.AreEqual(-1, j.CompareTo(new JID("foo@bar/baz")));
     Assert.AreEqual(-1, j.CompareTo(new JID("foo@bar")));
     Assert.AreEqual(-1, j.CompareTo(new JID("bas")));
     Assert.AreEqual(-1, j.CompareTo(new JID("bas/baz")));
     Assert.AreEqual(-1, j.CompareTo(new JID("bar/baz")));
     Assert.AreEqual(true, j < new JID("foo@bar/baz"));
     Assert.AreEqual(true, j <= new JID("foo@bar/baz"));
 }
Пример #20
0
 public void Test_Compare_Equal()
 {
     JID j = new JID("foo@bar/baz");
     Assert.AreEqual(0, j.CompareTo(j));
     Assert.AreEqual(0, j.CompareTo(new JID("foo@bar/baz")));
     j = new JID("foo@bar");
     Assert.AreEqual(0, j.CompareTo(j));
     Assert.AreEqual(0, j.CompareTo(new JID("foo@bar")));
     Assert.IsTrue(j == new JID("foo@bar"));
     Assert.IsTrue(j == new JID("foo@BAR"));
     Assert.IsTrue(j == new JID("FOO@BAR"));
     Assert.IsTrue(j == new JID("FOO@bar"));
     Assert.AreEqual(new JID("FOO@bar").GetHashCode(), j.GetHashCode());
     j = new JID("bar");
     Assert.AreEqual(0, j.CompareTo(j));
     Assert.AreEqual(0, j.CompareTo(new JID("bar")));
     j = new JID("foo/bar");
     Assert.AreEqual(0, j.CompareTo(j));
     Assert.AreEqual(0, j.CompareTo(new JID("foo/bar")));
     Assert.AreEqual(true, j >= new JID("foo/bar"));
     Assert.AreEqual(true, j <= new JID("foo/bar"));
 }
Пример #21
0
 public void Test_TwoAt()
 {
     try
     {
         JID j = new JID("boo@foo@bar");
         string u = j.User;
         Assert.IsTrue(false);
     }
     catch (JIDFormatException)
     {
         Assert.IsTrue(true);
     }
     catch (Exception)
     {
         Assert.IsTrue(false);
     }
 }
Пример #22
0
 public void Test_NoHost()
 {
     try
     {
         JID j = new JID("foo@");
         string u = j.User;
         Assert.IsTrue(false);
     }
     catch (JIDFormatException)
     {
         Assert.IsTrue(true);
     }
     catch (Exception)
     {
         Assert.IsTrue(false);
     }
 }
Пример #23
0
 private void txtJID_Leave(object sender, EventArgs e)
 {
     if (!txtJID.Text.Contains("@") && (this.DefaultDomain != null))
     {
         txtJID.Text = txtJID.Text + "@" + this.DefaultDomain;
     }
     if (txtNickname.Text == "")
     {
         JID jid = new JID(txtJID.Text);
         txtNickname.Text = jid.User;
     }
 }
Пример #24
0
 public void Test_Compare_Greater()
 {
     JID j = new JID("foo@bar/baz");
     Assert.AreEqual(1, j.CompareTo(new JID("foo@bap/baz")));
     Assert.AreEqual(1, j.CompareTo(new JID("fon@bar/baz")));
     Assert.AreEqual(1, j.CompareTo(new JID("foo@bar/bay")));
     Assert.AreEqual(1, j.CompareTo(new JID("foo@bar")));
     Assert.AreEqual(1, j.CompareTo(new JID("bar")));
     Assert.AreEqual(1, j.CompareTo(new JID("bar/baz")));
     j = new JID("foo@bar");
     Assert.AreEqual(1, j.CompareTo(new JID("foo@bap/baz")));
     Assert.AreEqual(1, j.CompareTo(new JID("fon@bar/baz")));
     Assert.AreEqual(1, j.CompareTo(new JID("bar")));
     Assert.AreEqual(1, j.CompareTo(new JID("bar/baz")));
     Assert.AreEqual(true, j > new JID("foo@bap/baz"));
     Assert.AreEqual(true, j >= new JID("foo@bap/baz"));
     // /me runs out of interest.
 }
Пример #25
0
 public void Test_BadCompare()
 {
     try
     {
         JID j = new JID("foo@boo/bar");
         j.CompareTo("foo@boo/bar");
         Assert.IsTrue(false);
     }
     catch (ArgumentException)
     {
         Assert.IsTrue(true);
     }
     catch (Exception)
     {
         Assert.IsTrue(false);
     }
 }
Пример #26
0
 public void Test_Insensitive()
 {
     JID j = new JID("foo@boo/bar");
     Assert.AreEqual(0, j.CompareTo(new JID("foo@BOO/bar")));
     Assert.AreEqual(0, j.CompareTo(new JID("FOO@boo/bar")));
     Assert.AreEqual(0, j.CompareTo(new JID("FOO@BOO/bar")));
     Assert.AreEqual(-1, j.CompareTo(new JID("FOO@BOO/BAR")));
 }
Пример #27
0
        public static bool TryParse(string j, out JID jid)
        {
            try
            {
                jid = new JID(j);
                return true;
            }
            catch { }

            jid = null;

            return false;
        }
Пример #28
0
 public void Test_Config()
 {
     JID j = new JID("config@-internal");
     Assert.AreEqual("config", j.User);
     Assert.AreEqual("-internal", j.Server);
     Assert.AreEqual(null, j.Resource);
 }
Пример #29
0
        public Program(string[] args)
        {
            JabberClient jc = new JabberClient();
            jc.OnReadText += new Bedrock.TextHandler(jc_OnReadText);
            jc.OnWriteText += new Bedrock.TextHandler(jc_OnWriteText);
            jc.OnError += new Bedrock.ExceptionHandler(jc_OnError);
            jc.OnStreamError += new Jabber.Protocol.ProtocolHandler(jc_OnStreamError);

            jc.AutoReconnect = 3f;

            GetOpt go = new GetOpt(this);
            try
            {
                go.Process(args);
            }
            catch (ArgumentException)
            {
                go.UsageExit();
            }

            if (untrustedOK)
                jc.OnInvalidCertificate += new System.Net.Security.RemoteCertificateValidationCallback(jc_OnInvalidCertificate);

            JID j = new JID(jid);
            jc.User = j.User;
            jc.Server = j.Server;
            jc.NetworkHost = networkHost;
            jc.Port = port;
            jc.Resource = "Jabber.Net Console Client";
            jc.Password = pass;
            jc.AutoStartTLS = TLS;
            jc.AutoPresence = initialPresence;

            if (certificateFile != null)
            {
                jc.SetCertificateFile(certificateFile, certificatePass);
                Console.WriteLine(jc.LocalCertificate.ToString(true));
            }

            if (boshURL != null)
            {
                jc[Options.POLL_URL] = boshURL;
                jc[Options.CONNECTION_TYPE] = ConnectionType.HTTP_Binding;
            }

            if (register)
            {
                jc.AutoLogin = false;
                jc.OnLoginRequired +=
                    new Bedrock.ObjectHandler(jc_OnLoginRequired);
                jc.OnRegisterInfo += new RegisterInfoHandler(this.jc_OnRegisterInfo);
                jc.OnRegistered += new IQHandler(jc_OnRegistered);
            }

            CapsManager cm = new CapsManager();
            cm.Stream = jc;
            cm.Node = "http://cursive.net/clients/ConsoleClient";

            Console.WriteLine("Connecting");
            jc.Connect();
            Console.WriteLine("Connected");

            string line;
            while ((line = Console.ReadLine()) != null)
            {
                if (line == "/clear")
                {
                    // Hm.... I wonder if this works on windows.
                    Console.Write("\x1b[H\x1b[2J");
                    continue;
                }
                if ((line == "/q") || (line == "/quit"))
                {
                    jc.Close();
                    break;
                }
                if (line.Trim() == "")
                {
                    continue;
                }
                try
                {
                    if (line == "</stream:stream>")
                    {
                        jc.Write(line);
                    }
                    else
                    {
                        // TODO: deal with stanzas that span lines... keep
                        // parsing until we have a full "doc".
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(line);
                        XmlElement elem = doc.DocumentElement;
                        if (elem != null)
                            jc.Write(elem);
                    }
                }
                catch (XmlException ex)
                {
                    Console.WriteLine("Invalid XML: " + ex.Message);
                }
            }
        }
Пример #30
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);
        }