stanzaerrors.cs

来自「语音视频功能 里面实现了基本的QQ与语音对话」· CS 代码 · 共 327 行

CS
327
字号
using System;
using System.Reflection;
using System.Xml.Serialization;

using gowk.core.packets;

namespace gowk.core.packets.errors
{
	[System.Serializable]
	public class Error
	{
		string text,type;
		int code;
		public Error()
		{
			this.type=ErrorTypes.Cancel;
		}
		public Error(string type)
		{
			this.type=type;
		}
		[System.Xml.Serialization.XmlAttribute("type")]
		public string Type
		{
			get{return this.type;}
			set{this.type=value;}
		}
		[System.Xml.Serialization.XmlElement("text",Namespace=Namespace.STANZAS)]
		public string Text
		{
			get{return this.text;}
			set{this.text=value;}
		}
		[System.Xml.Serialization.XmlAttribute("code")]
		public int Code
		{
			get{return this.code;}
			set{this.code=value;}
		}
	}
	[System.Serializable]
	public class StanzaError:Error
	{
	/*	string text,type;
		public StanzaError()
		{
			this.type=ErrorTypes.Cancel;
		}
		public StanzaError(string type)
		{
			this.type=type;
		}
		[System.Xml.Serialization.XmlAttribute("type")]
		public string Type
		{
			get{return this.type;}
			set{this.type=value;}
		}
		[System.Xml.Serialization.XmlElement("text",Namespace=Namespace.STANZAS)]
		public string Text
		{
			get{return this.text;}
			set{this.text=value;}
		}*/
		
		public BadRequest BadRequest;

		public Confict Confict;

		public FeatureNotImplemented FeatureNotImplemented;

		public Forbidden Forbidden;

		public Gone Gone;

		public InternalServerError InternalServerError;

		public ItemNotFound ItemNotFound;

		[System.Xml.Serialization.XmlElement("jid-malformed")]
		public JidMalformed JidMalformed;

		public NotAcceptable NotAcceptable;

		public NotAllowed NotAllowed;

		public NotAuthorized NotAuthorized;

		public PaymentRequired PaymentRequired;

		public RecipientUnavailable RecipientUnavailable;

		public Redirect Redirect;

		public RegistrationRequired RegistrationRequired;

		public RemoteServerNotFound RemoteServerNotFound;

		public RemoteServerTimeOut RemoteServerTimeOut;

		public ResourceConstraint ResourceConstraint;

		[System.Xml.Serialization.XmlElement("service-unavailable")]
		public ServiceUnavailable ServiceUnavailable;

		public SubscriptionRequired SubscriptionRequired;

		public UndefinedCondition UndefinedCondition;

		public UnexpectedRequest UnexpectedRequest;

		public StanzaErrorConditionBase GetErrorCondition()
		{
			FieldInfo[] fis=this.GetType().GetFields();
			foreach(FieldInfo fi in fis)
			{
				if(fi.FieldType.IsSubclassOf(typeof(StanzaErrorConditionBase)))
				{
					object value=fi.GetValue(this);
					if(value!=null) return(StanzaErrorConditionBase)value; 
				}
			}
			return null;
		}
	}
	public abstract class StanzaErrorConditionBase
	{
		public StanzaErrorConditionBase(string type)
		{
			this.Type=type;
		}
		[System.NonSerialized]
		public string Type;
	}
	[System.Xml.Serialization.XmlRoot("bad-request")]
	public class BadRequest:StanzaErrorConditionBase{public BadRequest():base(ErrorTypes.Modify){}}

	[System.Xml.Serialization.XmlRoot("conflict")]
	public class Confict:StanzaErrorConditionBase{public Confict():base(ErrorTypes.Cancel){}}

	[System.Xml.Serialization.XmlRoot("feature-not-implemented")]
	public class FeatureNotImplemented:StanzaErrorConditionBase{public FeatureNotImplemented():base(ErrorTypes.Cancel){}}

	[System.Xml.Serialization.XmlRoot("forbidden")]
	public class Forbidden:StanzaErrorConditionBase{public Forbidden():base(ErrorTypes.Auth){}}

