private Element CreateNode(XmlNodeResult nd, Element parent) { string ens; if (nd.Prefix != null) { RemObjects.InternetPack.XMPP.Elements.Attribute at = nd.Attribute.FirstOrDefault(a => a.Prefix == "xmlns" && a.Name == nd.Prefix); if (at == null) { Element el = parent; ens = string.Empty; while (el != null) { RemObjects.InternetPack.XMPP.Elements.Attribute els = el.Attributes.Where(a => a.Prefix == "xmlns" && a.Name == nd.Prefix).FirstOrDefault(); if (els != null) { ens = els.Value; break; } el = el.Parent; } } else ens = at.Value; } else { RemObjects.InternetPack.XMPP.Elements.Attribute at = nd.Attribute.FirstOrDefault(a => a.Prefix == null && a.Name == "xmlns"); if (at == null) ens = string.Empty; else ens = at.Value; } Element res = null; switch (ens) { case Namespaces.ClientStreamNamespace: case Namespaces.ServerStreamNamespace: case "": if (ens == null && parent != null && parent.Type == ElementType.IQ && nd.Name == "error") res = new IQError(); else switch (nd.Name) { case "iq": res = new IQ(); break; case "presence": res = new Presence(); break; case "message": res = new Message(); break; } break; case Namespaces.StreamNamespace: switch (nd.Name) { case "stream": RemObjects.InternetPack.XMPP.Elements.Attribute att = nd.Attribute.FirstOrDefault(a => a.Prefix == null && a.Name == "xmlns"); if (att == null || att.Value == Namespaces.ClientStreamNamespace) res = new ClientStream(); else res = new ServerStream(); break; case "features": res = new StreamFeatures(); break; case "error": res = new StreamError(); break; } break; case Namespaces.StartTLSNamespace: switch (nd.Name) { case "starttls": res = new StartTLS(); break; case "failure": res = new StartTLSFailure(); break; case "proceed": res = new StartTLSProceed(); break; } break; case Namespaces.SaslNamespace: switch (nd.Name) { case "mechanisms": res = new Mechanisms(); break; case "auth": res = new SaslAuth(); break; case "challenge": res = new SaslChallenge(); break; case "response": res = new SaslResponse(); break; case "abort": res = new SaslAbort(); break; case "success": res = new SaslSuccess(); break; case "failure": res = new SaslFailure(); break; } break; } if (res == null) { res = new UnknownElement(); } else res.Attributes.Clear(); // default ones shouldn't be here during the reading process if (parent != null) { res.Parent = parent; if (parent != fServerRoot) parent.Elements.Add(res); } res.Prefix = nd.Prefix; res.Name = nd.Name; foreach (var el in nd.Attribute) res.Attributes.Add(el); return res; }
public override void ToString(StringBuilder builder, WriteOptions wm) { if (Lang == null) { Lang = "en-US"; } if (ErrorText == null) { switch (Error) { case StreamErrorKind.BadFormat: Text = "the entity has sent XML that cannot be processed"; break; case StreamErrorKind.BadNamespace: Text = "the entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix"; break; case StreamErrorKind.Conflict: Text = "the server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream."; break; case StreamErrorKind.ConnectionTimeout: Text = "the entity has not generated any traffic over the stream for some period of time"; break; case StreamErrorKind.HostGone: Text = "the value of the 'to' attribute provided by the initiating entity in the stream header corresponds to a hostname that is no longer hosted by the server."; break; case StreamErrorKind.HostUnknown: Text = "the value of the 'to' attribute provided by the initiating entity in the stream header does not correspond to a hostname that is hosted by the server."; break; case StreamErrorKind.ImproperAddressing: Text = "a stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value)."; break; case StreamErrorKind.InternalServerError: Text = "the server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream."; break; case StreamErrorKind.InvalidFrom: Text = "the JID or hostname provided in a 'from' address does not match an authorized JID or validated domain negotiated between servers via SASL or dialback, or between a client and a server via authentication and resource binding."; break; case StreamErrorKind.InvalidId: Text = "the stream ID or dialback ID is invalid or does not match an ID previously provided."; break; case StreamErrorKind.InvalidNamespace: Text = "the streams namespace name is something other than \"http://etherx.jabber.org/streams\" or the dialback namespace name is something other than \"jabber:server:dialback\""; break; case StreamErrorKind.InvalidXml: Text = "the entity has sent invalid XML over the stream to a server that performs validation"; break; case StreamErrorKind.NotAuthorized: Text = "the entity has attempted to send data before the stream has been authenticated, or otherwise is not authorized to perform an action related to stream negotiation; the receiving entity MUST NOT process the offending stanza before sending the stream error."; break; case StreamErrorKind.PolicyViolation: Text = "the entity has violated some local service policy"; break; case StreamErrorKind.RemoteConnectionFailed: Text = "the server is unable to properly connect to a remote entity that is required for authentication or authorization."; break; case StreamErrorKind.ResourceConstraint: Text = "the server lacks the system resources necessary to service the stream."; break; case StreamErrorKind.RestrictedXml: Text = "the entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character."; break; case StreamErrorKind.SeeOtherHost: Text = "the server will not provide service to the initiating entity but is redirecting traffic to another host"; break; case StreamErrorKind.SystemShutdown: Text = "the server is being shut down and all active streams are being closed"; break; case StreamErrorKind.UndefinedCondition: Text = "the error condition is not one of those defined by the other conditions in this list; this error condition SHOULD be used only in conjunction with an application-specific condition."; break; case StreamErrorKind.UnsupportedEncoding: Text = "the initiating entity has encoded the stream in an encoding that is not supported by the server."; break; case StreamErrorKind.UnsupportedStanzaType: Text = "the initiating entity has sent a first-level child of the stream that is not supported by the server."; break; case StreamErrorKind.UnsupportedVersion: Text = "the value of the 'version' attribute provided by the initiating entity in the stream header specifies a version of XMPP that is not supported by the server"; break; case StreamErrorKind.XmlNotWellFormed: Text = "the initiating entity has sent XML that is not well-formed as defined by [XML]."; break; default: Text = "unknown error"; break; } } if (Error != StreamErrorKind.Unknown) { for (int i = Elements.Count - 1; i >= 0; i--) { Element el = Elements[i]; if (el.NamespaceURI == NamespaceURI) { Elements.RemoveAt(i); } } UnknownElement wel = new UnknownElement(); wel.Name = Mapping[Error]; wel.Attributes.Add(new Attribute { Name = "xmlns", Value = Namespaces.XMPPStreamNamespace }); Elements.Add(wel); wel = new UnknownElement(); wel.Name = "text"; wel.Text = Text; wel.Attributes.Add(new Attribute { Name = "xmlns", Value = Namespaces.XMPPStreamNamespace }); wel.Attributes.Add(new Attribute { Prefix = "xml", Name = "lang", Value = Lang }); Elements.Add(wel); } base.ToString(builder, wm); }
public override void ToString(StringBuilder builder, WriteOptions wm) { if (Lang == null) Lang = "en-US"; if (ErrorText == null) { switch (Error) { case StreamErrorKind.BadFormat: Text = "the entity has sent XML that cannot be processed"; break; case StreamErrorKind.BadNamespace: Text = "the entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix"; break; case StreamErrorKind.Conflict: Text = "the server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream."; break; case StreamErrorKind.ConnectionTimeout: Text = "the entity has not generated any traffic over the stream for some period of time"; break; case StreamErrorKind.HostGone: Text = "the value of the 'to' attribute provided by the initiating entity in the stream header corresponds to a hostname that is no longer hosted by the server."; break; case StreamErrorKind.HostUnknown: Text = "the value of the 'to' attribute provided by the initiating entity in the stream header does not correspond to a hostname that is hosted by the server."; break; case StreamErrorKind.ImproperAddressing: Text = "a stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value)."; break; case StreamErrorKind.InternalServerError: Text = "the server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream."; break; case StreamErrorKind.InvalidFrom: Text = "the JID or hostname provided in a 'from' address does not match an authorized JID or validated domain negotiated between servers via SASL or dialback, or between a client and a server via authentication and resource binding."; break; case StreamErrorKind.InvalidId: Text = "the stream ID or dialback ID is invalid or does not match an ID previously provided."; break; case StreamErrorKind.InvalidNamespace: Text = "the streams namespace name is something other than \"http://etherx.jabber.org/streams\" or the dialback namespace name is something other than \"jabber:server:dialback\""; break; case StreamErrorKind.InvalidXml: Text = "the entity has sent invalid XML over the stream to a server that performs validation"; break; case StreamErrorKind.NotAuthorized: Text = "the entity has attempted to send data before the stream has been authenticated, or otherwise is not authorized to perform an action related to stream negotiation; the receiving entity MUST NOT process the offending stanza before sending the stream error."; break; case StreamErrorKind.PolicyViolation: Text = "the entity has violated some local service policy"; break; case StreamErrorKind.RemoteConnectionFailed: Text = "the server is unable to properly connect to a remote entity that is required for authentication or authorization."; break; case StreamErrorKind.ResourceConstraint: Text = "the server lacks the system resources necessary to service the stream."; break; case StreamErrorKind.RestrictedXml: Text = "the entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character."; break; case StreamErrorKind.SeeOtherHost: Text = "the server will not provide service to the initiating entity but is redirecting traffic to another host"; break; case StreamErrorKind.SystemShutdown: Text = "the server is being shut down and all active streams are being closed"; break; case StreamErrorKind.UndefinedCondition: Text = "the error condition is not one of those defined by the other conditions in this list; this error condition SHOULD be used only in conjunction with an application-specific condition."; break; case StreamErrorKind.UnsupportedEncoding: Text = "the initiating entity has encoded the stream in an encoding that is not supported by the server."; break; case StreamErrorKind.UnsupportedStanzaType: Text = "the initiating entity has sent a first-level child of the stream that is not supported by the server."; break; case StreamErrorKind.UnsupportedVersion: Text = "the value of the 'version' attribute provided by the initiating entity in the stream header specifies a version of XMPP that is not supported by the server"; break; case StreamErrorKind.XmlNotWellFormed: Text = "the initiating entity has sent XML that is not well-formed as defined by [XML]."; break; default: Text = "unknown error"; break; } } if (Error != StreamErrorKind.Unknown) { for (int i = Elements.Count - 1; i >= 0; i--) { Element el = Elements[i]; if (el.NamespaceURI == NamespaceURI) { Elements.RemoveAt(i); } } UnknownElement wel = new UnknownElement(); wel.Name = Mapping[Error]; wel.Attributes.Add(new Attribute { Name = "xmlns", Value = Namespaces.XMPPStreamNamespace }); Elements.Add(wel); wel = new UnknownElement(); wel.Name = "text"; wel.Text = Text; wel.Attributes.Add(new Attribute { Name = "xmlns", Value = Namespaces.XMPPStreamNamespace }); wel.Attributes.Add(new Attribute { Prefix = "xml", Name = "lang", Value = Lang }); Elements.Add(wel); } base.ToString(builder, wm); }