1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * Copyright (c) 2003-2012 by AG-Software * 3 * All Rights Reserved. * 4 * Contact information for AG-Software is available at http://www.ag-software.de * 5 * * 6 * Licence: * 7 * The agsXMPP SDK is released under a dual licence * 8 * agsXMPP can be used under either of two licences * 9 * * 10 * A commercial licence which is probably the most appropriate for commercial * 11 * corporate use and closed source projects. * 12 * * 13 * The GNU Public License (GPL) is probably most appropriate for inclusion in * 14 * other open source projects. * 15 * * 16 * See README.html for details. * 17 * * 18 * For general enquiries visit our website at: * 19 * http://www.ag-software.de * 20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 21 22 using System; 23 24 using agsXMPP.Xml.Dom; 25 26 namespace agsXMPP.protocol 27 { 28 /* 29 <stream:error> 30 <defined-condition xmlns='urn:ietf:params:xml:ns:xmpp-streams'/> 31 <text xmlns='urn:ietf:params:xml:ns:xmpp-streams' 32 xml:lang='langcode'> 33 OPTIONAL descriptive text 34 </text> 35 [OPTIONAL application-specific condition element] 36 </stream:error> 37 */ 38 39 /* 40 RFC 4.7.3. Defined Conditions 41 42 The following stream-level error conditions are defined: 43 44 * <bad-format/> -- the entity has sent XML that cannot be processed; this error MAY be used instead of the more specific XML-related errors, such as <bad-namespace-prefix/>, <invalid-xml/>, <restricted-xml/>, <unsupported-encoding/>, and <xml-not-well-formed/>, although the more specific errors are preferred. 45 * <bad-namespace-prefix/> -- the entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix (see XML Namespace Names and Prefixes (XML Namespace Names and Prefixes)). 46 * <conflict/> -- the server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream. 47 * <connection-timeout/> -- the entity has not generated any traffic over the stream for some period of time (configurable according to a local service policy). 48 * <host-gone/> -- 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. 49 * <host-unknown/> -- 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. 50 * <improper-addressing/> -- a stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value). 51 * <internal-server-error/> -- the server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream. 52 * <invalid-from/> -- 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. 53 * <invalid-id/> -- the stream ID or dialback ID is invalid or does not match an ID previously provided. 54 * <invalid-namespace/> -- 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" (see XML Namespace Names and Prefixes (XML Namespace Names and Prefixes)). 55 * <invalid-xml/> -- the entity has sent invalid XML over the stream to a server that performs validation (see Validation (Validation)). 56 * <not-authorized/> -- 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. 57 * <policy-violation/> -- the entity has violated some local service policy; the server MAY choose to specify the policy in the <text/> element or an application-specific condition element. 58 * <remote-connection-failed/> -- the server is unable to properly connect to a remote entity that is required for authentication or authorization. 59 * <resource-constraint/> -- the server lacks the system resources necessary to service the stream. 60 * <restricted-xml/> -- the entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character (see Restrictions (Restrictions)). 61 * <see-other-host/> -- the server will not provide service to the initiating entity but is redirecting traffic to another host; the server SHOULD specify the alternate hostname or IP address (which MUST be a valid domain identifier) as the XML character data of the <see-other-host/> element. 62 * <system-shutdown/> -- the server is being shut down and all active streams are being closed. 63 * <undefined-condition/> -- 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. 64 * <unsupported-encoding/> -- the initiating entity has encoded the stream in an encoding that is not supported by the server (see Character Encoding (Character Encoding)). 65 * <unsupported-stanza-type/> -- the initiating entity has sent a first-level child of the stream that is not supported by the server. 66 * <unsupported-version/> -- 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; the server MAY specify the version(s) it supports in the <text/> element. 67 * <xml-not-well-formed/> -- the initiating entity has sent XML that is not well-formed as defined by [XML] (Bray, T., Paoli, J., Sperberg-McQueen, C., and E. Maler, �Extensible Markup Language (XML) 1.0 (2nd ed),� October 2000.). 68 69 */ 70 71 public enum StreamErrorCondition 72 { 73 /// <summary> 74 /// unknown error condition 75 /// </summary> 76 UnknownCondition = -1, 77 78 79 /// <summary> 80 /// the entity has sent XML that cannot be processed; this error MAY be used instead of the more specific XML-related errors, such as <bad-namespace-prefix/>, <invalid-xml/>, <restricted-xml/>, <unsupported-encoding/>, and <xml-not-well-formed/>, although the more specific errors are preferred. 81 /// </summary> 82 BadFormat, 83 84 /// <summary> 85 /// the entity has sent a namespace prefix that is unsupported, or has sent no namespace prefix on an element that requires such a prefix (see XML Namespace Names and Prefixes (XML Namespace Names and Prefixes)). 86 /// </summary> 87 BadNamespacePrefix, 88 89 /// <summary> 90 /// the server is closing the active stream for this entity because a new stream has been initiated that conflicts with the existing stream. 91 /// </summary> 92 Conflict, 93 94 /// <summary> 95 /// the entity has not generated any traffic over the stream for some period of time (configurable according to a local service policy). 96 /// </summary> 97 ConnectionTimeout, 98 99 /// <summary> 100 /// 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. 101 /// </summary> 102 HostGone, 103 104 /// <summary> 105 /// 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. 106 /// </summary> 107 HostUnknown, 108 109 /// <summary> 110 /// a stanza sent between two servers lacks a 'to' or 'from' attribute (or the attribute has no value). 111 /// </summary> 112 ImproperAddressing, 113 114 /// <summary> 115 /// the server has experienced a misconfiguration or an otherwise-undefined internal error that prevents it from servicing the stream. 116 /// </summary> 117 InternalServerError, 118 119 /// <summary> 120 /// 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. 121 /// </summary> 122 InvalidFrom, 123 124 /// <summary> 125 /// the stream ID or dialback ID is invalid or does not match an ID previously provided. 126 /// </summary> 127 InvalidId, 128 129 /// <summary> 130 /// 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" (see XML Namespace Names and Prefixes (XML Namespace Names and Prefixes)). 131 /// </summary> 132 InvalidNamespace, 133 134 /// <summary> 135 /// the entity has sent invalid XML over the stream to a server that performs validation. 136 /// </summary> 137 InvalidXml, 138 139 /// <summary> 140 /// 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. 141 /// </summary> 142 NotAuthorized, 143 144 /// <summary> 145 /// the entity has violated some local service policy; the server MAY choose to specify the policy in the <text/> element or an application-specific condition element. 146 /// </summary> 147 PolicyViolation, 148 149 /// <summary> 150 /// the server is unable to properly connect to a remote entity that is required for authentication or authorization. 151 /// </summary> 152 RemoteConnectionFailed, 153 154 /// <summary> 155 /// the server lacks the system resources necessary to service the stream. 156 /// </summary> 157 ResourceConstraint, 158 159 /// <summary> 160 /// the entity has attempted to send restricted XML features such as a comment, processing instruction, DTD, entity reference, or unescaped character (see Restrictions (Restrictions)). 161 /// </summary> 162 RestrictedXml, 163 164 /// <summary> 165 /// the server will not provide service to the initiating entity but is redirecting traffic to another host; the server SHOULD specify the alternate hostname or IP address (which MUST be a valid domain identifier) as the XML character data of the <see-other-host/> element. 166 /// </summary> 167 SeeOtherHost, 168 169 /// <summary> 170 /// the server is being shut down and all active streams are being closed. 171 /// </summary> 172 SystemShutdown, 173 174 /// <summary> 175 /// 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. 176 /// </summary> 177 UndefinedCondition, 178 179 /// <summary> 180 /// the initiating entity has encoded the stream in an encoding that is not supported by the server. 181 /// </summary> 182 UnsupportedEncoding, 183 184 /// <summary> 185 /// the initiating entity has sent a first-level child of the stream that is not supported by the server. 186 /// </summary> 187 UnsupportedStanzaType, 188 189 /// <summary> 190 /// 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; the server MAY specify the version(s) it supports in the <text/> element. 191 /// </summary> 192 UnsupportedVersion, 193 194 /// <summary> 195 /// the initiating entity has sent XML that is not well-formed as defined by the XML specs. 196 /// </summary> 197 XmlNotWellFormed 198 } 199 200 201 // <stream:error>Invalid handshake</stream:error> 202 // <stream:error>Socket override by another connection.</stream:error> 203 204 /// <summary> 205 /// Stream Errors <stream:error> 206 /// </summary> 207 public class Error : Element 208 { Error()209 public Error() 210 { 211 this.TagName = "error"; 212 this.Namespace = Uri.STREAM; 213 } 214 Error(StreamErrorCondition condition)215 public Error(StreamErrorCondition condition) : this() 216 { 217 this.Condition = condition; 218 } 219 220 /* 221 public Error(string msg) : this() 222 { 223 Message = msg; 224 } 225 226 /// <summary> 227 /// The error Description 228 /// </summary> 229 public string Message 230 { 231 get { return this.Value; } 232 set { this.Value = value; } 233 } 234 */ 235 236 public StreamErrorCondition Condition 237 { 238 get 239 { 240 if (HasTag("bad-format")) 241 return StreamErrorCondition.BadFormat; 242 else if (HasTag("bad-namespace-prefix")) 243 return StreamErrorCondition.BadNamespacePrefix; 244 else if (HasTag("conflict")) 245 return StreamErrorCondition.Conflict; 246 else if (HasTag("connection-timeout")) 247 return StreamErrorCondition.ConnectionTimeout; 248 else if (HasTag("host-gone")) 249 return StreamErrorCondition.HostGone; 250 else if (HasTag("host-unknown")) 251 return StreamErrorCondition.HostUnknown; 252 else if (HasTag("improper-addressing")) 253 return StreamErrorCondition.ImproperAddressing; 254 else if (HasTag("internal-server-error")) 255 return StreamErrorCondition.InternalServerError; 256 else if (HasTag("invalid-from")) 257 return StreamErrorCondition.InvalidFrom; 258 else if (HasTag("invalid-id")) 259 return StreamErrorCondition.InvalidId; 260 else if (HasTag("invalid-namespace")) 261 return StreamErrorCondition.InvalidNamespace; 262 else if (HasTag("invalid-xml")) 263 return StreamErrorCondition.InvalidXml; 264 else if (HasTag("not-authorized")) 265 return StreamErrorCondition.NotAuthorized; 266 else if (HasTag("policy-violation")) 267 return StreamErrorCondition.PolicyViolation; 268 else if (HasTag("remote-connection-failed")) 269 return StreamErrorCondition.RemoteConnectionFailed; 270 else if (HasTag("resource-constraint")) 271 return StreamErrorCondition.ResourceConstraint; 272 else if (HasTag("restricted-xml")) 273 return StreamErrorCondition.RestrictedXml; 274 else if (HasTag("see-other-host")) 275 return StreamErrorCondition.SeeOtherHost; 276 else if (HasTag("system-shutdown")) 277 return StreamErrorCondition.SystemShutdown; 278 else if (HasTag("undefined-condition")) 279 return StreamErrorCondition.UndefinedCondition; 280 else if (HasTag("unsupported-encoding")) 281 return StreamErrorCondition.UnsupportedEncoding; 282 else if (HasTag("unsupported-stanza-type")) 283 return StreamErrorCondition.UnsupportedStanzaType; 284 else if (HasTag("unsupported-version")) 285 return StreamErrorCondition.UnsupportedVersion; 286 else if (HasTag("xml-not-well-formed")) 287 return StreamErrorCondition.XmlNotWellFormed; 288 else 289 return StreamErrorCondition.UnknownCondition; 290 } 291 292 set 293 { 294 switch (value) 295 { 296 case StreamErrorCondition.BadFormat: 297 SetTag("bad-format", "", Uri.STREAMS); 298 break; 299 case StreamErrorCondition.BadNamespacePrefix: 300 SetTag("bad-namespace-prefix", "", Uri.STREAMS); 301 break; 302 case StreamErrorCondition.Conflict: 303 SetTag("conflict", "", Uri.STREAMS); 304 break; 305 case StreamErrorCondition.ConnectionTimeout: 306 SetTag("connection-timeout", "", Uri.STREAMS); 307 break; 308 case StreamErrorCondition.HostGone: 309 SetTag("host-gone", "", Uri.STREAMS); 310 break; 311 case StreamErrorCondition.HostUnknown: 312 SetTag("host-unknown", "", Uri.STREAMS); 313 break; 314 case StreamErrorCondition.ImproperAddressing: 315 SetTag("improper-addressing", "", Uri.STREAMS); 316 break; 317 case StreamErrorCondition.InternalServerError: 318 SetTag("internal-server-error", "", Uri.STREAMS); 319 break; 320 case StreamErrorCondition.InvalidFrom: 321 SetTag("invalid-from", "", Uri.STREAMS); 322 break; 323 case StreamErrorCondition.InvalidId: 324 SetTag("invalid-id", "", Uri.STREAMS); 325 break; 326 case StreamErrorCondition.InvalidNamespace: 327 SetTag("invalid-namespace", "", Uri.STREAMS); 328 break; 329 case StreamErrorCondition.InvalidXml: 330 SetTag("invalid-xml", "", Uri.STREAMS); 331 break; 332 case StreamErrorCondition.NotAuthorized: 333 SetTag("not-authorized", "", Uri.STREAMS); 334 break; 335 case StreamErrorCondition.PolicyViolation: 336 SetTag("policy-violation", "", Uri.STREAMS); 337 break; 338 case StreamErrorCondition.RemoteConnectionFailed: 339 SetTag("remote-connection-failed", "", Uri.STREAMS); 340 break; 341 case StreamErrorCondition.ResourceConstraint: 342 SetTag("resource-constraint", "", Uri.STREAMS); 343 break; 344 case StreamErrorCondition.RestrictedXml: 345 SetTag("restricted-xml", "", Uri.STREAMS); 346 break; 347 case StreamErrorCondition.SeeOtherHost: 348 SetTag("see-other-host", "", Uri.STREAMS); 349 break; 350 case StreamErrorCondition.SystemShutdown: 351 SetTag("system-shutdown", "", Uri.STREAMS); 352 break; 353 case StreamErrorCondition.UndefinedCondition: 354 SetTag("undefined-condition", "", Uri.STREAMS); 355 break; 356 case StreamErrorCondition.UnsupportedEncoding: 357 SetTag("unsupported-encoding", "", Uri.STREAMS); 358 break; 359 case StreamErrorCondition.UnsupportedStanzaType: 360 SetTag("unsupported-stanza-type", "", Uri.STREAMS); 361 break; 362 case StreamErrorCondition.UnsupportedVersion: 363 SetTag("unsupported-version", "", Uri.STREAMS); 364 break; 365 case StreamErrorCondition.XmlNotWellFormed: 366 SetTag("xml-not-well-formed", "", Uri.STREAMS); 367 break; 368 default: 369 return; 370 371 } 372 } 373 } 374 375 /// <summary> 376 /// <para> 377 /// The <text/> element is OPTIONAL. If included, it SHOULD be used only to provide descriptive or diagnostic information 378 /// that supplements the meaning of a defined condition or application-specific condition. 379 /// </para> 380 /// <para> 381 /// It SHOULD NOT be interpreted programmatically by an application. 382 /// It SHOULD NOT be used as the error message presented to a user, but MAY be shown in addition to the error message 383 /// associated with the included condition element (or elements). 384 /// </para> 385 /// </summary> 386 public string Text 387 { 388 get { return GetTag("text"); } 389 set 390 { 391 SetTag("text", value, Uri.STREAMS); 392 } 393 } 394 395 } 396 } 397