Exemplo n.º 1
0
 public ChatServerMenuItem(JabberID jid, MultiUserChatForm parentForm)
     : base(jid.ToString())
 {
     base.Click +=new EventHandler(ChatServerMenuItem_Click);
     _myJID = jid;
     _myForm = parentForm;
 }
Exemplo n.º 2
0
        public Session getSession(JabberID jabberID)
        {
            String  jidString = jabberID.ToString();
            Session session   = null;

            try {
                session = jidIndex[jidString];
                return(session);
            } catch (Exception ex) {
                try {
                    List <Session> resources = userIndex[jabberID.User];
                    return(resources[0]);
                } catch (Exception e) {
                    return(null);
                }
            }
        }
Exemplo n.º 3
0
        public void joinGroup(Group group, Packet packet)
        {
            JabberID jid    = new JabberID(packet.To);
            String   sender = packet.From;

            group.jid2nick.Add(sender, jid.Resource);
            group.nick2jid.Add(jid.Resource, sender);
            updatePresence(group, packet);

            foreach (KeyValuePair <String, Packet> pair in group.jid2presence)
            {
                Packet p = pair.Value;
                if (p.From != jid.ToString())
                {
                    p.To = sender;
                    MessageHandler.deliverPacket(p);
                }
            }
            serverMessage(group, jid.Resource + " has joined the group");
        }
Exemplo n.º 4
0
        public void SetupJoinRoomCommand(JabberID server)
        {
            string room = null;

            if (server.IsBareJID())
            {
                int resourceLoc = RoomCommands.Join.Length + server.ToString().Length + 1;

                room = string.Concat(server.ToString(), "/", _sm.LocalUser.UserName);
                txtOutgoingMessage.Text = string.Concat(RoomCommands.Join, room);
                txtOutgoingMessage.Select(resourceLoc, _sm.LocalUser.UserName.Length);
            }
            else if (server.IsServerJID())
            {
                room = string.Concat("@", server.ToString(), "/", _sm.LocalUser.UserName);
                txtOutgoingMessage.Text = string.Concat(RoomCommands.Join, room);
                txtOutgoingMessage.Select(RoomCommands.Join.Length, 0);
            }
            else if (server.IsFullJID())
            {
                room = server.ToString();
                int resourceLoc = room.LastIndexOf("/") + 1;

                txtOutgoingMessage.Text = string.Concat(RoomCommands.Join, room);
                txtOutgoingMessage.Select(resourceLoc, server.Resource.Length);
            }

            txtOutgoingMessage.Focus();
        }
Exemplo n.º 5
0
        public void LeaveRoom(JabberID occupantJID)
        {
            if ( _rooms.Count == 0 ) return;

            ChatRoomTabPage t = (ChatRoomTabPage)_rooms[occupantJID.ToString().ToLower()];
            t.LeaveRoom();
        }
Exemplo n.º 6
0
        public void JoinRoom( JabberID occupantJID)
        {
            if ( _rooms.Contains(occupantJID.ToString().ToLower()) )
            {
                ChatRoomTabPage t = (ChatRoomTabPage)_rooms[occupantJID.ToString().ToLower()];
                tabRooms.SelectedTab = t;
            }
            else
            {
                ChatRoomTabPage t = new ChatRoomTabPage(occupantJID, this, _sm);
                tabRooms.TabPages.Add(t);
                _rooms.Add(occupantJID.ToString().ToLower(), t);

                lblNotInRoom.Visible = false;

                t.LeftRoom += new ChatRoomTabPage.LeftRoomDelegate(t_LeftRoom);
                t.ChangedNickName += new ChatRoomTabPage.ChangedNickNameDelegate(t_ChangedNickName);
                t.JoinRoom();
            }
        }
