context: /* --------------------------------------------------------------------------
   * Copyrights
   *
   * Portions created by or assigned to Cursive Systems, Inc. are
   * Copyright (c) 2002-2008 Cursive Systems, Inc.  All Rights Reserved.  Contact
   * information for Cursive Systems, Inc. is available at
   * http://www.cursive.net/.
   *
   * License
   *
   * Jabber-Net is licensed under the LGPL.
   * See LICENSE.txt for details.
   * --------------------------------------------------------------------------*/
  using System;
  using System.Xml;
  
  using bedrock.util;
  using jabber.protocol;
  
  namespace jabber.protocol.stream
  {
      /// <summary>
      /// These error conditions may be read by constrained clients. 
      /// They are used for connection manager problems, abstracting stream errors, 
      /// communication problems between the connection manager and the server, 
      /// and invalid client requests (binding syntax errors, possible attacks, etc.)
      /// </summary>
      [Dash]
      public enum ConditionType
      {
          /// <summary>
          ///  None specified
          /// </summary>
          UNSPECIFIED = -1,
          /// <summary>
          /// The target domain specified in the 'to' attribute or the target host or
          /// port specified in the 'route' attribute is no longer serviced by 
          /// the connection manager.
          /// </summary>
          host_gone,
          /// <summary>
          /// The target domain specified in the 'to' attribute or the target host
          /// or port specified in the 'route' attribute is unknown to the connection manager.
          /// </summary>
          host_unknown,
          /// <summary>
          /// The initialization element lacks a 'to' or 'route' attribute (or the 
          /// attribute has no value) but the connection manager requires one.
          /// </summary>
          improper_addressing,
          /// <summary>
          /// The connection manager has experienced an internal error that prevents 
          /// it from servicing the request.
          /// </summary>
          internal_server_error,
          /// <summary>
          /// The connection manager was unable to connect to, or unable to 
          /// connect securely to, or has lost its connection to, the server.
          /// </summary>
          remote_connection_failed,
          /// <summary>
          /// Encapsulates an error in the protocol being transported.
          /// </summary>
          remote_stream_error,
          /// <summary>
          /// The connection manager does not operate at this URI 
          /// (e.g., the connection manager accepts only SSL or TLS connections at 
          /// some https: URI rather than the http: URI requested by the client). 
          /// The client may try POSTing to the URI in the content of the <uri/> child element.
          /// </summary>
          see_other_uri,
          /// <summary>
          /// The connection manager is being shut down. All active HTTP sessions are
          /// being terminated. No new sessions can be created.
          /// </summary>
          system_shutdown,
          /// <summary>
          /// The error is not one of those defined herein; the connection manager SHOULD 
          /// include application-specific information in the content of the <body/> wrapper.
          /// </summary>
          undefined_condition
      };
  
      /// <summary>
      /// Is this an error or a termination?
      /// </summary>
      public enum BodyType
      {
          /// <summary>
          /// None specified
          /// </summary>
          UNSPECIFIED = -1,
          /// <summary>
          /// Error encapsulated in response
          /// </summary>
          error,
          /// <summary>
          /// Terminate the stream
          /// </summary>
          terminate
      };
      
      /// <summary>
      /// An HTTP Binding body element, which encapsulates stanzas.
      /// See XEP-124 and XEP-206 for details.
      /// </summary>
      [SVN(@"$Id$")]
      public class Body : Element
      {
          /// <summary>
          /// Create for outbound
          /// </summary>
          /// <param name="doc"></param>
          public Body(XmlDocument doc) : base("body", URI.HTTP_BIND, doc)
          {
          }
  
          /// <summary>
          /// Create inbound instance
          /// </summary>
          /// <param name="prefix"></param>
          /// <param name="qname"></param>
          /// <param name="doc"></param>
          public Body(string prefix, XmlQualifiedName qname, XmlDocument doc) :
              base(prefix, qname, doc)
          {
          }
  
          /// <summary>
          /// The child elements of the body.  0 or more stanzas.
          /// </summary>
          public ElementList Contents
          {
              get { return new ElementList(this); }
              set
              {
                  InnerXml = "";
                  foreach (XmlElement el in value)
                      AddChild(el);
              }
          }
  
          /// <summary>
          /// The content encodings that server can handle.
          /// </summary>
          public string[] Accept
          {
              get { return GetAttr("accept").Split(new char[] {','}); }
              set { SetAttr("accept", string.Join(",", value)); }
          }
  
          /// <summary>
          /// Acknowledgement of a given RID.
          /// </summary>
          public long Ack
          {
              get { return GetLongAttr("ack"); }
              set { SetLongAttr("ack", value); }
          }
  
          /// <summary>
          /// Stream ID for digest auth calculations
          /// </summary>
          public string AuthID
          {
              get { return GetAttr("authid"); }
              set { SetAttr("authid", value); }
          }
  
          /// <summary>
          /// The charsets supported by the server.  Almost always just UTF8, if it exists.
          /// </summary>
          public string[] Charsets
          {
              get { return GetAttr("accept").Split(new char[] {' '}); }
              set { SetAttr("accept", string.Join(" ", value)); }
          }
  
          /// <summary>
          /// The error condition, if this is an error.
          /// </summary>
          public ConditionType Condition
          {
              get { return GetEnumAttr<ConditionType>("condition"); }
              set { SetEnumAttr("condition", value); }
          }
  
          /// <summary>
          /// 
          /// </summary>
          public string Content
          {
              get { return GetAttr("content"); }
              set { SetAttr("content", value); }
          }
  
          /// <summary>
          /// A client MAY include a 'from' attribute to enable the 
          /// connection manager to forward its identity to the server.
          /// </summary>
          public string From
          {
              get { return GetAttr("from"); }
              set { SetAttr("from", value); }
          }
  
          /// <summary>
          /// This attribute specifies the maximum number of requests the connection manager 
          /// is allowed to keep waiting at any one time during the session. If the client 
          /// is not able to use HTTP Pipelining then this SHOULD be set to "1".
          /// </summary>
          public int Hold
          {
              get { return GetIntAttr("hold"); }
              set { SetIntAttr("hold", value); }
          }
  
          /// <summary>
          /// This attribute specifies the longest allowable inactivity period (in seconds). 
          /// This enables the client to ensure that the periods with no requests pending 
          /// are never too long (see Polling Sessions and Inactivity).
          /// </summary>
          public int Inactivity
          {
              get { return GetIntAttr("inactivity"); }
              set { SetIntAttr("inactivity", value); }
          }
          
          /// <summary>
          /// The client MUST set the 'key' attribute of all subsequent requests to the 
          /// value of the next key in the generated sequence (decrementing from K(n-1) 
          /// towards K(1) with each request sent).
          /// </summary>
          public string Key
          {
              get { return GetAttr("key"); }
              set { SetAttr("key", value); }
          }
          
          /// <summary>
          /// If the connection manager supports session pausing (see Inactivity) then it 
          /// SHOULD advertise that to the client by including a 'maxpause' attribute in 
          /// the session creation response element. The value of the attribute indicates 
          /// the maximum length of a temporary session pause (in seconds) that a client
          /// MAY request.
          /// </summary>
          public int MaxPause
          {
              get { return GetIntAttr("maxpause"); }
              set { SetIntAttr("maxpause", value); }
          }
          
          /// <summary>
          /// The client MUST set the 'newkey' attribute of the first request in the session to the value K(n).
          /// </summary>
          public string NewKey
          {
              get { return GetAttr("newkey"); }
              set { SetAttr("newkey", value); }
          }
          
          /// <summary>
          /// If a client encounters an exceptional temporary situation during which it 
          /// will be unable to send requests to the connection manager for a period of 
          /// time greater than the maximum inactivity period (e.g., while a runtime 
          /// environment changes from one web page to another), and if the connection 
          /// manager included a 'maxpause' attribute in its Session Creation Response,
          /// then the client MAY request a temporary increase to the maximum inactivity 
          /// period by including a 'pause' attribute in a request.
          /// </summary>
          public int Pause
          {
              get { return GetIntAttr("pause"); }
              set { SetIntAttr("pause", value); }
          }
          
          /// <summary>
          /// This attribute specifies the shortest allowable polling interval (in seconds). 
          /// This enables the client to not send empty request elements more often than desired.
          /// </summary>
          public int Polling
          {
              get { return GetIntAttr("polling"); }
  
gt:             set { SetIntAttr("polling", value); }