Ejemplo n.º 1
0
        private static SipResponse CreateDefaultResponse(SipMessage packet)
        {
            SipResponse  response = new SipResponse(200, "OK");
            SipHeadField hCallID  = new SipHeadField(SipHeadFieldName.CallID, packet.CallID.Value);
            SipHeadField hCSeq    = new SipHeadField(SipHeadFieldName.CSeq, packet.CSeq.Value);
            SipHeadField hFrom    = new SipHeadField(SipHeadFieldName.From, packet.From.Value);

            if (packet.To != null)
            {
                SipHeadField hTo = new SipHeadField(SipHeadFieldName.To, packet.To.Value);
                response.HeadFields.Add(hTo);
            }
            if (packet.Supported != null)
            {
                SipHeadField hSupported = new SipHeadField(SipHeadFieldName.Supported, packet.Supported.Value);
                response.HeadFields.Add(hSupported);
            }
            response.HeadFields.Add(hFrom);
            response.HeadFields.Add(hCallID);
            response.HeadFields.Add(hCSeq);

            response.Body = Environment.NewLine;

            return(response);
        }
Ejemplo n.º 2
0
 private bool CheckResponse(SipResponse rsp)
 {
     if (((rsp.CallID != null) && (rsp.CSeq != null)) && ((rsp.ContentLength == null) || ((int.Parse(rsp.ContentLength.Value) >= 0) && (int.Parse(rsp.ContentLength.Value) < MaxMessageLength))))
     {
         return(true);
     }
     if (this.MessageParsingFailed != null)
     {
         this.MessageParsingFailed(this, EventArgs.Empty);
     }
     return(false);
 }
Ejemplo n.º 3
0
        public static SipMessage RSPInvitePacket(SipMessage packet)
        {
            System.Net.EndPoint localPoint = Ower.Conncetion.LocalEndPoint;
            string port = localPoint.ToString().Split(':')[1];

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("v=0");
            sb.AppendLine("o=-0 0 IN " + localPoint.ToString());
            sb.AppendLine("s=session");
            sb.AppendLine("c=IN IP4 " + localPoint.ToString());
            sb.AppendLine("t=0 0");
            sb.AppendLine(string.Format("m=message {0} sip {1}", port, Ower.Uri.Sid));
            SipResponse response = CreateDefaultResponse(packet);

            response.Body = sb.ToString();
            return(response);
        }
Ejemplo n.º 4
0
        private bool ParseResponse(string line)
        {
            int blankIndex1 = line.IndexOf(" ");
            int blankIndex2 = line.IndexOf(" ", (int)(blankIndex1 + 1));

            if ((blankIndex1 < 1) || (blankIndex2 < 1))
            {
                if (this.MessageParsingFailed != null)
                {
                    this.MessageParsingFailed(this, EventArgs.Empty);
                }
                return(false);
            }
            try
            {
                SipResponse msg = new SipResponse(int.Parse(line.Substring(blankIndex1, blankIndex2 - blankIndex1)), line.Substring(blankIndex2 + 1));
                if (this.ParseHeaders(msg))
                {
                    if (!this.CheckResponse(msg))
                    {
                        return(false);
                    }
                    this.responseEventArgs.Response = msg;
                    if (this.ResponseReceived != null)
                    {
                        this.ResponseReceived(this, this.responseEventArgs);
                    }
                    return(true);
                }
                return(false);
            }
            catch (Exception exception)
            {
                Trace.WriteLine(exception.ToString());
                return(false);
            }
        }
Ejemplo n.º 5
0
 public SipResponseReceivedEventArgs(SipResponse response)
 {
     this.response = response;
 }