Exemplo n.º 7
0
        public void process(Session session)
        {
            //Assembly assem = Assembly.LoadFrom(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\SaxExpat.dll");
            //IXmlReader reader = SaxReaderFactory.CreateReader(assem, null);
            //reader.ContentHandler = this;
            this.session = session;
            //reader.Parse(new ReaderInputSource(session.getReader()));

            XmlReader reader = XmlReader.Create(session.Reader);


            JabberServer.output.WriteLine("JIH:server version");

            reader.MoveToContent();


            try {
                do
                {
                    switch (reader.Depth)
                    {
                    case 0:
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            if (reader.Name == "stream:stream")
                            {
                                Dictionary <String, String> atts = getAttributes(reader);
                                Packet openPacket = new Packet(null, reader.Name, reader.NamespaceURI, atts);
                                openPacket.Session = (session);
                                String from = atts["from"];
                                session.JID = (new JabberID(from));
                                packetQ.enqueue(openPacket);
                            }
                            else
                            {
                                throw new XmlException("Root node must be <stream:stream>");
                            }
                            break;

                        case XmlNodeType.EndElement:
                            Packet closePacket = new Packet("/stream:stream");
                            closePacket.Session = (session);
                            packetQ.enqueue(closePacket);
                            break;
                        }
                        break;

                    case 1:
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            Dictionary <String, String> atts = getAttributes(reader);
                            packet         = new Packet(null, reader.Name, reader.NamespaceURI, atts);
                            packet.Session = (session);
                            if (reader.IsEmptyElement)
                            {
                                goto case XmlNodeType.EndElement;
                            }
                            break;

                        case XmlNodeType.EndElement:
                            packetQ.enqueue(packet);
                            break;
                        }
                        break;

                    default:
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            Dictionary <String, String> atts = getAttributes(reader);
                            Packet child = new Packet(packet, reader.Name, reader.NamespaceURI, atts);
                            packet = child;
                            if (reader.IsEmptyElement)
                            {
                                goto case XmlNodeType.EndElement;
                            }
                            break;

                        case XmlNodeType.EndElement:
                            packet = packet.Parent;
                            break;

                        case XmlNodeType.Text:
                            packet.Children.Add(reader.Value);
                            break;
                        }
                        break;
                    }
                } while (reader.Read());
            } catch (Exception ex) {
                //JabberServer.output.WriteLine(ex.ToString());
                // Bilokakov problem so xml stream-ot
                // io-exception, invalid xml, zatvoren socket i sl.
                // treba da se napravi clean-up : zatvori stream </stream:stream>, zatvori socket, trgni Session object i sl.

                // Ne sekogas znaci greska : posle </stream:stream> se zatvara socket-ot i ne treba da se pravi nisto



                UserIndex userIndex = JabberServer.getUserIndex();
                if (!userIndex.containsSession(session))
                {
                    return;
                }
                //clean-up code (copied from CloseStreamHandler)
                try
                {
                    //      Log.trace("Closing session");
                    //Session session = packet.Session;

                    //session.Writer.Write("</stream:stream> ");
                    //session.Writer.Flush();

                    //notify other subscribers that user is unavailble
                    //by Marko
                    //begin
                    JabberID userid = session.getJID();

                    Packet unavailiblePacket = new Packet("presence");
                    unavailiblePacket.setFrom(userid.ToString());
                    unavailiblePacket.setAttribute("type", "unavailable");
                    userIndex.getUser(userid.User).getRoster().updateSubscribers(unavailiblePacket);
                    //it is not tested, but it should work
                    //end



                    //send groupchat presence unavailable & remove from groups
                    String jid = userid.ToString();

                    Packet presence = new Packet("presence");
                    presence.Type = "unavailable";
                    foreach (KeyValuePair <String, GroupChatManager.Group> kvp in GroupChatManager.Manager.groups)
                    {
                        GroupChatManager.Group group = kvp.Value;
                        try {
                            String nick = group.jid2nick[jid];                                       // test whether the user is in the group
                            presence.From = group.JabberID + "/" + nick;
                            GroupChatManager.Manager.removeUser(group, jid);                         // first remove then deliver so that the packet does not come back
                            GroupChatManager.Manager.deliverToGroup(group, presence);
                        } catch (Exception e) {
                        }
                    }
                    // end groupchar clean-up

                    //session.Socket.Close();
                    userIndex.removeSession(session);
                    //      Log.trace("Closed session");
                }
                catch (Exception e)
                {
                    //      Log.error("CloseStreamHandler: ",ex);
                    userIndex.removeSession(packet.Session);
                    //      Log.trace("Exception closed session");
                }
            }
        }
Exemplo n.º 8
0
 public void Remove(JabberID jid)
 {
     try { base.Remove(jid.ToString().ToLower()); }
     catch { }
 }
Exemplo n.º 9
0
 public MessageForm Item(JabberID jid)
 {
     return (MessageForm)base[jid.ToString().ToLower()];
 }
Exemplo n.º 10
0
 public bool Contains(JabberID jid)
 {
     return base.Contains(jid.ToString().ToLower());
 }
