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); } } } }
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); } }
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); }
static XmppGlobal() { jabber_client = new JabberClient (); roster_manager = new RosterManager (); roster_manager.Stream = jabber_client; presence_manager = new PresenceManager (); presence_manager.Stream = jabber_client; iq_tracker = new IQTracker (jabber_client); connection = new Connection (); debug = new Debug (); disco = new Disco (); presence = new Presence (); roster = new Roster (); queries = new Queries (); query_cache = new QueryCache (); messaging = new Messaging (); }
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()); }
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); }
/// <summary>Signin button</summary> private void btnSignin_Click(object sender, EventArgs e) { panelCredentials.Enabled = false; JID jid = new JID(txtUserName.Text); if (String.IsNullOrEmpty(jid.User)) { jabberClient.User = txtUserName.Text; jabberClient.Server = cbServer.Text.Equals(DEFAULT_SERVER) ? "gmail.com" : cbServer.Text; } else { jabberClient.User = jid.User; jabberClient.Server = jid.Server; } jabberClient.NetworkHost = cbServer.Text; jabberClient.Password = txtPassword.Text; jabberClient.AutoRoster = true; jabberClient.AutoStartTLS = true; jabberClient.AutoPresence = true; jabberClient.AutoLogin = true; jabberClient.Resource = "realjabber"; //jabberClient.PlaintextAuth = true; jabberClient.OnAuthenticate += new bedrock.ObjectHandler(jabberClient_OnAuthenticate); jabberClient.OnInvalidCertificate += new System.Net.Security.RemoteCertificateValidationCallback(jabberClient_OnInvalidCertificate); jabberClient.AddNamespace("rtt", RealTimeTextUtil.RealTimeText.NAMESPACE); jabberClient.OnIQ += new IQHandler(jabberClient_OnIQ); rosterMgr = new RosterManager(); rosterMgr.Stream = jabberClient; rosterMgr.AutoSubscribe = true; rosterMgr.AutoAllow = jabber.client.AutoSubscriptionHanding.AllowAll; rosterMgr.OnRosterBegin += new bedrock.ObjectHandler(RosterMgr_OnRosterBegin); rosterMgr.OnRosterEnd += new bedrock.ObjectHandler(RosterMgr_OnRosterEnd); rosterMgr.OnRosterItem += new RosterItemHandler(RosterMgr_OnRosterItem); rosterMgr.OnSubscription += new SubscriptionHandler(rosterMgr_OnSubscription); rosterMgr.OnUnsubscription += new UnsubscriptionHandler(rosterMgr_OnUnsubscription); discoMgr = new DiscoManager(); discoMgr.Stream = jabberClient; capsMgr = new CapsManager(); capsMgr.DiscoManager = discoMgr; capsMgr.AddFeature(RealTimeTextUtil.RealTimeText.NAMESPACE); capsMgr.Node = RealTimeTextUtil.RealTimeText.NAMESPACE; capsMgr.Stream = jabberClient; presenceMgr = new PresenceManager(); presenceMgr.Stream = jabberClient; presenceMgr.CapsManager = capsMgr; rosterTree.RosterManager = rosterMgr; rosterTree.PresenceManager = presenceMgr; rosterTree.DoubleClick += new EventHandler(rosterTree_DoubleClick); lblUser.Text = jabberClient.User; jabberClient.Connect(); }
public void Connect() { _jabberClient = new JabberClient { Server = this.Server, User = this.UserName, Password = this.Password, Resource = this.Resource, AutoStartTLS = true, PlaintextAuth = true, AutoPresence = true, AutoRoster = false, AutoReconnect = -1, AutoLogin = true }; _presenceManager = new PresenceManager { Stream = _jabberClient }; _discoManager = new DiscoManager(); // add presence manager event handlers _presenceManager.OnPrimarySessionChange += presenceManager_OnPrimarySessionChange; _presenceManager.OnStreamChanged += presenceManager_OnStreamChanged; _presenceManager.OnPrimarySessionChange += presenceManager_OnPrimarySessionChange; // add jabber client event handlers _jabberClient.OnAfterPresenceOut += jabber_OnAfterPresenceOut; _jabberClient.OnAuthenticate += jabber_OnAuthenticate; _jabberClient.OnAuthError += jabber_OnAuthError; _jabberClient.OnBeforePresenceOut += jabber_OnBeforePresenceOut; _jabberClient.OnConnect += jabber_OnConnect; _jabberClient.OnDisconnect += jabber_OnDisconnect; _jabberClient.OnError += jabber_OnError; _jabberClient.OnInvalidCertificate += jabber_OnInvalidCertificate; _jabberClient.OnIQ += jabber_OnIQ; _jabberClient.OnLoginRequired += jabber_OnLoginRequired; _jabberClient.OnMessage += jabber_OnMessage; _jabberClient.OnPresence += jabber_OnPresence; _jabberClient.OnProtocol += jabber_OnProtocol; _jabberClient.OnReadText += jabber_OnReadText; _jabberClient.OnRegistered += jabber_OnRegistered; _jabberClient.OnRegisterInfo += jabber_OnRegisterInfo; _jabberClient.OnStreamError += jabber_OnStreamError; _jabberClient.OnStreamHeader += jabber_OnStreamHeader; _jabberClient.OnStreamInit += jabber_OnStreamInit; _jabberClient.OnWriteText += jabber_OnWriteText; // add discovery manager event handlers _discoManager.OnStreamChanged += discoManager_OnStreamChanged; // connect to the HipChat server this.Logger.Info(string.Format("Connecting to '{0}'", _jabberClient.Server)); _jabberClient.Connect(); var retryCountLimit = 10; while (!_jabberClient.IsAuthenticated && retryCountLimit > 0) { this.Logger.Info(string.Format("Waiting...")); retryCountLimit--; Thread.Sleep(1000); } if (_jabberClient.IsAuthenticated) { this.Logger.Info(string.Format("Authenticated as '{0}'", _jabberClient.User)); } }
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); }
public XmppProtocolManager(Session session) : base(session) { Trace.Call(session); JabberClient = new JabberClient(); JabberClient.Resource = "Smuxi"; JabberClient.AutoLogin = true; JabberClient.AutoPresence = false; JabberClient.OnStreamInit += OnStreamInit; JabberClient.OnMessage += OnMessage; JabberClient.OnConnect += OnConnect; JabberClient.OnDisconnect += OnDisconnect; JabberClient.OnAuthenticate += OnAuthenticate; JabberClient.OnError += OnError; JabberClient.OnProtocol += OnProtocol; JabberClient.OnWriteText += OnWriteText; JabberClient.OnIQ += OnIQ; RosterManager = new RosterManager(); RosterManager.Stream = JabberClient; RosterManager.OnRosterItem += OnRosterItem; PresenceManager = new PresenceManager(); PresenceManager.Stream = JabberClient; JabberClient.OnPresence += OnPresence; ConferenceManager = new ConferenceManager(); ConferenceManager.Stream = JabberClient; ConferenceManager.OnJoin += OnJoin; ConferenceManager.OnLeave += OnLeave; ConferenceManager.OnParticipantJoin += OnParticipantJoin; ConferenceManager.OnParticipantLeave += OnParticipantLeave; }
private void btLogin_Click(object sender, EventArgs e) { if (txtID.Text == "" || txtPW.Text == "") return; jabberClient1.User = txtID.Text; jabberClient1.Password = "******" + txtPW.Text; jabberClient1.NetworkHost = "chat." + retChatServer(cbServer.SelectedIndex) +".lol.riotgames.com"; jabberClient1.Connect(); panLogin.Visible = false; rm = new RosterManager(); rm.Stream = jabberClient1; rm.AutoSubscribe = true; rm.AutoAllow = jabber.client.AutoSubscriptionHanding.AllowAll; rm.OnRosterBegin += new bedrock.ObjectHandler(rm_OnRosterBegin); rm.OnRosterEnd += new bedrock.ObjectHandler(rm_OnRosterEnd); rm.OnRosterItem += new RosterItemHandler(rm_OnRosterItem); pm = new PresenceManager(); pm.Stream = jabberClient1; fRoster.RosterManager = rm; fRoster.PresenceManager = pm; }
public void Test_Create() { PresenceManager pp = new PresenceManager(); Assert.AreEqual("jabber.client.PresenceManager", pp.GetType().FullName); }
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]); }
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); }
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); }
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)); }
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 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); } } }
public void TestUserHost() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); JID f = new JID("foo", "bar", null); pres.From = f; pp.AddPresence(pres); Assert.AreEqual("foo@bar", pp[f.Bare].From.ToString()); }
private void btnSignin_Click(object sender, EventArgs e) { Console.WriteLine("ClickedSignIn"); User = txtUserName.Text; Pwd = txtPassword.Text; Server = textBoxServerName.Text; pnlCredentials.Enabled = false; jabberClient1.User = User; //jabberClient1.Server = "gmail.com"; jabberClient1.Server = textBoxServerName.Text; // this needs to be the server's name shown in the openfire GUI jabberClient1.NetworkHost = textBoxNetworkHost.Text; // this needs to be where the server is located // MacBook Air Local: jabberClient1.NetworkHost = "192.168.111.44"; // jabberClient1.NetworkHost = "192.168.111.11"; jabberClient1.Password = Pwd; jabberClient1.AutoRoster = true; jabberClient1.AutoStartTLS = true; jabberClient1.SSL = checkBox1.Checked; jabberClient1.Port = 5222; int port = 0; if (int.TryParse(textBoxPort.Text, out port)) jabberClient1.Port = port; rm = new RosterManager(); rm.Stream = jabberClient1; rm.AutoSubscribe = true; rm.OnSubscription += new SubscriptionHandler(rm_OnSubscription); rm.OnUnsubscription += new UnsubscriptionHandler(rm_OnUnsubscription); rm.AutoAllow = jabber.client.AutoSubscriptionHanding.AllowAll; rm.OnRosterBegin += new bedrock.ObjectHandler(rm_OnRosterBegin); rm.OnRosterEnd += new bedrock.ObjectHandler(rm_OnRosterEnd); rm.OnRosterItem += new RosterItemHandler(rm_OnRosterItem); pm = new PresenceManager(); pm.Stream = jabberClient1; rosterTree1.RosterManager = rm; rosterTree1.PresenceManager = pm; rosterTree1.DoubleClick += new EventHandler(rosterTree1_DoubleClick); jabberClient1.Connect(); jabberClient1.OnAuthenticate += new bedrock.ObjectHandler(jabberClient1_OnAuthenticate); lblUser.Text = jabberClient1.User; }
public void TestHostResource() { PresenceManager pp = new PresenceManager(); Presence pres = new Presence(doc); JID f = new JID(null, "bar", "baz"); pres.From = f; pp.AddPresence(pres); Assert.AreEqual("bar/baz", pp[f.Bare].From.ToString()); }