	[System.Xml.Serialization.XmlRoot("gone")]
	public class Gone:StanzaErrorConditionBase{public Gone():base(ErrorTypes.Modify){}}

	[System.Xml.Serialization.XmlRoot("internal-server-error")]
	public class InternalServerError:StanzaErrorConditionBase{public InternalServerError():base(ErrorTypes.Wait){}}

	[System.Xml.Serialization.XmlRoot("item-not-found")]
	public class ItemNotFound:StanzaErrorConditionBase{public ItemNotFound():base(ErrorTypes.Cancel){}}

	[System.Xml.Serialization.XmlRoot("jid-malformed")]
	public class JidMalformed:StanzaErrorConditionBase{public JidMalformed():base(ErrorTypes.Modify){}}

	[System.Xml.Serialization.XmlRoot("not-acceptable")]
	public class NotAcceptable:StanzaErrorConditionBase{public NotAcceptable():base(ErrorTypes.Modify){}}

	[System.Xml.Serialization.XmlRoot("not-allowed")]
	public class NotAllowed:StanzaErrorConditionBase{public NotAllowed():base(ErrorTypes.Cancel){}}

	[System.Xml.Serialization.XmlRoot("not-authorized")]
	public class NotAuthorized:StanzaErrorConditionBase{public NotAuthorized():base(ErrorTypes.Auth){}}

	[System.Xml.Serialization.XmlRoot("payment-required")]
	public class PaymentRequired:StanzaErrorConditionBase{public PaymentRequired():base(ErrorTypes.Auth){}}

	[System.Xml.Serialization.XmlRoot("recipient-unavailable")]
	public class RecipientUnavailable:StanzaErrorConditionBase{public RecipientUnavailable():base(ErrorTypes.Wait){}}

	[System.Xml.Serialization.XmlRoot("redirect")]
	public class Redirect:StanzaErrorConditionBase{public Redirect():base(ErrorTypes.Modify){}public string redirect;}//

	[System.Xml.Serialization.XmlRoot("registration-required")]
	public class RegistrationRequired:StanzaErrorConditionBase{public RegistrationRequired():base(ErrorTypes.Auth){}}

	[System.Xml.Serialization.XmlRoot("remote-server-not-found")]
	public class RemoteServerNotFound:StanzaErrorConditionBase{public RemoteServerNotFound():base(ErrorTypes.Cancel){}}

	[System.Xml.Serialization.XmlRoot("remote-server-timeout")]
	public class RemoteServerTimeOut:StanzaErrorConditionBase{public RemoteServerTimeOut():base(ErrorTypes.Wait){}}

	[System.Xml.Serialization.XmlRoot("resource-constraint")]
	public class ResourceConstraint:StanzaErrorConditionBase{public ResourceConstraint():base(ErrorTypes.Wait){}}

	[System.Xml.Serialization.XmlRoot("service-unavailable")]
	public class ServiceUnavailable:StanzaErrorConditionBase{public ServiceUnavailable():base(ErrorTypes.Cancel){}}

	[System.Xml.Serialization.XmlRoot("subscription-required/")]
	public class SubscriptionRequired:StanzaErrorConditionBase{public SubscriptionRequired():base(ErrorTypes.Auth){}}

	[System.Xml.Serialization.XmlRoot("undefined-condition")]
	public class UndefinedCondition:StanzaErrorConditionBase{public UndefinedCondition():base(ErrorTypes.Cancel){}}