Exemplo n.º 11
0
 public MessageForm Add(JabberID RemoteUserJID, MessageForm msgWindow)
 {
     base.Add(RemoteUserJID.ToString().ToLower(), msgWindow);
     return msgWindow;
 }
Exemplo n.º 12
0
        }//update roster

        public void informSubscriber()
        {
            //needs to be checked!
            if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster) != null)
            {
                foreach (object obj in (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Keys)
                {
                    Subscriber sub = (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers[obj] as Subscriber;
                    if (sub.subscription.Equals("from") || sub.subscription.Equals("both")) //inform sender of his subscribers status!
                    {
                        JabberID myid = new JabberID(obj.ToString());                       //other's subscribers id
                        if (myid.Domain.Equals(Server.JabberServer.server_name))            //if from this server
                        {
                            //new code!



                            if (Server.JabberServer.getUserIndex().getUser(myid.User).getSessions().Values == null)
                            {
                                // if Server.JabberServer.getUserIndex().getUser(myid.User).getSessions()
                                //user is offline
                                Packet presencePacket = new Packet("presence");
                                presencePacket.From = myid.ToString();
                                presencePacket.To   = new JabberID(this.user + "@" + Server.JabberServer.server_name).ToString();
                                presencePacket.setAttribute("type", "unavailable");
                                MessageHandler.deliverPacket(presencePacket);
                            }// if (Server.JabberServer.getUserIndex().getUser(myid.User).getSessions().Values!=null)
                            else
                            {
                                foreach (Object obj2 in (Server.JabberServer.getUserIndex().getUser(myid.User).getSessions().Values))
                                {//for each active session
                                    Session sess = obj2 as Session;

                                    Packet presencePacket = new Packet("presence");
                                    presencePacket.From = myid.ToString();
                                    presencePacket.To   = new JabberID(this.user + "@" + Server.JabberServer.server_name).ToString();
                                    if (sess.getPresence().isAvailible())
                                    {
                                        presencePacket.setAttribute("type", "available");
                                        if (sess.getPresence().getShow() != null)
                                        {
                                            presencePacket.Children.Add(new Packet("show", sess.getPresence().getShow()));
                                        }


                                        if (sess.getPresence().getStatus() != null)
                                        {
                                            presencePacket.Children.Add(new Packet("status", sess.getPresence().getStatus()));
                                        }


                                        if (sess.getPresence().getPriority() != null)
                                        {
                                            presencePacket.Children.Add(new Packet("priority", sess.getPresence().getPriority()));
                                        }

                                        //other info may be added!
                                    }
                                    else
                                    {
                                        presencePacket.setAttribute("type", "unavailable");
                                    }
                                    MessageHandler.deliverPacket(presencePacket);
                                } //for each active session
                            }
                        }         //  if(myid.Domain.Equals(Server.JabberServer.server_name))
                        else
                        {
                            //generate probe for S2S communication!@TODO
                        }
                    } //if (sub.subscription.Equals("from") || sub.subscription.Equals("both"))
                }     //foreach (object obj in (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Keys)
            }         //if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster) != null)
        }
Exemplo n.º 13
0
        }//getPacket

        public void updateRoster(Packet packet)
        {
            //Extract the query packet
            Packet rosterQuery = packet.getFirstChild("query");

            rosterQuery.setAttribute("xmlns", "jabber:iq:roster");
            foreach (object rosterItems in rosterQuery.getChildren())
            {
                //for each <item> packet in the query
                Object child = rosterItems;
                if (child is Packet)
                {
                    Packet itemPacket = child as Packet;
                    String subJID     = itemPacket.getAttribute("jid");



                    //create Subscriber object if needed
                    //Subscriber sendersSubscriberItem = this.subscribers[subJID] as Subscriber;
                    if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster) == null)
                    {
                        Server.JabberServer.RosterHashtable[this.user] = new UserRoster();
                    }
                    Subscriber sub = (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers[subJID] as Subscriber;
                    if (sub == null)
                    {
                        sub = new Subscriber();
                        sub.subscription = "none";
                        sub.ask          = null;
                        (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Add(subJID, sub);
                    }

                    if (itemPacket.getAttribute("subscription") != null)
                    {
                        //signal to remove
                        if (itemPacket.getAttribute("subscription").Equals("remove"))
                        {
                            //remove from subscribers item
                            JabberID otherID = new JabberID(subJID);
                            (Server.JabberServer.RosterHashtable[this.user] as UserRoster).subscribers.Remove(otherID.ToString());
                            if ((Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.ContainsKey(subJID))
                            {
                                //remove <item> packet
                                (Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.Remove(subJID);
                            }

                            if ((Server.JabberServer.RosterHashtable[otherID.User] as UserRoster) == null)
                            {
                                Server.JabberServer.RosterHashtable[otherID.User] = new UserRoster();
                            }
                            //set only subscription=none from other item
                            sub = ((Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).subscribers[this.user + "@" + Server.JabberServer.server_name]) as Subscriber;
                            if (sub == null)
                            {
                                sub = new Subscriber();
                            }
                            sub.subscription = "none";
                            sub.ask          = null;
                            (Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).subscribers[this.user + "@" + Server.JabberServer.server_name] = sub;
                            //(Server.JabberServer.RosterHashtable[subJID] as UserRoster).subscribers.Add(subJID, sendersSubscriberItem);
                            //}
                            if ((Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).items.ContainsKey(this.user + "@" + Server.JabberServer.server_name))
                            {
                                //update <item> packet
                                //itemPacket.removeAttribute("subscription");

                                Packet mypacket = (Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).items[this.user + "@" + Server.JabberServer.server_name] as Packet;
                                mypacket.setAttribute("subscription", "none");
                                mypacket.setAttribute("ask", null);
                                (Server.JabberServer.RosterHashtable[otherID.User] as UserRoster).items[this.user + "@" + Server.JabberServer.server_name] = mypacket;
                            }
                        }
                    }
                    else
                    {
                        //update <item> with the subscriber info for roster push
                        itemPacket.setAttribute("subscription", sub.subscription);
                        itemPacket.setAttribute("ask", sub.ask);

                        //Packet test = items[subJID];
                        if (!(Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.ContainsKey(subJID))
                        {
                            //store updated <item> packet
                            (Server.JabberServer.RosterHashtable[this.user] as UserRoster).items.Add(subJID, itemPacket);
                        }
                        else
                        {
                            (Server.JabberServer.RosterHashtable[this.user] as UserRoster).items[subJID] = itemPacket;
                        }
                    }
                }
            }
            //Roster push
            packet.Type = "set";
            JabberID jidTo = packet.getSession().getJID();

            packet.To = jidTo.User + "@" + jidTo.Domain;
            packet.removeAttribute("from");
            //needs to be verified
            MessageHandler.deliverPacket(packet);
        }//update roster
Exemplo n.º 14
0
        private void HandleUserLeftRoom( JabberID user )
        {
            string leftMessage = string.Format("User {0} has left the room", user.Resource);

            _users.Remove(user.ToString().ToLower());
            BindList();

            AddMessageHistory(this.Room, leftMessage);
        }
Exemplo n.º 15
0
        public void notify(Packet packet)
        {
            try
            {
                //      Log.trace("Closing session");
                Session session = packet.Session;

                session.Writer.Write("</stream:stream> ");
                session.Writer.Flush();

                //notify other subscribers that user is unavailble
                //by Marko
                //begin
                JabberID userid = session.getJID();

                Packet unavailiblePacket = new Packet("presence");
                unavailiblePacket.setFrom(userid.ToString());
                unavailiblePacket.setAttribute("type", "unavailable");
                userIndex.getUser(userid.User).getRoster().updateSubscribers(unavailiblePacket);
                //it is not tested, but it should work
                //end

                //send groupchat presence unavailable & remove from groups
                String jid = userid.ToString();

                Packet presence = new Packet("presence");
                presence.Type = "unavailable";
                foreach (KeyValuePair <String, GroupChatManager.Group> kvp in GroupChatManager.Manager.groups)
                {
                    GroupChatManager.Group group = kvp.Value;
                    try
                    {
                        String nick = group.jid2nick[jid];               // test whether the user is in the group
                        presence.From = group.JabberID + "/" + nick;
                        GroupChatManager.Manager.removeUser(group, jid); // first remove then deliver so that the packet does not come back
                        GroupChatManager.Manager.deliverToGroup(group, presence);
                    }
                    catch (Exception ex)
                    {
                    }
                }
                // end groupchar clean-up



                //session.Socket.Close();
                userIndex.removeSession(session);
                //      Log.trace("Closed session");
            }
            catch (Exception ex)
            {
                JabberServer.output.WriteLine(ex.ToString());
                //      Log.error("CloseStreamHandler: ",ex);
//              packet.Session.Socket.Close();
//              userIndex.removeSession(packet.Session);
                //      Log.trace("Exception closed session");
            }
            finally
            {
                packet.Session.Socket.Close();
            }
        }