Beispiel #1
0
        private bool ParseBody(SipMessage msg)
        {
            SipHeadField lengthField = msg.ContentLength;

            if ((lengthField != null) && (Int32.Parse(lengthField.Value) >= 1))
            {
                int len = Int32.Parse(lengthField.Value);
                if ((this.stream.Length - this.stream.Position) < len)
                {
                    return(false);
                }
                msg.BodyBuffer = new byte[len];
                this.stream.Read(msg.BodyBuffer, 0, len);
            }
            return(true);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static SipMessage ReplyMsgPacket(SipMessage packet, string msgContent)
        {
            SipRequest   req          = new SipRequest(SipMethodName.Message, DEFAULT_URI);
            SipHeadField hFrom        = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString());
            SipHeadField hCallID      = new SipHeadField(SipHeadFieldName.CallID, packet.CallID.Value);
            SipHeadField hCSeq        = new SipHeadField(SipHeadFieldName.CSeq, packet.CSeq.Value);
            SipHeadField hTo          = new SipHeadField(SipHeadFieldName.To, packet.To.Value);
            SipHeadField hContentType = new SipHeadField(SipHeadFieldName.ContentType, "text/html-fragment");
            SipHeadField hSupported   = new SipHeadField(SipHeadFieldName.Supported, "SaveHistory");

            req.HeadFields.Add(hFrom);
            req.HeadFields.Add(hCallID);
            req.HeadFields.Add(hCSeq);
            req.HeadFields.Add(hTo);
            req.HeadFields.Add(hContentType);
            req.HeadFields.Add(hSupported);
            req.Body = msgContent;
            return(req);
        }
Beispiel #4
0
 private bool ParseHeaders(SipMessage msg)
 {
     for (string str = this.reader.ReadLine(); this.CheckLine(str); str = this.reader.ReadLine())
     {
         if (str.Length < 1)
         {//空白行解析开始Body部分
             return(this.ParseBody(msg));
         }
         int index = str.IndexOf(": ");
         if (index < 1)
         {
             return(false);
         }
         string       name   = str.Substring(0, index);
         SipHeadField header = this.ParseHeadField(name, str.Substring(index + 2));
         if (header != null)
         {
             msg.HeadFields.Add(header);
         }
     }
     return(false);
 }
Beispiel #5
0
 public static SipMessage RSPBye(SipMessage packet)
 {
     return(CreateDefaultResponse(packet));
 }
Beispiel #6
0
 public static SipMessage RSPReceiveMsgPacket(SipMessage packet)
 {
     return(CreateDefaultResponse(packet));
 }