Пример #1
0
        private void ProcessAuthIQSet(XmppStream stream, AuthIq iq, XmppHandlerContext context)
        {
            if (string.IsNullOrEmpty(iq.Query.Username) || string.IsNullOrEmpty(iq.Query.Resource))
            {
                context.Sender.SendTo(stream, XmppStanzaError.ToNotAcceptable(iq));
                return;
            }

            bool authorized = false;

            if (!string.IsNullOrEmpty(iq.Query.Digest))
            {
                authorized = AuthDigest(iq.Query.Username, iq.Query.Digest, stream, context.UserManager);
            }
            if (!string.IsNullOrEmpty(iq.Query.Password))
            {
                authorized = AuthPlain(iq.Query.Username, iq.Query.Password, stream, context.UserManager);
            }
            if (authorized)
            {
                stream.Authenticate(iq.Query.Username);

                var answer = new IQ(IqType.result);
                answer.Id   = iq.Id;
                answer.To   = iq.From;
                answer.From = iq.To;
                context.Sender.SendTo(stream, answer);
            }
            else
            {
                context.Sender.SendTo(stream, XmppStanzaError.ToNotAuthorized(iq));
            }
        }
        private Element ValidateClientStanza(Stanza stanza, XmppStream stream)
        {
            if (!stream.Authenticated)
            {
                if (!(stanza is AuthIq) && (stanza is IQ && !(((IQ)stanza).Query is Register)))
                {
                    return(XmppStanzaError.ToNotAuthorized(stanza));
                }
            }

            //remove empty jids
            if (stanza.HasFrom && string.IsNullOrEmpty(stanza.From.ToString()))
            {
                stanza.From = null;
            }
            if (stanza.HasTo && string.IsNullOrEmpty(stanza.To.ToString()))
            {
                stanza.To = null;
            }

            //prep strings
            stanza.From = NodePrep(stanza.From);
            stanza.To   = NodePrep(stanza.To);

            if (!ValidateJid(stanza.From) || !ValidateJid(stanza.To))
            {
                return(XmppStanzaError.ToBadRequest(stanza));
            }

            if (stanza.HasFrom)
            {
                if (!stream.JidBinded(stanza.From))
                {
                    // return null if we have from in bind iq (for qutIM 0.3 client)
                    if (!(stanza is IQ) || ((IQ)stanza).Bind == null || ((IQ)stanza).Bind.Resource != stanza.From.Resource)
                    {
                        return(XmppStreamError.InvalidFrom);
                    }
                }
            }
            else
            {
                if (stream.MultipleResources)
                {
                    return(XmppStanzaError.ToConflict(stanza));
                }
                stanza.From = new Jid(string.Format("{0}@{1}/{2}", stream.User, stream.Domain, 0 < stream.Resources.Count ? stream.Resources[0] : null));
            }

            if (stanza is Message)
            {
                var message = (Message)stanza;
                if (message.Type == MessageType.chat && message.To == null)
                {
                    return(XmppStanzaError.ToRecipientUnavailable(stanza));
                }
            }
            return(null);
        }
Пример #3
0
        private void ProcessAuthIQSet(XmppStream stream, AuthIq iq, XmppHandlerContext context)
        {
            if (string.IsNullOrEmpty(iq.Query.Username) || string.IsNullOrEmpty(iq.Query.Resource))
            {
                context.Sender.SendTo(stream, XmppStanzaError.ToNotAcceptable(iq));
                return;
            }

            context.Sender.SendTo(stream, XmppStanzaError.ToNotAuthorized(iq));
        }