예제 #1
0
		public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
		{
			if (iq.HasTo && iq.To != iq.From) return XmppStanzaError.ToForbidden(iq);

			if (iq.Type == IqType.get) return GetRoster(stream, iq, context);
			else if (iq.Type == IqType.set) return SetRoster(stream, iq, context);
			else return null;
		}
예제 #2
0
        private bool Send(Stanza stanza)
        {
            if (stanza.To == null)
            {
                XmppStanzaError.ToForbidden(stanza);
            }
            XmppSession session = SessionManager.GetSession(stanza.To);

            if (session != null)
            {
                Sender.SendTo(session.Stream, stanza);
            }
            return(session != null);
        }
예제 #3
0
        private IQ SetVCard(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            if (iq.From != iq.To)
            {
                return(XmppStanzaError.ToForbidden(iq));
            }

            var answer = new IQ(IqType.result);

            answer.Id   = iq.Id;
            answer.To   = iq.From;
            answer.From = iq.To;
            context.StorageManager.VCardStorage.SetVCard(iq.To, iq.Vcard);
            answer.Vcard = iq.Vcard;
            return(answer);
        }
예제 #4
0
        public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            if (iq.Type != IqType.get || !iq.HasTo)
            {
                return(XmppStanzaError.ToNotAcceptable(iq));
            }

            var currSession = context.SessionManager.GetSession(iq.From);

            if (currSession == null || !currSession.Available)
            {
                return(XmppStanzaError.ToForbidden(iq));
            }

            double seconds = 0;//available

            if (iq.To.IsServer)
            {
                seconds = (DateTime.UtcNow - startedTime).TotalSeconds;
            }
            else
            {
                var session = context.SessionManager.GetSession(iq.To);
                if (session == null || !session.Available)
                {
                    var lastActivity = context.StorageManager.OfflineStorage.GetLastActivity(iq.To);
                    if (lastActivity != null)
                    {
                        seconds        = (DateTime.UtcNow - lastActivity.LogoutDateTime).TotalSeconds;
                        iq.Query.Value = lastActivity.Status;
                    }
                    else
                    {
                        return(XmppStanzaError.ToRecipientUnavailable(iq));
                    }
                }
            }

            ((Last)(iq.Query)).Seconds = (int)seconds;
            iq.Type = IqType.result;
            iq.SwitchDirection();
            return(iq);
        }
예제 #5
0
        public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            if (iq.HasTo && iq.To != iq.From)
            {
                return(XmppStanzaError.ToForbidden(iq));
            }

            if (iq.Type == IqType.get)
            {
                return(GetRoster(stream, iq, context));
            }
            else if (iq.Type == IqType.set)
            {
                return(SetRoster(stream, iq, context));
            }
            else
            {
                return(null);
            }
        }
예제 #6
0
        public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            if (iq.To != null && iq.From != iq.To)
            {
                return(XmppStanzaError.ToForbidden(iq));
            }

            if (iq.Type == IqType.get)
            {
                return(GetPrivate(stream, iq, context));
            }
            else if (iq.Type == IqType.set)
            {
                return(SetPrivate(stream, iq, context));
            }
            else
            {
                return(XmppStanzaError.ToBadRequest(iq));
            }
        }
예제 #7
0
        public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            //Admins iq

            //New member
            MucRoomMember member = Room.GetRealMember(iq.From);

            if (member != null)
            {
                if (iq.Query != null)
                {
                    if (iq.Query is Admin && (member.Affiliation == Affiliation.admin || member.Affiliation == Affiliation.owner))
                    {
                        Room.AdminCommand(iq, member);
                    }
                    else if (iq.Query is Owner && (member.Affiliation == Affiliation.owner))
                    {
                        Room.OwnerCommand(iq, member);
                    }
                    else
                    {
                        XmppStanzaError.ToForbidden(iq);
                    }
                }
                else
                {
                    XmppStanzaError.ToBadRequest(iq);
                }
            }
            else
            {
                XmppStanzaError.ToForbidden(iq);
            }
            if (!iq.Switched)
            {
                iq.SwitchDirection();
            }
            iq.From = Room.Jid;
            return(iq);
        }
        public override IQ HandleIQ(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            //Admins iq

            //New member
            MucRoomMember member = Room.GetRealMember(iq.From);

            if (member != null)
            {
                if (iq.Query != null)
                {
                    if (iq.Query is Admin && (member.Affiliation == Affiliation.admin || member.Affiliation == Affiliation.owner))
                    {
                        Room.AdminCommand(iq, member);
                    }
                    else if (iq.Query is Owner && (member.Affiliation == Affiliation.owner))
                    {
                        Room.OwnerCommand(iq, member);
                    }
                    else if (iq.Query is Core.protocol.x.tm.history.History && iq.Type == IqType.get)
                    {
                        Jid jid        = iq.To;
                        var mucStore   = new DbMucStore();
                        var properties = new Dictionary <string, string>(1)
                        {
                            { "connectionStringName", "core" }
                        };
                        mucStore.Configure(properties);

                        var history = (Core.protocol.x.tm.history.History)iq.Query;

                        foreach (var msg in mucStore.GetMucMessages(jid, history.Count, history.StartIndex))
                        {
                            if (msg == null)
                            {
                                continue;
                            }

                            history.AddChild(HistoryItem.FromMessage(msg));
                        }
                        iq.Type = IqType.result;
                        iq.SwitchDirection();
                        return(iq);
                    }
                    else
                    {
                        XmppStanzaError.ToForbidden(iq);
                    }
                }
                else
                {
                    XmppStanzaError.ToBadRequest(iq);
                }
            }
            else
            {
                XmppStanzaError.ToForbidden(iq);
            }
            if (!iq.Switched)
            {
                iq.SwitchDirection();
            }
            iq.From = Room.Jid;
            return(iq);
        }