Пример #1
0
        public XmppHandlerResult ProcessElement(BindIq element, XmppSession session, XmppHandlerContext context)
        {
            if (element.Query.TagName.Equals("bind", StringComparison.OrdinalIgnoreCase))
            {
                if (session.Binded)
                {
                    return(Error(session, ErrorCondition.Conflict, element));
                }

                session.Bind(!string.IsNullOrEmpty(element.Query.Resource) ? element.Query.Resource : session.Jid.User);
                element.From  = element.To = null;
                element.Query = new Bind(session.Jid);
                var result = Component(Send(session, element.ToResult()));
                foreach (var s in context.Sessions.GetSessions(session.Jid))
                {
                    if (!session.Equals(s))
                    {
                        result.Add(Close(s));
                    }
                }
                return(result);
            }
            else
            {
                var resource = element.Query.Resource;
                return(session.Jid.Resource == resource?Close(session) : Error(session, ErrorCondition.ItemNotFound, element));
            }
        }
Пример #2
0
        public XmppHandlerResult ProcessElement(Handshake element, XmppSession session, XmppHandlerContext context)
        {
            var test = new Handshake(secret, session.AuthData as string);

            if (element.Value != test.Value)
            {
                return(Error(session, StreamErrorCondition.NotAuthorized));
            }

            session.Authenticate(null);
            session.Bind(null);
            return(Send(session, new Handshake()));
        }