コード例 #1
0
        void OnStreamStart(object sender, Node node)
        {
            var e = (StreamElement)node;

            this._log.Debug("recv <<:\n{0}\n", e.StartTag());

            var stream = new StreamElement
            {
                Id        = this.Session.Id,
                From      = "warface",
                Version   = "1.0",
                Prefix    = "stream",
                Namespace = Namespaces.STREAM
            };

            this.Send(stream.StartTag().ToString().Replace("/>", ">"));

            if (e.To.Server != "warface")
            {
                var error = new Element("error", null, Namespaces.STREAM)
                {
                    Prefix = "stream"
                };
                error.C("host-unknown", ns: Namespaces.STREAMS);
                this.Send(error);
                return;
            }

            var features = new StreamFeatures {
                Prefix = "stream"
            };

            {
                if (!this.Session.IsAuthenticated)
                {
                    if (!this.Session.IsTlsStarted)
                    {
                        features.C("starttls", ns: Namespaces.TLS)
                        .C("required");
                    }

                    features.C("mechanisms", ns: Namespaces.SASL)
                    .C("mechanism", "PLAIN");
                }
                else
                {
                    features.C("bind", ns: Namespaces.BIND);
                    features.C("session", ns: Namespaces.SESSION);
                }
            }

            this.Send(features);
        }
コード例 #2
0
        public static StreamElement ToError(this StreamElement stream, StreamErrorCondition condition = StreamErrorCondition.UndefinedCondition, string text = null)
        {
            var tag = "";

            switch (condition)
            {
            case StreamErrorCondition.BadFormat: tag = "bad-format"; break;

            case StreamErrorCondition.BadNamespacePrefix: tag = "bad-namespace-prefix"; break;

            case StreamErrorCondition.Conflict: tag = "conflict"; break;

            case StreamErrorCondition.ConnectionTimeout: tag = "connection-timeout"; break;

            case StreamErrorCondition.HostGone: tag = "host-gone"; break;

            case StreamErrorCondition.HostUnknown: tag = "host-unknown"; break;

            case StreamErrorCondition.ImproperAddressing: tag = "improper-addressing"; break;

            case StreamErrorCondition.InternalServerError: tag = "internal-server-error"; break;

            case StreamErrorCondition.InvalidFrom: tag = "invalid-from"; break;

            case StreamErrorCondition.InvalidId: tag = "invalid-id"; break;

            case StreamErrorCondition.InvalidNamespace: tag = "invalid-namespace"; break;

            case StreamErrorCondition.InvalidXml: tag = "invalid-xml"; break;

            case StreamErrorCondition.NotAuthorized: tag = "not-authorized"; break;

            case StreamErrorCondition.PolicyViolation: tag = "policy-violation"; break;

            case StreamErrorCondition.RemoteConnectionFailed: tag = "remote-connection-failed"; break;

            case StreamErrorCondition.ResourceConstraint: tag = "resource-constraint"; break;

            case StreamErrorCondition.RestrictedXml: tag = "restricted-xml"; break;

            case StreamErrorCondition.SeeOtherHost: tag = "see-other-host"; break;

            case StreamErrorCondition.SystemShutdown: tag = "system-shutdown"; break;

            case StreamErrorCondition.UnknownCondition: tag = "unknown-condition"; break;

            case StreamErrorCondition.UnsupportedEncoding: tag = "unsupported-encoding"; break;

            case StreamErrorCondition.UnsupportedStanzaType: tag = "unsupported-stanza-type"; break;

            case StreamErrorCondition.UnsupportedVersion: tag = "unsupported-version"; break;

            case StreamErrorCondition.XmlNotWellFormed: tag = "xml-not-well-formed"; break;

            case StreamErrorCondition.UndefinedCondition:
            default: tag = "undefined-condition"; break;
            }

            stream.C(tag, ns: Namespaces.STANZAS);

            if (!string.IsNullOrEmpty(text))
            {
                stream.C("text", text, Namespaces.STANZAS);
            }

            return(stream);
        }