Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / C#

LumiSoft MailServer

Rate me:
Please Sign up or sign in to vote.
3.79/5 (22 votes)
17 Nov 2006CPOL1 min read 321.3K   4.9K   74  
Full featured SMTP/POP3/IMAP server
using System;
using System.Collections.Generic;
using System.Text;

namespace LumiSoft.Net.SIP.Message
{
    /// <summary>
    /// Implements SIP "Session-Expires" value. Defined in RFC 4028.
    /// </summary>
    /// <remarks>
    /// <code>
    /// RFC 4028 Syntax:
    ///     Session-Expires  = delta-seconds *(SEMI se-params)
    ///     se-params        = refresher-param / generic-param
    ///     refresher-param  = "refresher" EQUAL  ("uas" / "uac")
    /// </code>
    /// </remarks>
    public class SIP_t_SessionExpires : SIP_t_ValueWithParams
    {
        private int m_Expires = 1;

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="value">Session-Expires value.</param>
        public SIP_t_SessionExpires(string value)
        {
            Parse(value);
        }
        

        #region method Parse
        
        /// <summary>
        /// Parses "Session-Expires" from specified value.
        /// </summary>
        /// <param name="value">SIP "Session-Expires" value.</param>
        /// <exception cref="ArgumentNullException">Raised when <b>value</b> is null.</exception>
        /// <exception cref="SIP_ParseException">Raised when invalid SIP message.</exception>
        public void Parse(string value)
        {
            if(value == null){
                throw new ArgumentNullException("value");
            }

            Parse(new StringReader(value));
        }

        /// <summary>
        /// Parses "Session-Expires" from specified reader.
        /// </summary>
        /// <param name="reader">Reader from where to parse.</param>
        /// <exception cref="ArgumentNullException">Raised when <b>reader</b> is null.</exception>
        /// <exception cref="SIP_ParseException">Raised when invalid SIP message.</exception>
        public override void Parse(StringReader reader)
        {
            /*
                Session-Expires  = delta-seconds *(SEMI se-params)
                se-params        = refresher-param / generic-param
                refresher-param  = "refresher" EQUAL  ("uas" / "uac")      
            */

            if(reader == null){
                throw new ArgumentNullException("reader");
            }

            // delta-seconds
            string word = reader.ReadWord();
            if(word == null){
                throw new SIP_ParseException("Session-Expires delta-seconds value is missing !");
            }
            try{
                m_Expires = Convert.ToInt32(word);
            }
            catch{
                throw new SIP_ParseException("Invalid Session-Expires delta-seconds value !");
            }

            // Parse parameters
            ParseParameters(reader);
        }

        #endregion

        #region method ToStringValue

        /// <summary>
        /// Converts this to valid "Session-Expires" value.
        /// </summary>
        /// <returns>Returns "Session-Expires" value.</returns>
        public override string ToStringValue()
        {
            /*
                Session-Expires  = delta-seconds *(SEMI se-params)
                se-params        = refresher-param / generic-param
                refresher-param  = "refresher" EQUAL  ("uas" / "uac")      
            */

            StringBuilder retVal = new StringBuilder();
            
            // delta-seconds
            retVal.Append(m_Expires.ToString());

            // Add parameters
            retVal.Append(ParametersToString());

            return retVal.ToString();
        }

        #endregion


        #region Properties Implementation

        /// <summary>
        /// Gets or sets after how many seconds session expires.
        /// </summary>
        /// <exception cref="ArgumentException">Is raised when value less than 1 is passed.</exception>
        public int Expires
        {
            get{ return m_Expires; }

            set{
                if(m_Expires < 1){
                    throw new ArgumentException("Property Expires value must be > 0 !");
                }

                m_Expires = value;
            }
        }

        /// <summary>
        /// Gets or sets Session-Expires 'refresher' parameter. Normally this value is 'ua' or 'uas'.
        /// Value null means not specified.
        /// </summary>
        public string Refresher
        {
            get{ 
                SIP_Parameter parameter = this.Parameters["refresher"];
                if(parameter != null){
                    return parameter.Value;
                }
                else{
                    return null;
                }
            }

            set{
                if(value == null){
                    this.Parameters.Remove("refresher");
                }
                else{
                    this.Parameters.Set("refresher",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