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); }
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); }
/// <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); }
/// <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)); }
/// <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)); }
public void Setup() { mocks = new MockRepository(); stream = mocks.DynamicMock<XmppStream>(); tracker = mocks.DynamicMock<IIQTracker>(); doc = new XmlDocument(); jid = new JID("test.example.com"); }
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()); }
public static bool TryParse(string j, out JID jid) { try { jid = new JID(j); return(true); } catch { } jid = null; return(false); }
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); }
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()); }
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()); }
public void Test_Numeric() { JID j = new JID("support", "conference.192.168.32.109", "bob"); Assert.AreEqual("conference.192.168.32.109", j.Server); }
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); }
/// <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); }
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()); }
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); } }
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); }
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); }
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")); }
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")); }
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); } }
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); } }
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; } }
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. }
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); } }
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"))); }
public static bool TryParse(string j, out JID jid) { try { jid = new JID(j); return true; } catch { } jid = null; return false; }
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); }
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); } } }
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); }