public static void WriteRCVPacket(SipMessage p) { string info = Environment.NewLine + ">>>>>>>>>>>>>>>>> rcv pack start >>>>>>>>>>>>>>" + Environment.NewLine; info += p; info += Environment.NewLine + ">>>>>>>>>>>>>>>> rcv pack end >>>>>>>>>>>>>>>>>>" + Environment.NewLine; Log.WriteLog(LogFile.Debug, info); }
public void Route(ISipTransport transport, SipMessage message) { lock (syncLock) { queue.Enqueue(message); recvEvt.Set(); } }
// 同意对方添加自己为好友 public void AgreeAddBuddy(SipUri uri, string userid) { SipMessage agreePacket = PacketFactory.HandleContactRequest(userid); this.convHandleContactRequest = this.convMgr.Create(agreePacket, true); this.convHandleContactRequest.MsgRcv += new EventHandler <ConversationArgs>(this.ConvHandleContactRequest_MsgRcv); this.user.ContactsManager.Add(new Contact(uri, string.Empty, ContactType.Buddy)); }
public void Parse183SessionProgress() { const string HexData = "5349502f322e30203138332053657373696f6e2050726f67726573730d0a416c6c6f773a20494e564954452c4259452c52454749535445522c41434b2c4f5054494f4e532c43414e43454c2c494e464f2c5355425343524942452c4e4f544946592c52454645522c5550444154450d0a43616c6c2d49443a2033646534363232302d343038622d343065302d386164612d3436393366616530386437394031302e302e352e32350d0a436f6e746163743a203c7369703a31353439394031302e302e382e34343a353036303e0d0a436f6e74656e742d547970653a206d756c7469706172742f6d697865643b626f756e646172793d756e697175652d626f756e646172792d310d0a435365713a203220494e564954450d0a46726f6d3a203c7369703a31313939323937313732314031302e302e352e32353a353036303b757365723d70686f6e653e0d0a526571756972653a2031303072656c0d0a525365713a20310d0a53657373696f6e2d49443a2030316538316263313366363434356262646130313161633866376431323564330d0a537570706f727465643a2074696d65722c7265706c616365730d0a546f3a203c7369703a31353439394031302e302e382e34343a353036303b757365723d70686f6e653e3b7461673d363833312d463133330d0a5669613a205349502f322e302f5544502031302e302e352e32353a353036303b72656365697665643d31302e302e352e32353b6272616e63683d7a39684734624b3766653864316366323864333831383631660d0a436f6e74656e742d4c656e6774683a203430380d0a0d0a2d2d756e697175652d626f756e646172792d310d0a436f6e74656e742d547970653a206170706c69636174696f6e2f7364700d0a0d0a763d300d0a6f3d2d2039203020494e204950342031302e302e382e34340d0a733d2d0d0a633d494e204950342031302e302e382e34340d0a743d3020300d0a6d3d617564696f203130303136205254502f4156502038203130310d0a613d7274706d61703a382050434d412f383030300d0a613d7274706d61703a3130312074656c6570686f6e652d6576656e742f383030300d0a613d666d74703a31303120302d31350d0a613d7074696d653a32340d0a613d73656e64726563760d0a0d0a2d2d756e697175652d626f756e646172792d310d0a436f6e74656e742d547970653a206170706c69636174696f6e2f495355503b76657273696f6e3d6974752d7439322b3b626173653d6e7876330d0a436f6e74656e742d446973706f736974696f6e3a207369676e616c3b68616e646c696e673d6f7074696f6e616c0d0a0d0a06120001290101000d0a2d2d756e697175652d626f756e646172792d312d2d0d0a"; var binaryData = HexData.ToByteArray().ToArray(); SipMessage.Parse(binaryData); }
public static SipRequest CreateRequest(this SipMessage sipMessage) { if (sipMessage.GetMessageType() != SipMessageType.Request) { throw new SipParsingException(); } throw new NotImplementedException(); }
/// <summary> /// 添加好友 /// </summary> /// <param name="uri">sipuri</param> /// <param name="desc">description,为空时显示用户昵称</param> public void AddBuddy(SipUri uri, string desc) { if (this.isAlive == false) { return; } SipMessage packet = PacketFactory.AddBuddy(uri, desc); this.convAddBuddy = this.convMgr.Create(packet, true); this.convAddBuddy.MsgRcv += new EventHandler <ConversationArgs>(this.ConvAddBuddy_MsgRcv); }
/// <summary> /// Routes a <see cref="SipMessage" /> received by an <see cref="ISipTransport" /> to the <see cref="ISipAgent" /> /// instance that needs to handle it. /// </summary> /// <param name="transport">The <see cref="ISipTransport" /> that received the message.</param> /// <param name="message">The <see cref="SipMessage" /> received by the transport.</param> public void Route(ISipTransport transport, SipMessage message) { if (message is SipRequest && agent is SipServerAgent) { agent.OnReceive(transport, message); } else if (message is SipResponse && agent is SipClientAgent) { agent.OnReceive(transport, message); } }
public void Shall_parse_response_bytes() { const string str = "SIP/2.0 200 OK\r\nContent-Length: 0\r\n" + "\r\n"; var response = (SipResponse)SipMessage.Parse(Encoding.UTF8.GetBytes(str)); Assert.That(response.Version, Is.EqualTo("SIP/2.0")); Assert.That(response.StatusCode, Is.EqualTo(200)); Assert.That(response.ReasonPhrase, Is.EqualTo("OK")); }
public void Get_Raw_Sip_Message_Type_Success(string sipMessage, SipMessageType messageTypeExpected) { // *** ARRANGE *** SipMessage rawMessage = new SipMessage(sipMessage); // *** ACT *** SipMessageType messageTypeResult = rawMessage.GetMessageType(); // *** ASSERT *** Assert.Equal(messageTypeExpected, messageTypeResult); }
private void SingInSipcStep1() { string sendData = FetionTemplate.RegesterSIPCStep1(this.user.Uri.Sid.ToString()); string[] addrStrArr = this.user.SysConfig.SipcProxy.Split(':'); CreateConnection(addrStrArr[0], addrStrArr[1]); //cn值是随机的,可以自己创建. SipMessage step1data = PacketFactory.RegSipcStep1("d62aa14003cb0de2f252afa755df43cf"); this.convRegSipcStep1 = this.convMgr.Create(step1data, true); this.convRegSipcStep1.MsgRcv += new EventHandler <ConversationArgs>(this.ConvRegSipcStep1_OnMsgRcv); }
private void ProcessHeaderLines(List <string> headerLines, SipMessage sipMessage) { //var factory = new SipParserFactory(); //var headers = new List<SipHeaderBase>(); //foreach (var headerLine in headerLines) //{ // var parser = factory.CreateHeaderParser(ParseHeaderName(headerLine)); // SipHeaderBase sipHeader = parser.Parse(new Util.StringReader(headerLine)); // headers.Add(sipHeader); //} // sipMessage.SetHeaders(headers); }
private void SingInSipcStep2(string nonce, string rsaKey) { if (string.IsNullOrEmpty(nonce)) { return; } this.sipcResponse = ComputeAuthResponse.ComputeNewResponse(this.user.UserId, this.user.Password, rsaKey, nonce); SipMessage step2data = PacketFactory.RegSipcStep2(this.sipcResponse); this.convRegSipcStep2 = this.convMgr.Create(step2data, true); this.convRegSipcStep2.MsgRcv += new EventHandler <ConversationArgs>(this.convRegSipcStep2_MsgRcv); }
public virtual void Send(SipMessage packet) { DebugWriter.WriteSendPacket(packet); try { TcpHelper.AsyncSend(this.socket, packet, this.SendCallback); } catch (SocketException ex) { Log.WriteLog(LogFile.Error, ex.ToString()); ErrManager.RaiseError(new FxErrArgs(ErrLevel.Fatal, ex)); } }
public override void Send(SipMessage packet) { try { TcpHelper.AsyncSend(this.socket, packet, this.SendCallback); } catch (SocketException ex) { Log.WriteLog(LogFile.Debug, "ChatConnection Send异常:" + ex.ToString()); //not throw fata error,keep main thread not exit ErrManager.RaiseError(new FxErrArgs(ErrLevel.Critical, ex)); } }
public static StandardHeaders CreateHeaders(this SipMessage sipMessage) { throw new NotImplementedException(); //StandardHeaders headers = new StandardHeaders() //{ // CSeq = CSeq.Parse(sipMessage.GetHeaderValue(HeaderName.Cseq)[0]), // From = Identification.Parse(sipMessage.GetHeaderValue(HeaderName.From)[0]), // To = Identification.Parse(sipMessage.GetHeaderValue(HeaderName.To)[0]), // CallId = sipMessage.GetHeaderValue(HeaderName.CallId)[0], // MaxForwards = sipMessage.GetHeaderValue(HeaderName.MaxForwards)[0] //}; }
private SipContext CreateSipContext(SipMessage message, Datagram datagram) { var request = message as SipRequest; var response = message as SipResponse; var c = new SipContext(); c.Request = request; c.Response = response; c.RemoteEndPoint = datagram.RemoteEndPoint; c.LocalEndPoint = datagram.LocalEndPoint; return(c); }
public void Shall_clone_request() { const string str = "INVITE sip:[email protected] SIP/2.0\r\n" + "From: John Smith <sip:[email protected]>\r\n" + "To: Joe Shmoe <sip:[email protected]>\r\n\r\n"; var original = (SipRequest)SipMessage.Parse(str); var cloned = original.DeepClone(); original.Method = "REGISTER"; Assert.That(cloned.ToString(), Does.Contain("INVITE")); Assert.That(original.Method, Does.Contain("REGISTER")); }
public void Shall_clone_response() { const string str = "SIP/2.0 200 OK\r\nContent-Length: 0\r\n" + "\r\n"; var original = (SipResponse)SipMessage.Parse(str); var cloned = original.DeepClone(); original.StatusCode = 183; original.ReasonPhrase = "Session Progress"; Assert.That(cloned.ToString(), Does.Contain("200 OK")); Assert.That(original.ToString(), Does.Contain("183 Session Progress")); }
public Conversation(BaseSipConnection connection, SipMessage packet) { this.connection = connection; this.callID = int.Parse(packet.CallID.Value); this.cseq = packet.CSeq.Value; this.from = new SipUri(packet.From.Value); string eventStr = (packet.Event == null ? SipEvent.None.ToString() : packet.Event.Value); if (Enum.IsDefined(typeof(SipEvent), eventStr)) { this.eventName = (SipEvent)Enum.Parse(typeof(SipEvent), eventStr, true); } this.originPacket = packet; }
public void RcvPacket(SipMessage packet) { SipRequest req = packet as SipRequest; if (req != null) { if (req[SipHeadFieldName.From] != null) { this.from = new SipUri(req[SipHeadFieldName.From].Value); } this.RcvRequest(req); } else { this.RcvResponse(packet as SipResponse); } }
public void Shall_set_level() { try { TraceEvent traceEvent = null; Trace.SetLogger(e => { traceEvent = e; }); Trace.SetLevel(TraceLevel.Fatal); SipMessage.Parse("INVITE sip:[email protected] SIP/0.0\r\n\r\n"); Assert.That(traceEvent, Is.Null); } finally { Trace.SetLogger(null); } }
public static void CopyHeadersFrom(this SipMessage msg, SipMessage @from, params string[] headers) { if (headers == null) { foreach (var h in @from.Headers) { msg.Headers[h] = @from.Headers[h]; } } else { var headersToCopy = new[] { "Call-ID", "From", "Max-Forwards", "Supported", "To", "Via" }; foreach (var c in headersToCopy) { msg.Headers[c] = @from.Headers[c]; } } }
public Conversation Create(BaseSipConnection conn, SipMessage packet, bool doSend) { int callID = int.Parse(packet.CallID.Value); Conversation conv = null; lock (this.syncFlag) { if (!this.convList.ContainsKey(callID)) { conv = new Conversation(conn, packet); this.convList.Add(callID, conv); } } if (doSend) { conn.Send(packet); } return(conv); }
public void Shall_byteify_response() { var response = new SipResponse { Version = "SIP/2.0", StatusCode = 200, ReasonPhrase = "OK" }; var buffer = new byte[ushort.MaxValue]; response.TryCopyTo(buffer, 0, out int length); var response2 = (SipResponse)SipMessage.Parse(new ArraySegment <byte>(buffer, 0, length)); Assert.That(response2.ToString(), Is.EqualTo( "SIP/2.0 200 OK\r\nContent-Length: 0\r\n" + "\r\n")); }
public void Shall_intercept_trace() { try { TraceEvent traceEvent = null; Trace.SetLogger(e => { traceEvent = e; }); SipMessage.Parse("INVITE sip:[email protected] SIP/0.0\r\n\r\n"); Assert.That(traceEvent.FileName, Is.EqualTo("osip_message_parse.c")); Assert.That(traceEvent.LineNumber, Is.EqualTo(168)); Assert.That(traceEvent.Level, Is.EqualTo(TraceLevel.Error)); Assert.That(traceEvent.Message, Is.EqualTo("Wrong version number\n")); } finally { Trace.SetLogger(null); } }
public void Read_Sip_Message_Success() { // *** ARRANGE *** string sipTest = @"INVITE sip: [email protected] SIP/ 2.0\r\n" + "FROM: \"Test JPR\" < sip:[email protected] >; tag = 80eea88d4a11e71dda58b0b03400\r\n" + "To: < sip:[email protected] >\r\n" + "CSeq: 1 INVITE\r\n" + "Call-ID: 9255ba2465765c49339cde4c46086852\r\n" + "Contact: \"Test JPR\" < sip:[email protected]:5060; transport = udp; gsid = 80eea88d - 4a11 - 4701 - 8bda - 58b0b0340000 >\r\n" + "Allow: INVITE, ACK, OPTIONS, BYE, CANCEL, SUBSCRIBE, NOTIFY, REFER, INFO, PRACK, PUBLISH, UPDATE\r\n" + "Supported: 100rel, histinfo, join, replaces, timer\r\n" + "Max-Forwards: 66\r\n" + "Via: SIP / 2.0 / UDP 91.241.11.242:5060; branch = z9hG4bK - s1632 - 001300246567 - 1--s1632 -\r\n" + "Via: SIP / 2.0 / TCP 10.10.11.215:15060; rport = 53669; ibmsid = local.1476854311683_977646_977657; branch = z9hG4bK663015852070684\r\n" + "Via: SIP / 2.0 / TCP 10.10.11.215:15060; rport; ibmsid = local.1476854311683_977645_977656; branch = z9hG4bK767685979626846\r\n" + "Accept-Language: en\r\n" + "Alert-Info: < cid:internal @algocloud.net>;avaya-cm-alert-type=internal\r\n" + "P-Asserted-Identity: \"Test JPR\" <sip:[email protected]>\r\n" + "Session-Expires: 1800;refresher=uac\r\n" + "Min-SE: 1800\r\n" + "Remote-LegId: 462\r\n" + "Content-Type: application/sdp\r\n" + "User-to-User: 00FA080001008858BFD6BD;encoding=hex\r\n" + "P-AV-Message-Id: 1_1\r\n" + "Max-Breadth: 60\r\n" + "P-Charging-Vector: icid-value=\"AAS:50-8da8ee801e7114ab058da0c34b0\"\r\n" + "Content-Length: 258\r\n"; SipMessage roSipMessage = new SipMessage(sipTest); // *** ACT *** string resultFrom = roSipMessage.GetHeaderValue("FROM")[0]; string[] resultVia = roSipMessage.GetHeaderValue("Via"); string resultChargingVector = roSipMessage.GetHeaderValue("P-Charging-Vector")[0]; string resultContentLength = roSipMessage.GetHeaderValue("Content-Length")[0]; // *** ACT *** Assert.Equal(" \"Test JPR\" < sip:[email protected] >; tag = 80eea88d4a11e71dda58b0b03400", resultFrom); Assert.Equal(" icid-value=\"AAS:50-8da8ee801e7114ab058da0c34b0\"", resultChargingVector); Assert.Equal(" 258", resultContentLength); }
public SipMessage Receive() { SipMessage message; if (received != null) { message = received; received = null; recvEvt.Reset(); return(message); } if (!recvEvt.WaitOne(timeout, false)) { throw new TimeoutException(); } message = received; received = null; return(message); }
private void StartChat(SipMessage packet) { string a = packet.Authorization.Value.Trim(); if (a.IndexOf("CS address", StringComparison.CurrentCultureIgnoreCase) < 0) { return; } var kvList = StringHelper.GetKeyValuePairs(a); string[] chatSvrs = StringHelper.GetKeyFromPairs("CS address", kvList).Split(';'); string ticksAuth = StringHelper.GetKeyFromPairs("credential", kvList); IList <Contact> participants = GetChatParticipants(packet.Body); int callID = int.Parse(packet.CallID.Value); this.convMgr.Remove(callID); string remote = chatSvrs[0].Split(':')[0]; string port = chatSvrs[0].Split(':')[1]; ChatConnection conn = this.convMgr.CreateChatConnection(remote, port); if (conn != null) { conn.MessageReceived += new EventHandler <ConversationArgs>(ReceiveSipMessage); conn.StartListen(); var sipdata = PacketFactory.RegToChatServer(callID.ToString(), ticksAuth); Conversation newConv = this.convMgr.Create(conn, sipdata, true); participants.ToList().ForEach(c => newConv.Participants.Add(c)); if (newConv != null) { newConv.MsgRcv += new EventHandler <ConversationArgs>(this.convMgr.RaiseMsgRcv); } } }
public override int OnRegistrationEvent(RegistrationEvent e) { short code = e.getCode(); tsip_register_event_type_t type = e.getType(); RegistrationSession session = e.getSession(); SipMessage message = e.getSipMessage(); if (message != null) { Console.WriteLine("call-id={0}", message.getSipHeaderValue("call-id")); //byte[] bytes = message.getContent(); } switch (type) { case tsip_register_event_type_t.tsip_ao_register: case tsip_register_event_type_t.tsip_ao_unregister: break; } Console.WriteLine("OnRegistrationChanged() ==> {0}:{1}", code, e.getPhrase()); return(0); }
internal async Task SendSipMessageAsync(SipMessage sipMessage) { await UdpUser.SendAsync(remoteServerAddress, remoteServerPort, sipMessage.GetSipMessage()); }
private void ProcessHeaderLines(List<string> headerLines, SipMessage sipMessage) { //var factory = new SipParserFactory(); //var headers = new List<SipHeaderBase>(); //foreach (var headerLine in headerLines) //{ // var parser = factory.CreateHeaderParser(ParseHeaderName(headerLine)); // SipHeaderBase sipHeader = parser.Parse(new Util.StringReader(headerLine)); // headers.Add(sipHeader); //} // sipMessage.SetHeaders(headers); }