	[System.Xml.Serialization.XmlRoot("nexpected-request")]
	public class UnexpectedRequest:StanzaErrorConditionBase{public UnexpectedRequest():base(ErrorTypes.Wait){}}
	/*
    o  <bad-request/> -- the sender has sent XML that is malformed or
      that cannot be processed (e.g., an IQ stanza that includes an
      unrecognized value of the 'type' attribute); the associated error
      type SHOULD be "modify".

   o  <conflict/> -- access cannot be granted because an existing
      resource or session exists with the same name or address; the
      associated error type SHOULD be "cancel".

   o  <feature-not-implemented/> -- the feature requested is not
      implemented by the recipient or server and therefore cannot be
      processed; the associated error type SHOULD be "cancel".

   o  <forbidden/> -- the requesting entity does not possess the
      required permissions to perform the action; the associated error
      type SHOULD be "auth".

   o  <gone/> -- the recipient or server can no longer be contacted at
      this address (the error stanza MAY contain a new address in the
      XML character data of the <gone/> element); the associated error
      type SHOULD be "modify".

   o  <internal-server-error/> -- the server could not process the
      stanza because of a misconfiguration or an otherwise-undefined
      internal server error; the associated error type SHOULD be "wait".

   o  <item-not-found/> -- the addressed JID or item requested cannot be
      found; the associated error type SHOULD be "cancel".

   o  <jid-malformed/> -- the sending entity has provided or
      communicated an XMPP address (e.g., a value of the 'to' attribute)
      or aspect thereof (e.g., a resource identifier) that does not
      adhere to the syntax defined in Addressing Scheme (Section 3); the
      associated error type SHOULD be "modify".





Saint-Andre, Ed.            Standards Track                    [Page 55]

RFC 3920                       XMPP Core                    October 2004


   o  <not-acceptable/> -- the recipient or server understands the
      request but is refusing to process it because it does not meet
      criteria defined by the recipient or server (e.g., a local policy
      regarding acceptable words in messages); the associated error type
      SHOULD be "modify".

   o  <not-allowed/> -- the recipient or server does not allow any
      entity to perform the action; the associated error type SHOULD be
      "cancel".

   o  <not-authorized/> -- the sender must provide proper credentials
      before being allowed to perform the action, or has provided
      improper credentials; the associated error type SHOULD be "auth".

   o  <payment-required/> -- the requesting entity is not authorized to
      access the requested service because payment is required; the
      associated error type SHOULD be "auth".

   o  <recipient-unavailable/> -- the intended recipient is temporarily
      unavailable; the associated error type SHOULD be "wait" (note: an
      application MUST NOT return this error if doing so would provide
      information about the intended recipient's network availability to
      an entity that is not authorized to know such information).

   o  <redirect/> -- the recipient or server is redirecting requests for
      this information to another entity, usually temporarily (the error
      stanza SHOULD contain the alternate address, which MUST be a valid
      JID, in the XML character data of the <redirect/> element); the
      associated error type SHOULD be "modify".

   o  <registration-required/> -- the requesting entity is not
      authorized to access the requested service because registration is
      required; the associated error type SHOULD be "auth".

   o  <remote-server-not-found/> -- a remote server or service specified
      as part or all of the JID of the intended recipient does not
      exist; the associated error type SHOULD be "cancel".

   o  <remote-server-timeout/> -- a remote server or service specified
      as part or all of the JID of the intended recipient (or required
      to fulfill a request) could not be contacted within a reasonable
      amount of time; the associated error type SHOULD be "wait".

   o  <resource-constraint/> -- the server or recipient lacks the system
      resources necessary to service the request; the associated error
      type SHOULD be "wait".
   o  <service-unavailable/> -- the server or recipient does not
      currently provide the requested service; the associated error type
      SHOULD be "cancel".

   o  <subscription-required/> -- the requesting entity is not
      authorized to access the requested service because a subscription
      is required; the associated error type SHOULD be "auth".

   o  <undefined-condition/> -- the error condition is not one of those
      defined by the other conditions in this list; any error type may
      be associated with this condition, and it SHOULD be used only in
      conjunction with an application-specific condition.

   o  <unexpected-request/> -- the recipient or server understood the
      request but was not expecting it at this time (e.g., the request
      was out of order); the associated error type SHOULD be "wait".


*/
	/// <summary>
	/// 
	///o  cancel -- do not retry (the error is unrecoverable)
	///o  continue -- proceed (the condition was only a warning)
	///o  modify -- retry after changing the data sent
	///o  auth -- retry after providing credentials
	///o  wait -- retry after waiting (the error is temporary)
	/// </summary>
	public sealed class ErrorTypes
	{
		public const string Cancel="cancel";
		public const string Continue="continue";
		public const string Modify="modify";
		public const string Auth="auth";
		public const string Wait="wait";
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?