Example #1
0
        public static CSeq Parse(string Input)
        {
            CSeq   c      = new CSeq();
            string pieces = Input.Split(":")[1].TrimStart();

            string[] Components = pieces.Split(" ");
            if (Components.Length != 2)
            {
                throw new IndexOutOfRangeException("CSeq requires exactly two components");
            }

            c.Sequence = int.Parse(Components[0]);
            c.Method   = (Request.RequestLine.MethodTypes)Enum.Parse(typeof(Request.RequestLine.MethodTypes), Components[1]);


            return(c);
        }
Example #2
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Via.ToString());
            sb.Append(From.ToString());
            sb.Append($"To: <sip:{To.ToString()}>").AppendLine();
            sb.Append(CallId.ToString());
            sb.Append(CSeq.ToString());
            if (!string.IsNullOrEmpty(UserAgent))
            {
                sb.Append($"User-Agent: {UserAgent}").AppendLine();
            }
            if (Expires > 0)
            {
                sb.Append($"Expires: {Expires.ToString()}").AppendLine();
            }
            if (!string.IsNullOrEmpty(Accept))
            {
                sb.Append($"Accept: {Accept}").AppendLine();
            }
            if (!string.IsNullOrEmpty(ContentType))
            {
                sb.Append($"Content-Type: {ContentType}").AppendLine();
            }
            if (ContentLength > 0)
            {
                sb.Append($"Content-Length: {ContentLength.ToString()}").AppendLine();
            }
            sb.Append($"Max-Forwards: {MaxForwards}").AppendLine();
            if (Allow != null && Allow.Count > 0)
            {
                sb.Append($"Allow: {string.Join(",",Allow)}").AppendLine();
            }
            if (CustomHeaders.Count() > 0)
            {
                foreach (KeyValuePair <string, string> Header in CustomHeaders)
                {
                    sb.Append($"X-{Header.Key}: {Header.Value}").AppendLine();
                }
            }

            return(sb.ToString());
        }