Ejemplo n.º 1
0
        private void subscribeToPubSubToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PubSubSubcribeForm ps = new PubSubSubcribeForm();

            // this is a small race.  to do it right, I should call dm.BeginFindServiceWithFeature,
            // and modify that to call back on all of the found services.  The idea is that
            // by the the time the user has a chance to click on the menu item, the DiscoManager
            // will be populated.
            ps.DiscoManager = dm;
            if (ps.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            JID    jid  = ps.JID;
            string node = ps.Node;
            string text = string.Format("{0}/{1}", jid, node);

            TabPage tp = new TabPage(text);

            tp.Name = text;

            PubSubDisplay disp = new PubSubDisplay();

            disp.Node = psm.GetNode(jid, node, 10);
            tp.Controls.Add(disp);
            disp.Dock = DockStyle.Fill;

            tabControl1.TabPages.Add(tp);
            tabControl1.SelectedTab = tp;
        }
Ejemplo n.º 2
0
 public ConversationItem(ConversationSender sender, JID identifier, DateTime timestamp)
 {
     Sender     = sender;
     Identifier = identifier;
     Timestamp  = timestamp;
     Messages   = new ObservableCollection <ConversationMessage>();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets all of the current presence stanzas for the given user.
 /// </summary>
 /// <param name="jid">User who's presence stanzas you want.</param>
 /// <returns>Array of presence stanzas for the given user.</returns>
 public Presence[] GetAll(JID jid)
 {
     UserPresenceManager upm = (UserPresenceManager)m_items[jid.Bare];
     if (upm == null)
         return new Presence[0];
     return upm.GetAll();
 }
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
        /// <summary>
        /// TODO: Documentation SessionInfo
        /// </summary>
        /// <param name="to"></param>
        /// <param name="sid"></param>
        /// <param name="payload"></param>
        /// <returns></returns>
        public void SessionInfo(JID to, String sid, Element payload)
        {
            JingleIQ jingleIq;

            if (payload != null)
            {
                jingleIq = new JingleIQ(payload.OwnerDocument);
            }
            else
            {
                jingleIq = new JingleIQ(this.Stream.Document);
            }

            jingleIq.From = this.Stream.JID;
            jingleIq.To   = to;
            jingleIq.Type = IQType.set;
            jingleIq.Instruction.Action = ActionType.session_info;
            jingleIq.Instruction.Sid    = sid;

            if (payload != null)
            {
                jingleIq.Instruction.AddChild(payload);
            }

            this.Stream.Write(jingleIq);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Does the given JID implement the given feature?  Bare JID asks if any
 /// resource of that user implements that feature.  Full JID asks if the
 /// given resource implements that feature.
 /// 
 /// Requires a CapsManager to be set before use.
 /// </summary>
 /// <param name="jid"></param>
 /// <param name="featureURI"></param>
 /// <returns>True if the feaure is implemented</returns>
 public bool HasFeature(JID jid, string featureURI)
 {
     StringSet feats = GetFeatures(jid);
     if (feats == null)
         return false;
     return feats[featureURI];
 }
Ejemplo n.º 7
0
 public static SASLHandler Create(List <string> availableMethods, JID clientJID, string password)
 {
     // return availableMethods.Contains("SCRAM-SHA-1") ? new SASLSCRAM { ClientJID = clientJID, Password = password} : null;
     return(new SASLSCRAM {
         ClientJID = clientJID, Password = password
     });
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Add an privacy item that shows or hides this particular JID from list when in invisible mode
        /// </summary>
        /// <returns></returns>
        public PrivacyItem AddPrivacyItem(JID jid, PrivacyItemAction action, PrivacyItemRights right)
        {
            XmlElement e = GetOrCreateElement("list", null, null);


            PrivacyItem p = CreateChildElement <PrivacyItem>(e);

            p.Value  = jid.Bare;
            p.Type   = PrivacyItemType.jid;
            p.Action = action;
            p.Order  = GetPrivacyItems().Length;

            switch (right)
            {
            case PrivacyItemRights.PresenceIn:
                p.AllowPresenceIn = true;
                break;

            case PrivacyItemRights.PresenceOut:
                p.AllowPresenceOut = true;
                break;

            case PrivacyItemRights.Messages:
                p.AllowMessages = true;
                break;
            }

            return(p);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// TODO: Documentation InitiateSession
        /// </summary>
        /// <param name="to"></param>
        /// <param name="useTurnOnly"></param>
        /// <returns></returns>
        public String InitiateSession(JID to, Boolean useTurnOnly)
        {
            if (this.StartingSessionRecipient == null && to != this.Stream.JID)
            {
                this.StartingSessionRecipient = to;
                this.StartingSessionSid       = JingleUtilities.GenerateSid;
                this.StartingSessionAction    = ActionType.session_initiate;

                if (this.OnBeforeInitiatorAllocate != null)
                {
                    this.OnBeforeInitiatorAllocate(this, new EventArgs());
                }

                if (this.TurnSupported)
                {
                    this.CreateTurnSession(this.StartingSessionSid, useTurnOnly);
                }
                else
                {
                    throw new NotSupportedException();
                }

                return(this.StartingSessionSid);
            }
            return(null);
        }
Ejemplo n.º 10
0
 private void presenceManager_OnPrimarySessionChange(object sender, JID bare)
 {
     if (bare.Bare.Equals(_jabberClient.JID.Bare, StringComparison.InvariantCultureIgnoreCase))
     {
         return;
     }
 }
Ejemplo n.º 11
0
        private void SendRandomResponse(JID replyTo, string chatText, MessageType messageType)
        {
            string[] chatTextWords = chatText.Split(' ');
            string   message       = string.Empty;

            switch (chatTextWords[0])
            {
            case "coolio":
            case "gaytroll":
                message = "Get-RandomImage " + chatText;
                break;

            default:
                break;
            }

            if (message != string.Empty)
            {
                PowerShellCommand     powerShellCommand = BuildPowerShellCommand(message);
                Collection <PSObject> psObjects         = _powershellRunner.RunPowerShellModule(powerShellCommand.CommandText,
                                                                                                powerShellCommand.ParameterText);
                SendResponse(replyTo, psObjects, messageType);
            }
            return;
        }
Ejemplo n.º 12
0
 private void FireOnPrimarySessionChange(JID from)
 {
     if (OnPrimarySessionChange != null)
     {
         OnPrimarySessionChange(this, from);
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Determines if a specified JID is online with any resources.
 /// This performs better than retrieving the particular associated presence packet.
 /// </summary>
 /// <param name="jid">The JID to look up.</param>
 /// <returns>If true, the user is online; otherwise the user is offline</returns>
 public bool IsAvailable(JID jid)
 {
     lock (this)
     {
         return(m_items[jid.Bare] != null);
     }
 }
Ejemplo n.º 14
0
        private void SendResponse(JID replyTo, Collection <PSObject> psObjects, MessageType messageType)
        {
            foreach (var psObject in psObjects)
            {
                Logger.Info(psObject.ImmediateBaseObject.GetType().FullName);
                string message = string.Empty;

                // the PowerShell (.NET) return types we are supporting
                if (psObject.BaseObject.GetType() == typeof(string))
                {
                    message = psObject.ToString();
                }

                else if (psObject.BaseObject.GetType() == typeof(Hashtable))
                {
                    Hashtable hashTable = (Hashtable)psObject.BaseObject;

                    foreach (DictionaryEntry dictionaryEntry in hashTable)
                    {
                        message += string.Format("{0} = {1}\n", dictionaryEntry.Key, dictionaryEntry.Value);
                    }
                }

                SendMessage(messageType, replyTo, message);
            }
        }
Ejemplo n.º 15
0
        private void Session_OnMessageReceived(object sender, Message message)
        {
            if (message.Body == null && message.X == null)
            {
                return;
            }

            string chatText = message.Body == null?message.X.InnerText.Trim() : message.Body.Trim();

            if (string.IsNullOrEmpty(chatText) || chatText == " ")
            {
                return;
            }

            JID responseJid = new JID(message.From.User, message.From.Server, message.From.Resource);

            // intercept a handful of messages not directly for AutoBot
            if (message.Type == MessageType.groupchat && !chatText.Trim().StartsWith(_mentionName))
            {
                chatText = RemoveMentionFromMessage(chatText);
                SendRandomResponse(responseJid, chatText, message.Type);
                return;
            }

            // ensure the message is intended for AutoBot
            chatText = RemoveMentionFromMessage(chatText);
            PowerShellCommand     powerShellCommand = BuildPowerShellCommand(chatText);
            Collection <PSObject> psObjects         = _powershellRunner.RunPowerShellModule(powerShellCommand.CommandText,
                                                                                            powerShellCommand.ParameterText);

            SendResponse(responseJid, psObjects, message.Type);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Sends a presence subscription request and updates the roster
        /// for a new roster contact.
        /// </summary>
        /// <param name="to">The JID of the contact (required)</param>
        /// <param name="nickname">The nickname to show for the contact.</param>
        /// <param name="groups">A list of groups to put the contact in.  May be null.  Hint: new string[] {"foo", "bar"}</param>
        public void Subscribe(JID to, string nickname, string[] groups)
        {
            Debug.Assert(to != null);

            RosterIQ riq = new RosterIQ(Document);

            riq.Type = IQType.set;
            Roster r = riq.Instruction;
            Item   i = r.AddItem();

            i.JID = to;
            if (nickname != null)
            {
                i.Nickname = nickname;
            }
            if (groups != null)
            {
                foreach (string g in groups)
                {
                    i.AddGroup(g);
                }
            }
            Write(riq); // don't care about result.  we should get a iq/response and a roster push.

            Presence pres = new Presence(Document);

            pres.To   = to;
            pres.Type = PresenceType.subscribe;
            Write(pres);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Get the details for the given conference bookmark.
        /// </summary>
        /// <param name="jid"></param>
        /// <returns></returns>
        public BookmarkConference this[JID jid]
        {
            get { return(m_conferences[jid]); }
            set
            {
                BookmarkConference prev = null;
                if (value == null)
                {
                    if (m_conferences.TryGetValue(jid, out prev))
                    {
                        m_conferences.Remove(jid);
                        prev.SetAttribute("remove", "true");
                    }
                    else
                    {
                        // no-op.  Setting null on a non-existing JID.
                        return;
                    }
                }
                else
                {
                    m_conferences[jid] = prev = value;
                }

                BookmarksIQ biq = new BookmarksIQ(m_stream.Document);
                biq.Type = IQType.set;
                Bookmarks bm = biq.Bookmarks;
                foreach (BookmarkConference conf in m_conferences.Values)
                {
                    bm.AddChild((XmlElement)conf.CloneNode(true, m_stream.Document));
                }
                m_stream.Tracker.BeginIQ(biq, BookmarksSet, prev);
            }
        }
Ejemplo n.º 20
0
        void on_m_JoinChatButton_clicked()
        {
            Account selectedAccount = Gui.ShowAccountSelectMenu(m_JoinChatButton);

            if (selectedAccount != null)
            {
                JID    jid  = null;
                string nick = (!String.IsNullOrEmpty(mucNicknameLineEdit.Text)) ? mucNicknameLineEdit.Text : selectedAccount.ConferenceManager.DefaultNick;
                if (JID.TryParse(String.Format("{0}@{1}/{2}", mucRoomLineEdit.Text, mucServerLineEdit.Text, nick), out jid))
                {
                    if (!String.IsNullOrEmpty(jid.User) && !String.IsNullOrEmpty(jid.Server))
                    {
                        try {
                            selectedAccount.JoinMuc(jid, mucPasswordLineEdit.Text);
                        } catch (UserException ex) {
                            QMessageBox.Critical(this.TopLevelWidget(), "Synapse Error", ex.Message);
                        }
                    }
                    else
                    {
                        QMessageBox.Critical(null, "Synapse", "Invalid JID");
                    }
                }
                else
                {
                    QMessageBox.Critical(this.TopLevelWidget(), "Synapse Error", "Invalid conference room");
                }
            }
        }
Ejemplo n.º 21
0
        public void Test_Escape()
        {
            JID j = JID.Escape("d'artagnan", "gascon.fr", "elder");

            Assert.AreEqual(@"d\[email protected]/elder", j.ToString());
            j = JID.Escape("space cadet", "example.com", null);
            Assert.AreEqual(@"space\[email protected]", j.ToString());
            j = JID.Escape("call me \"ishmael\"", "example.com", null);
            Assert.AreEqual(@"call\20me\20\22ishmael\[email protected]", j.ToString());
            j = JID.Escape("at&t guy", "example.com", null);
            Assert.AreEqual(@"at\26t\[email protected]", j.ToString());
            j = JID.Escape("/.fanboy", "example.com", null);
            Assert.AreEqual(@"\[email protected]", j.ToString());
            j = JID.Escape("::foo::", "example.com", null);
            Assert.AreEqual(@"\3a\3afoo\3a\[email protected]", j.ToString());
            j = JID.Escape("<foo>", "example.com", null);
            Assert.AreEqual(@"\3cfoo\[email protected]", j.ToString());
            j = JID.Escape("user@host", "example.com", null);
            Assert.AreEqual(@"user\[email protected]", j.ToString());
            j = JID.Escape(@"c:\net", "example.com", null);
            Assert.AreEqual(@"c\3a\[email protected]", j.ToString());
            j = JID.Escape(@"c:\\net", "example.com", null);
            Assert.AreEqual(@"c\3a\5c\[email protected]", j.ToString());
            j = JID.Escape(@"c:\cool stuff", "example.com", null);
            Assert.AreEqual(@"c\3a\5ccool\[email protected]", j.ToString());
            j = JID.Escape(@"c:\5commas", "example.com", null);
            Assert.AreEqual(@"c\3a\[email protected]", j.ToString());
        }
Ejemplo n.º 22
0
        public void TestGroupChat()
        {
            XMPPClient ObjXmppClient = new XMPPClient();

            //initializing the xmpp client with credentials
            ObjXmppClient.JID            = "*****@*****.**";
            ObjXmppClient.Password       = "******";
            ObjXmppClient.Server         = "54.173.99.54";
            ObjXmppClient.AutoReconnect  = true;
            ObjXmppClient.RetrieveRoster = true;
            ObjXmppClient.PresenceStatus = new PresenceStatus()
            {
                PresenceType = PresenceType.available, IsOnline = true
            };
            ObjXmppClient.AutoAcceptPresenceSubscribe = true;
            ObjXmppClient.AttemptReconnectOnBadPing   = true;
            //
            XMPPConnection ObjXmppCon = new XMPPConnection(ObjXmppClient);

            ObjXmppCon = new XMPPConnection(ObjXmppClient);
            ObjXmppCon.Connect();
            ObjXmppClient.Connect();
            //muc manager test
            MucManager mucManager = new MucManager(ObjXmppClient);
            JID        roomJID    = "*****@*****.**";

            mucManager.EnterRoom(roomJID, "XMPPTestNickName");

            mucManager.SendGroupChat(roomJID, "test Chat");
        }
Ejemplo n.º 23
0
        public void HandleSvpnMsg(Element msg, JID from)
        {
            SvpnMsg request = msg as SvpnMsg;

            if (request == null)
            {
                return;
            }

            string[] parts = request.Data.Split(DELIM);
            string   jid   = from.User + "@" + from.Server;

            if (!_fingerprints.ContainsKey(parts[1]))
            {
                _fingerprints = _fingerprints.InsertIntoNew(parts[1], parts[0]);
            }

            if (!_addresses.ContainsKey(jid))
            {
                _addresses = _addresses.InsertIntoNew(parts[1], jid);
            }

            if (parts[2] == PacketTypes.Request.ToString() && _xmpp.JID != from)
            {
                string data = _data + DELIM + PacketTypes.Reply.ToString();
                _xmpp.SendTo(new SvpnMsg(_doc, data), from);
            }
        }
Ejemplo n.º 24
0
        public XmppTest(Livecoding.ChatRoom client)
        {
            Rooms     = new Dictionary <string, Room> ();
            IDManager = new IDManager();
            JID       = client.JID;
            Password  = client.Password;
            ressource = client.Resource;
            Nick      = JID.Split('@') [0];

            keepAliveTimer          = new System.Timers.Timer(1000 * 60);
            keepAliveTimer.Elapsed += KeepAliveTimer_Elapsed;
            messageTypes            = new Dictionary <string, XMPPMessage> ();
            iqMethods = new Dictionary <string, XMPPMessage> ();
            messageTypes.Add("open", XMPP_Open);
            messageTypes.Add("stream:features", XMPP_Features);
            messageTypes.Add("success", XMPP_Success);
            messageTypes.Add("iq", XMPP_IQ);
            messageTypes.Add("close", XMPP_Close);
            messageTypes.Add("message", XMPP_Message);
            messageTypes.Add("presence", XMPP_Presence);


            List <KeyValuePair <string, string> > customHeaders = new List <KeyValuePair <string, string> >();

            customHeaders.Add(new KeyValuePair <string, string>("Sec-WebSocket-Extensions", "permessage-deflate"));
            string origin    = "https://www.livecoding.tv";         //TODO:
            string UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)";

            uri    = "wss://www.livecoding.tv:443" + client.WebsocketURL;
            socket = new WebSocket(uri, "xmpp", HttpHelper.ConvertCookies(client.Session.Cookies), customHeaders, UserAgent, origin);
            socket.MessageReceived += Socket_MessageReceived;
            socket.Open();
            socket.Opened += Socket_Opened;
        }
Ejemplo n.º 25
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.º 26
0
        /// <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();
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Get the default configuration of the node.
        /// </summary>
        /// <param name="service">JID of the pub/sub service</param>
        /// <param name="callback">Callback.  Must not be null.  Will not be called back
        /// if there is an error, but instead OnError will be called.</param>
        /// <param name="state">State information to be passed back to callback</param>
        public void GetDefaults(JID service, IqCB callback, object state)
        {
            OwnerPubSubCommandIQ <OwnerDefault> iq = new OwnerPubSubCommandIQ <OwnerDefault>(m_stream.Document);

            iq.To   = service;
            iq.Type = IQType.get;
            BeginIQ(iq, OnDefaults, new IQTracker.TrackerData(callback, state, null, null));
        }
Ejemplo n.º 28
0
 /// <summary>
 /// Creates a new JID/Node combination.
 /// </summary>
 /// <param name="jid">JID to associate with JIDNode.</param>
 /// <param name="node">Node to associate with JIDNode.</param>
 public JIDNode(JID jid, string node)
 {
     this.m_jid = jid;
     if ((node != null) && (node != ""))
     {
         this.m_node = node;
     }
 }
Ejemplo n.º 29
0
        public void Deny(JID jid)
        {
            Presence reply = new Presence(m_stream.Document);

            reply.To   = jid;
            reply.Type = PresenceType.unsubscribed;
            Write(reply);
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Gets the currently-known version of a roster item for this JID.
 /// </summary>
 public Item this[JID jid]
 {
     get
     {
         lock (this)
             return((Item)m_items[jid]);
     }
 }
Ejemplo n.º 31
0
		public virtual Tag Initialize()
		{
#if DEBUG
			Manager.Events.LogMessage(this, LogType.Debug, "Initializing Base Processor");
#endif

            Id = Manager.Settings.Id;
            Password = Manager.Settings.Password;

			return null;
		}
Ejemplo n.º 32
0
        /// <summary>
        /// Remove a contact from the roster
        /// </summary>
        /// <param name="jid">Typically just a user@host JID</param>
        public void Remove(JID jid)
        {
/*
C: <iq from='[email protected]/balcony' type='set' id='delete_1'>
     <query xmlns='jabber:iq:roster'>
       <item jid='*****@*****.**' subscription='remove'/>
     </query>
   </iq>
 */
            RosterIQ iq = new RosterIQ(m_stream.Document);
            iq.Type = IQType.set;
            Roster r = iq.Instruction;
            Item item = r.AddItem();
            item.JID = jid;
            item.Subscription = Subscription.remove;
            m_stream.Write(iq);  // ignore response
        }
Ejemplo n.º 33
0
        private void m_stream_OnProtocol(object sender, System.Xml.XmlElement rp)
        {
            // There isn't always a from address.  iq:roster, for example.
            string af = rp.GetAttribute("from");
            if (af == "")
                return;
            JID from = new JID(af);
            if (from.Bare != (string)m_room)
                return;  // not for this room.

            switch (rp.LocalName)
            {
                case "presence":
                    Presence p = (Presence)rp;
                    if (p.Error != null)
                    {
                        m_state = STATE.error;
                        if (OnPresenceError != null)
                            OnPresenceError(this, p);
                        return;
                    }

                    Presence oldPresence = (m_participants[from] != null) ? ((RoomParticipant)m_participants[from]).Presence : null;

                    ParticipantCollection.Modification mod = ParticipantCollection.Modification.NONE;
                    RoomParticipant party = m_participants.Modify(p, out mod);

                    // if this is ours
                    if (p.From == m_jid)
                    {
                        switch (m_state)
                        {
                            case STATE.join:
                                OnJoinPresence(p);
                                break;
                            case STATE.leaving:
                                OnLeavePresence(p);
                                break;
                            case STATE.running:
                                if (p.Type == PresenceType.unavailable)
                                    OnLeavePresence(p);
                                else
                                    OnPresenceChange(this, party, oldPresence);
                                break;
                        }
                    }
                    else
                    {
                        switch (mod)
                        {
                            case ParticipantCollection.Modification.NONE:
                                if (OnParticipantPresenceChange != null)
                                    OnParticipantPresenceChange(this, party, oldPresence);
                                break;
                            case ParticipantCollection.Modification.JOIN:
                                if (OnParticipantJoin != null)
                                    OnParticipantJoin(this, party);
                                break;
                            case ParticipantCollection.Modification.LEAVE:
                                if (OnParticipantLeave != null)
                                    OnParticipantLeave(this, party);
                                break;
                        }
                    }
                    break;
                case "message":
                    Message m = (Message)rp;
                    if (m.Type == MessageType.groupchat)
                    {
                        if (m.Subject != null)
                        {
                            if (OnSubjectChange != null)
                                OnSubjectChange(this, m);
                            m_subject = m;
                        }
                        else if (m.From == m_jid)
                        {
                            if (OnSelfMessage != null)
                                OnSelfMessage(this, m);
                        }
                        else
                        {
                            if (OnRoomMessage != null)
                                OnRoomMessage(this, m);
                        }
                    }
                    else
                    {
                        if (m.From.Resource == null)
                        {
                            // room notification of some kind
                            if (OnAdminMessage != null)
                                OnAdminMessage(this, m);
                        }
                        else
                        {
                            if (OnPrivateMessage != null)
                                OnPrivateMessage(this, m);
                        }
                    }
                    break;
                case "iq":
                    if (OnIQ != null)
                        OnIQ(this, (IQ)rp);
                    break;
            }
        }
Ejemplo n.º 34
0
 /// <summary>
 /// Removes the room from the list.
 /// Should most often be called by the Room.Leave() method.
 /// If the room does not exist, no exception is thrown.
 /// </summary>
 /// <param name="roomAndNick">Room to remove.</param>
 public void RemoveRoom(JID roomAndNick)
 {
     m_rooms.Remove(roomAndNick);
 }
Ejemplo n.º 35
0
        /// <summary>
        /// Joins a conference room.
        /// </summary>
        /// <param name="roomAndNick">room@conference/nick, where "nick" is the desred nickname in the room.</param>
        /// <returns>
        /// If already joined, the existing room will be returned.
        /// If not, a Room object will be returned in the joining state.
        /// </returns>
        public Room GetRoom(JID roomAndNick)
        {
            if (roomAndNick == null)
                throw new ArgumentNullException("roomAndNick");

            if (roomAndNick.Resource == null)
                roomAndNick.Resource = DefaultNick;

            if (m_rooms.ContainsKey(roomAndNick))
                return m_rooms[roomAndNick];

            // If no resource specified, pick up the user's name from their JID
            if (roomAndNick.Resource == null)
                roomAndNick.Resource = m_stream.JID.User;

            Room r = new Room(this, roomAndNick);
            r.OnJoin += OnJoin;
            r.OnLeave += OnLeave;
            r.OnPresenceError += OnPresenceError;
            r.OnRoomConfig += OnRoomConfig;
            r.OnRoomMessage += OnRoomMessage;
            r.OnPrivateMessage += OnPrivateMessage;
            r.OnAdminMessage += OnAdminMessage;
            r.OnSelfMessage += OnSelfMessage;
            r.OnSubjectChange += OnSubjectChange;
            r.OnParticipantJoin += OnParticipantJoin;
            r.OnParticipantLeave += OnParticipantLeave;
            r.OnParticipantPresenceChange += OnParticipantPresenceChange;
            r.OnPresenceChange += OnPresenceChange;

            m_rooms[roomAndNick] = r;
            return r;
        }
Ejemplo n.º 36
0
 /// <summary>
 /// Remove the membership privileges of the given user
 /// </summary>
 /// <param name="jid">The bare jid of the user to revoke the membership of.</param>
 /// <param name="reason"></param>
 public void RevokeMembership(JID jid, string reason)
 {
     // Or "Dismember".
     ChangeAffiliation(jid, RoomAffiliation.none, reason);
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Ban a user from re-joining the room.  Must be an admin.
 /// </summary>
 /// <param name="jid">The bare JID of the user to ban</param>
 /// <param name="reason">The reason for the shunning</param>
 public void Ban(JID jid, string reason)
 {
     ChangeAffiliation(jid, RoomAffiliation.outcast, reason);
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Creates a new JID/Node combination.
 /// </summary>
 /// <param name="jid">JID to associate with JIDNode.</param>
 /// <param name="node">Node to associate with JIDNode.</param>
 public JIDNode(JID jid, string node)
 {
     this.m_jid = jid;
     if ((node != null) && (node != ""))
         this.m_node = node;
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Retrieves the child items associated with this node and JID,
 /// and then calls back on the handler.
 /// If the information is in the cache, handler gets
 /// called right now.
 /// </summary>
 /// <param name="jid">JID of Service to query.</param>
 /// <param name="node">Node on the service to interact with.</param>
 /// <param name="handler">Callback that gets called with the items.</param>
 /// <param name="state">Context to pass back to caller when complete</param>
 public void BeginGetItems(JID jid, string node, DiscoNodeHandler handler, object state)
 {
     BeginGetItems(GetNode(jid, node), handler, state);
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Retrieves the child items associated with this node,
 /// and then calls back on the handler.
 /// 
 /// If caching is specified, items already in the cache call the handler
 /// immediately.
 /// </summary>
 /// <param name="jid">JID of Service to query.</param>
 /// <param name="node">Node on the service to interact with.</param>
 /// <param name="handler">Callback that gets called with the items.</param>
 /// <param name="state">Context to pass back to caller when complete</param>
 /// <param name="cache">Should caching be performed on this request?</param>
 public void BeginGetItems(JID jid, string node, DiscoNodeHandler handler, object state, bool cache)
 {
     DiscoNode dn = cache ? GetNode(jid, node) : new DiscoNode(jid, node);
     BeginGetItems(dn, handler, state);
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Add a note to the bookmark list.
 /// </summary>
 /// <param name="jid"></param>
 /// <param name="text"></param>
 /// <returns></returns>
 public BookmarkNote AddNote(JID jid, string text)
 {
     BookmarkNote n = new BookmarkNote(this.OwnerDocument);
     n.JID = jid;
     n.Text = text;
     this.AddChild(n);
     return n;
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Add a conference room to the bookmark list
 /// </summary>
 /// <param name="jid"></param>
 /// <param name="name"></param>
 /// <param name="autoJoin"></param>
 /// <param name="nick"></param>
 /// <returns></returns>
 public BookmarkConference AddConference(JID jid, string name, bool autoJoin, string nick)
 {
     BookmarkConference c = new BookmarkConference(this.OwnerDocument);
     c.JID = jid;
     c.ConferenceName = name;
     c.AutoJoin = autoJoin;
     if (nick != null)
         c.Nick = nick;
     this.AddChild(c);
     return c;
 }
Ejemplo n.º 43
0
        /// <summary>
        /// Invite a user to join the room.
        /// </summary>
        /// <param name="invitee">The JID of the person to invite</param>
        /// <param name="reason">The reason for the invite, or null for none.</param>
        public void Invite(JID invitee, string reason)
        {
            if (m_state != STATE.running)
                throw new InvalidOperationException("Must be in running state to send invite: " + m_state.ToString());

            if (invitee == null)
                throw new ArgumentNullException("invitee");
            /*
            <message
                from='[email protected]/desktop'
                to='*****@*****.**'>
              <x xmlns='http://jabber.org/protocol/muc#user'>
                <invite to='*****@*****.**'>
                  <reason>
                    Hey Hecate, this is the place for all good witches!
                  </reason>
                </invite>
              </x>
            </message>
             */
            Message m = new Message(m_manager.Stream.Document);
            m.To = m_room;
            UserX x = new UserX(m_manager.Stream.Document);
            x.AddInvite(invitee, reason);
            m.AddChild(x);
            m_manager.Write(m);
        }
Ejemplo n.º 44
0
 /// <summary>
 /// Creates a disco node.
 /// </summary>
 /// <param name="jid">JID associated with this JIDNode.</param>
 /// <param name="node">node associated with this JIDNode.</param>
 public DiscoNode(JID jid, string node)
     : base(jid, node)
 {
 }
Ejemplo n.º 45
0
 /// <summary>
 /// Change the affiliation (long-term) with the room of a user, based on their real JID.
 /// </summary>
 /// <param name="jid">The bare JID of the user of which to change the affiliation</param>
 /// <param name="affiliation">The new affiliation</param>
 /// <param name="reason">The reason for the change</param>
 public void ChangeAffiliation(JID jid, RoomAffiliation affiliation, string reason)
 {
     if (m_state != STATE.running)
         throw new InvalidOperationException("Must be in running state to change affiliation: " + m_state.ToString());
     if (jid == null)
         throw new ArgumentNullException("jid");
     if (affiliation == RoomAffiliation.UNSPECIFIED)
         throw new ArgumentNullException("affiliation");
     /*
     <iq from='[email protected]/throne'
         id='ban1'
         to='*****@*****.**'
         type='set'>
       <query xmlns='http://jabber.org/protocol/muc#admin'>
         <item affiliation='outcast'
               jid='*****@*****.**'>
           <reason>Treason</reason>
         </item>
       </query>
     </iq>
      */
     RoomAdminIQ iq = new RoomAdminIQ(m_manager.Stream.Document);
     iq.To = m_room;
     iq.Type = IQType.set;
     AdminQuery query = iq.Instruction;
     AdminItem item = query.AddItem();
     item.JID = jid;
     item.Affiliation = affiliation;
     item.Reason = reason;
     m_manager.BeginIQ(iq, null, null);
 }
Ejemplo n.º 46
0
 /// <summary>
 /// Creates nodes and ensure that they are cached.
 /// </summary>
 /// <param name="jid">JID associated with DiscoNode.</param>
 /// <param name="node">Node associated with DiscoNode.</param>
 /// <returns>
 /// If DiscoNode exists, returns the found node.
 /// Otherwise it creates the node and return it.
 /// </returns>
 public DiscoNode GetNode(JID jid, string node)
 {
     lock (m_items)
     {
         string key = DiscoNode.GetKey(jid, node);
         DiscoNode n = (DiscoNode)m_items[key];
         if (n == null)
         {
             n = new DiscoNode(jid, node);
             m_items.Add(key, n);
         }
         return n;
     }
 }
Ejemplo n.º 47
0
 /// <summary>
 /// Make this user a member of the room.
 /// </summary>
 /// <param name="jid">The bare jid of the user to grant membership to.</param>
 /// <param name="reason"></param>
 public void GrantMembership(JID jid, string reason)
 {
     ChangeAffiliation(jid, RoomAffiliation.member, reason);
 }
Ejemplo n.º 48
0
 /// <summary>
 /// Creates nodes where only the JID is specified.
 /// </summary>
 /// <param name="jid">JID associated with DiscoNode.</param>
 /// <returns>
 /// If DiscoNode exists, returns the found node.
 /// Otherwise it creates the node and return it.
 /// </returns>
 public DiscoNode GetNode(JID jid)
 {
     return GetNode(jid, null);
 }
Ejemplo n.º 49
0
 /// <summary>
 /// Get a participant by their room@service/nick JID.
 /// </summary>
 /// <param name="nickJid">room@service/nick</param>
 /// <returns>Participant object</returns>
 public RoomParticipant this[JID nickJid]
 {
     get
     {
         return (RoomParticipant)m_hash[nickJid];
     }
 }
Ejemplo n.º 50
0
 /// <summary>
 /// Subscribes to a publish-subscribe node.
 /// </summary>
 /// <param name="service">Component that handles PubSub requests.</param>
 /// <param name="node">The node on the component that the client wants to interact with.</param>
 /// <param name="maxItems">Maximum number of items to retain.  First one to call Subscribe gets their value, for now.</param>
 /// <returns>
 /// The existing node will be returned if there is already a subscription.
 /// If the node does not exist, the PubSubNode object will be returned
 /// in a subscribing state.
 /// </returns>
 public PubSubNode GetNode(JID service, string node, int maxItems)
 {
     JIDNode jn = new JIDNode(service, node);
     PubSubNode n = null;
     if (m_nodes.TryGetValue(jn, out n))
         return n;
     n = new PubSubNode(Stream, service, node, maxItems);
     m_nodes[jn] = n;
     n.OnError += OnError;
     return n;
 }
Ejemplo n.º 51
0
 /// <summary>
 /// Determines whether or not the conference room is being managed
 /// by this ConferenceManager.
 /// </summary>
 /// <param name="roomAndNick">Room to look for.</param>
 /// <returns>True if the room is being managed.</returns>
 public bool HasRoom(JID roomAndNick)
 {
     return m_rooms.ContainsKey(roomAndNick);
 }
Ejemplo n.º 52
0
        ///<summary>
        /// Removes the publish-subscribe node from the manager and sends a delete
        /// node to the XMPP server.
        ///</summary>
        /// <param name="service">
        /// Component that handles PubSub requests.
        /// </param>
        /// <param name="node">
        /// The node on the component that the client wants to interact with.
        /// </param>
        /// <param name="errorHandler">
        /// Callback for any errors with the publish-subscribe node deletion.
        /// </param>
        public void RemoveNode(JID service, string node, bedrock.ExceptionHandler errorHandler)
        {
            JIDNode jn = new JIDNode(service, node);

            PubSubNode psNode = null;
            if (m_nodes.TryGetValue(jn, out psNode))
            {
                m_nodes.Remove(jn);
            }
            else
            {
                psNode = new PubSubNode(Stream, service, node, 10);
            }

            psNode.OnError += errorHandler;

            psNode.Delete();
        }
Ejemplo n.º 53
0
 /// <summary>
 /// Create.
 /// </summary>
 /// <param name="manager">The manager for this room.</param>
 /// <param name="roomAndNick">room@conference/nick, where "nick" is the desred nickname in the room.</param>
 internal Room(ConferenceManager manager, JID roomAndNick)
 {
     m_manager = manager;
     XmppStream stream = manager.Stream;
     m_jid = roomAndNick;
     m_room = new JID(m_jid.User, m_jid.Server, null);
     stream.OnProtocol += new Jabber.Protocol.ProtocolHandler(m_stream_OnProtocol);
     JabberClient jc = stream as JabberClient;
     if (jc != null)
         jc.OnAfterPresenceOut += new Jabber.Client.PresenceHandler(m_stream_OnAfterPresenceOut);
 }
Ejemplo n.º 54
0
 /// <summary>
 /// Get the default configuration of the node.
 /// </summary>
 /// <param name="service">JID of the pub/sub service</param>
 /// <param name="callback">Callback.  Must not be null.  Will not be called back 
 /// if there is an error, but instead OnError will be called.</param>
 /// <param name="state">State information to be passed back to callback</param>
 public void GetDefaults(JID service, IqCB callback, object state)
 {
     OwnerPubSubCommandIQ<OwnerDefault> iq = new OwnerPubSubCommandIQ<OwnerDefault>(m_stream.Document);
     iq.To = service;
     iq.Type = IQType.get;
     BeginIQ(iq, OnDefaults, new IQTracker.TrackerData(callback, state, null, null));
 }
Ejemplo n.º 55
0
 /// <summary>
 /// Gets the currently-known version of a roster item for this JID.
 /// </summary>
 public Item this[JID jid]
 {
     get
     {
         lock (this)
             return (Item) m_items[jid];
     }
 }
Ejemplo n.º 56
0
        /// <summary>
        /// Create a Node.  Next, call Create and/or Subscribe.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="jid"></param>
        /// <param name="node"></param>
        /// <param name="maxItems"></param>
        internal PubSubNode(XmppStream stream, JID jid, string node, int maxItems)
        {
            if (stream == null)
                throw new ArgumentException("must not be null", "stream");
            if (node == null)
                throw new ArgumentException("must not be null", "node");
            if (node == "")
                throw new ArgumentException("must not be empty", "node");

            m_stream = stream;
            m_jid = jid;
            m_node = node;
            m_items = new ItemList(this, maxItems);
        }
Ejemplo n.º 57
0
        /// <summary>
        /// Attempts to register a new user.  This will fire
        /// OnRegisterInfo to retrieve information about the
        /// new user, and OnRegistered when the registration
        /// is completed or failed.
        /// </summary>
        /// <param name="jid">The user to register.</param>
        public void Register(JID jid)
        {
            RegisterIQ iq = new RegisterIQ(Document);
            Register reg = iq.Instruction;
            iq.Type = IQType.Get;
            iq.To = jid.Server;

            reg.Username = jid.User;
            Tracker.BeginIQ(iq, OnGetRegister, jid);
        }
Ejemplo n.º 58
0
        /// <summary>
        /// Removes a contact from the roster.
        /// This will also remove the subscription for that contact being removed.
        /// </summary>
        /// <param name="to">The JID to remove</param>
        public void RemoveRosterItem(JID to)
        {
            Debug.Assert(to != null);

            /*
            <iq from='[email protected]/balcony' type='set' id='roster_4'>
              <query xmlns='jabber:iq:roster'>
            <item jid='*****@*****.**' subscription='remove'/>
              </query>
            </iq>
             */
            RosterIQ riq = new RosterIQ(Document) {Type = IQType.Set};
            Roster r = riq.Instruction;
            Item i = r.AddItem();
            i.JID = to;
            i.Subscription = Subscription.remove;
            Write(riq); // don't care about result.  we should get a iq/response and a roster push.
        }
Ejemplo n.º 59
0
        /// <summary>
        /// Sends a presence subscription request and updates the roster
        /// for a new roster contact.
        /// </summary>
        /// <param name="to">The JID of the contact (required)</param>
        /// <param name="nickname">The nickname to show for the contact.</param>
        /// <param name="groups">A list of groups to put the contact in.  May be null.  Hint: new string[] {"foo", "bar"}</param>
        public void Subscribe(JID to, string nickname, string[] groups)
        {
            Debug.Assert(to != null);

            RosterIQ riq = new RosterIQ(Document) {Type = IQType.Set};
            Roster r = riq.Instruction;
            Item i = r.AddItem();
            i.JID = to;
            if (nickname != null)
                i.Nickname = nickname;
            if (groups != null)
            {
                foreach (string g in groups)
                    i.AddGroup(g);
            }
            Write(riq); // don't care about result.  we should get a iq/response and a roster push.

            Presence pres = new Presence(Document) {To = to, Type = PresenceType.subscribe};
            Write(pres);
        }
Ejemplo n.º 60
0
 public UserPresenceManager(JID jid)
 {
     Debug.Assert(jid.Resource == null);
     m_jid = jid;
 }