コード例 #1
0
        private IQ ProcessBind(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            if (iq.Type != IqType.set)
            {
                return(XmppStanzaError.ToBadRequest(iq));
            }

            var answer = new IQ(IqType.result);

            answer.Id = iq.Id;

            var bind     = (Bind)iq.Bind;
            var resource = !string.IsNullOrEmpty(bind.Resource) ? bind.Resource : stream.User;

            if (bind.TagName.Equals("bind", StringComparison.OrdinalIgnoreCase))
            {
                var jid = new Jid(stream.User, stream.Domain, resource);

                var session = context.SessionManager.GetSession(jid);
                if (session != null)
                {
                    if (session.Stream.Id != stream.Id)
                    {
                        context.Sender.SendToAndClose(session.Stream, XmppStreamError.Conflict);
                        answer.AddTag("newTalkWindow", "true");
                    }
                    else
                    {
                        return(XmppStanzaError.ToConflict(iq));
                    }
                }

                stream.BindResource(resource);
                context.SessionManager.AddSession(new XmppSession(jid, stream));
                answer.Bind = new Bind(jid);
            }
            else if (bind.TagName.Equals("unbind", StringComparison.OrdinalIgnoreCase))
            {
                if (!stream.Resources.Contains(resource))
                {
                    return(XmppStanzaError.ToNotFound(iq));
                }

                context.SessionManager.CloseSession(iq.From);
                stream.UnbindResource(resource);
                if (stream.Resources.Count == 0)
                {
                    context.Sender.CloseStream(stream);
                }
            }
            else
            {
                return(XmppStanzaError.ToBadRequest(iq));
            }
            if (stream.MultipleResources)
            {
                answer.To = iq.From;
            }
            return(answer);
        }
コード例 #2
0
        private IQ GetVCard(XmppStream stream, IQ iq, XmppHandlerContext context)
        {
            var answer = new IQ(IqType.result);

            answer.Id   = iq.Id;
            answer.To   = iq.From;
            answer.From = iq.To;

            answer.Vcard = iq.To.HasUser ?
                           context.StorageManager.VCardStorage.GetVCard(iq.To, iq.Id) :
                           GetServiceVcard(iq.To, context);

            if (answer.Vcard == null)
            {
                return(XmppStanzaError.ToNotFound(iq));
            }
            return(answer);
        }
コード例 #3
0
        public override void HandlePresence(XmppStream stream, Presence presence, XmppHandlerContext context)
        {
            var session = sessionManager.GetSession(presence.From);

            if (session == null)
            {
                context.Sender.SendTo(stream, XmppStanzaError.ToNotFound(presence));
                return;
            }

            if (presence.Type == PresenceType.available || presence.Type == PresenceType.invisible || presence.Type == PresenceType.unavailable)
            {
                sessionManager.SetSessionPresence(session, presence);
            }

            if (presence.HasTo && presence.To.ToString() != stream.Domain)
            {
                HandlePresence(presence, session);                //Presence to one of contacts
            }
            else
            {
                BroadcastPresence(presence);
            }
        }