Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C#

SIP Stack with SIP Proxy - (VOIP)

Rate me:
Please Sign up or sign in to vote.
4.86/5 (45 votes)
11 Jun 2007CPOL2 min read 1.6M   28.1K   162  
C# implementation of SIP
using System;

namespace LumiSoft.Net.Mime
{
	/// <summary>
	/// Mime entity header field.
	/// </summary>
	public class HeaderField
	{
		private string m_Name  = "";
		private string m_Value = "";

		/// <summary>
		/// Default construtor.
		/// </summary>
		public HeaderField()
		{			
		}

		/// <summary>
		/// Creates new header field with specified name and value.
		/// </summary>
		/// <param name="name">Header field name. Header field name must end with colon(:) and may contain US-ASCII character values between 33 and 126.</param>
		/// <param name="value">Header field value.</param>
		public HeaderField(string name,string value)
		{
			this.Name  = name;
			this.Value = value;
		}


		#region Properties Implementation

		/// <summary>
		/// Gets or sets header field name. Header field name must end with colon(:) and may contain US-ASCII character values between 33 and 126.
		/// </summary>
		public string Name
		{
			get{ return m_Name; }

			set{ 
				/* RFC 2822 2.2 Header Fields
					Header fields are lines composed of a field name, followed by a colon
					(":"), followed by a field body, and terminated by CRLF.  A field
					name MUST be composed of printable US-ASCII characters (i.e.,
					characters that have values between 33 and 126, inclusive), except
					colon.  A field body may be composed of any US-ASCII characters,
					except for CR and LF.  However, a field body may contain CRLF when
					used in header "folding" and  "unfolding" as described in section
					2.2.3.  All field bodies MUST conform to the syntax described in
					sections 3 and 4 of this standard.
				*/

				if(value == ""){
					throw new Exception("Header Field name can't be empty !");
				}
				
				// Colon is missing from name, just add it
				if(!value.EndsWith(":")){
					value += ":";
				}

				// Check if name is between ASCII 33 - 126 characters
				foreach(char c in value.Substring(0,value.Length - 1)){
					if(c < 33 || c > 126){
						throw new Exception("Invalid field name '" + value + "'. A field name MUST be composed of printable US-ASCII characters (i.e.,characters that have values between 33 and 126, inclusive),except	colon.");
					}
				}

				m_Name = value; 
			}
		}

		/// <summary>
		/// Gets or sets header field value.
		/// </summary>
		public string Value
		{
			get{ return Core.CanonicalDecode(m_Value); }

			set{ m_Value = Core.CanonicalEncode(value,"utf-8"); }
		}

        /// <summary>
        /// Gets header field encoded value.
        /// </summary>
        internal string EncodedValue
        {
            get{ return m_Value; }
        }

		#endregion

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions