public static string GetCSeqMethod(SipHeadField field) { //Q: 2 R string raw = field.ToString(); if (!raw.StartsWith(SipHeadFieldName.CSeq)) { throw new ArgumentException("can't get CSeqMethod from :" + field.Value); } string[] arr = raw.Split(new char[] { ' ' }); if (arr.Length > 1) { return(arr[2]); } return(string.Empty); }
public static SipMessage HandleContactRequest(string userid) { //string msgContent = string.Format("<args><contacts><buddies><buddy uri=\"{0}\" result=\"1\" buddy-lists=\"\" expose-mobile-no=\"0\" expose-name=\"0\" /></buddies></contacts></args>", buddyUri.ToString()); string msgContent = string.Format("<args><contacts><buddies><buddy user-id=\"{0}\" result=\"1\" buddy-lists=\"\" local-name=\"\" expose-mobile-no=\"1\" expose-name=\"1\" /></buddies></contacts></args>", userid); SipRequest req = new SipRequest(SipMethodName.Service, DEFAULT_URI); SipHeadField hFrom = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString()); SipHeadField hCallID = new SipHeadField(SipHeadFieldName.CallID, Ower.Conncetion.NextCallID().ToString()); SipHeadField hCSeq = new SipHeadField(SipHeadFieldName.CSeq, "1 " + SipMethodName.Service); SipHeadField hEvent = new SipHeadField(SipHeadFieldName.Event, "HandleContactRequestV4"); req.HeadFields.Add(hFrom); req.HeadFields.Add(hCallID); req.HeadFields.Add(hCSeq); req.HeadFields.Add(hEvent); req.Body = msgContent; return(req); }
public static SipMessage RegSipcStep2(string response, string verifyAlgorithm, string type, string picResponse, string chid) { string msgContent = "<args><device accept-language=\"default\" machine-code=\"1F2E883F250398DEE59C33DD607A6B4C\" /><caps value=\"3FF\" /><events value=\"7F\" /><user-info mobile-no=\"" + Ower.MobileNo.ToString() + "\" user-id=\"" + Ower.UserId + "\"><personal version=\"0\" attributes=\"v4default;alv2-version;alv2-warn\" /><custom-config version=\"0\" /><contact-list version=\"0\" buddy-attributes=\"v4default\" /></user-info><credentials domains=\"fetion.com.cn;m161.com.cn;www.ikuwa.cn;games.fetion.com.cn;turn.fetion.com.cn\" /><presence><basic value=\"400\" desc=\"\" /><extendeds /></presence></args>"; SipRequest req = new SipRequest(SipMethodName.Register, DEFAULT_URI); SipHeadField hFrom = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString()); SipHeadField hCallID = new SipHeadField(SipHeadFieldName.CallID, "1"); SipHeadField hCSeq = new SipHeadField(SipHeadFieldName.CSeq, "2 " + SipMethodName.Register); SipHeadField hAuth = new SipHeadField(SipHeadFieldName.Authorization, string.Format("Digest algorithm=\"SHA1-sess-v4\",response=\"{0}\"", response)); SipHeadField hAuthExt = new SipHeadField(SipHeadFieldName.Authorization, string.Format("Verify algorithm=\"{0}\",type=\"{1}\",response=\"{2}\",chid=\"{3}\"", verifyAlgorithm, type, picResponse, chid)); req.HeadFields.Add(hFrom); req.HeadFields.Add(hCallID); req.HeadFields.Add(hCSeq); req.HeadFields.Add(hAuth); req.HeadFields.Add(hAuthExt); req.Body = msgContent; return(req); }
public static SipMessage RegSipcStep1(string cn) { string msgContent = Environment.NewLine; SipRequest req = new SipRequest(SipMethodName.Register, DEFAULT_URI); SipHeadField hFrom = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString()); SipHeadField hCallID = new SipHeadField(SipHeadFieldName.CallID, "1"); SipHeadField hCSeq = new SipHeadField(SipHeadFieldName.CSeq, "1 " + SipMethodName.Register); SipHeadField hCN = new SipHeadField("CN", cn); SipHeadField hCL = new SipHeadField("CL", "type = \"pc\", version = \"4.7.1680\""); req.HeadFields.Add(hFrom); req.HeadFields.Add(hCallID); req.HeadFields.Add(hCSeq); req.HeadFields.Add(hCN); req.HeadFields.Add(hCL); req.Body = msgContent; return(req); }
public static SipMessage LeaveMsgPacket(SipUri sipUri, 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, Ower.Conncetion.NextCallID().ToString()); SipHeadField hCSeq = new SipHeadField(SipHeadFieldName.CSeq, "2 M"); SipHeadField hTo = new SipHeadField(SipHeadFieldName.To, sipUri.ToString()); SipHeadField hContentType = new SipHeadField(SipHeadFieldName.ContentType, "text/plain"); 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); }
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); }
/// <summary> /// SMS packet. /// </summary> /// <param name="sipUri">The sipURI.</param> /// <param name="msgContent">Content of the Msg.</param> /// <param name="isCatMsg">是否是长短信</param> /// <returns></returns> public static SipMessage SMSPacket(SipUri sipUri, string msgContent, bool isCatMsg) { string eventName = (isCatMsg == true ? "SendCatSMS" : "SendSMS"); SipRequest req = new SipRequest(SipMethodName.Message, DEFAULT_URI); SipHeadField hFrom = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString()); SipHeadField hCallID = new SipHeadField(SipHeadFieldName.CallID, Ower.Conncetion.NextCallID().ToString()); SipHeadField hCSeq = new SipHeadField(SipHeadFieldName.CSeq, "1 " + SipMethodName.Message); SipHeadField hTo = new SipHeadField(SipHeadFieldName.To, sipUri.ToString()); SipHeadField hEvent = new SipHeadField(SipHeadFieldName.Event, eventName); req.HeadFields.Add(hFrom); req.HeadFields.Add(hCallID); req.HeadFields.Add(hCSeq); req.HeadFields.Add(hTo); req.HeadFields.Add(hEvent); req.Body = msgContent; return(req); }
public static SipMessage AddBuddy(SipUri buddyUri, string desc) { if (string.IsNullOrEmpty(desc)) { desc = Ower.NickName; } string msgContent = string.Format("<args><contacts><buddies><buddy uri=\"{0}\" buddy-lists=\"\" desc=\"{1}\" expose-mobile-no=\"1\" expose-name=\"1\" addbuddy-phrase-id=\"0\" /></buddies></contacts></args>", buddyUri.ToString(), desc); SipRequest req = new SipRequest(SipMethodName.Service, DEFAULT_URI); SipHeadField hFrom = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString()); SipHeadField hCallID = new SipHeadField(SipHeadFieldName.CallID, Ower.Conncetion.NextCallID().ToString()); SipHeadField hCSeq = new SipHeadField(SipHeadFieldName.CSeq, "1 " + SipMethodName.Service); SipHeadField hEvent = new SipHeadField(SipHeadFieldName.Event, "AddBuddyV4"); req.HeadFields.Add(hFrom); req.HeadFields.Add(hCallID); req.HeadFields.Add(hCSeq); req.HeadFields.Add(hEvent); req.Body = msgContent; return(req); }
public static SipMessage ReplyMsgPacket(Conversation conv, 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, conv.CallID.ToString()); //SipHeadField hCSeq = new SipHeadField(SipHeadFieldName.CSeq, conv.CSeq); SipHeadField hCSeq = new SipHeadField(SipHeadFieldName.CSeq, conv.Connection.NextCseq().ToString() + " M"); SipHeadField hTo = new SipHeadField(SipHeadFieldName.To, conv.From.ToString()); 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); }
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); }
public void AddFielder(SipHeadField fielder) { this.headFielders.Add(fielder); }