public SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum serverType, SIPMonitorEventTypesEnum eventType, string message, SIPRequest sipRequest, SIPResponse sipResponse, SIPEndPoint localEndPoint, SIPEndPoint remoteEndPoint, SIPCallDirection callDirection) { m_serialisationPrefix = SERIALISATION_PREFIX; ClientType = SIPMonitorClientTypesEnum.Console; ServerType = serverType; EventType = eventType; Message = message; RemoteEndPoint = remoteEndPoint; ServerEndPoint = localEndPoint; Created = DateTimeOffset.UtcNow; ProcessID = Process.GetCurrentProcess().Id; string dirn = (callDirection == SIPCallDirection.In) ? CALLDIRECTION_IN_STRING : CALLDIRECTION_OUT_STRING; if (sipRequest != null) { Message = "REQUEST (" + Created.ToString("HH:mm:ss:fff") + "): " + localEndPoint + dirn + remoteEndPoint + "\r\n" + sipRequest.ToString(); } else if (sipResponse != null) { Message = "RESPONSE (" + Created.ToString("HH:mm:ss:fff") + "): " + localEndPoint + dirn + remoteEndPoint + "\r\n" + sipResponse.ToString(); } }
/// <summary> /// Forwards a SIP request through the Proxy. This method differs from the standard Send in that irrespective of whether the Proxy is /// receiving and sending on different sockets only a single Via header will ever be allowed on the request. It is then up to the /// response processing logic to determine from which Proxy socket to forward the request and to add back on the Via header for the /// end agent. This method is only ever used for requests destined for EXTERNAL SIP end points. /// </summary> /// <param name="dstSIPEndPoint">The destination SIP socket to send the request to.</param> /// <param name="sipRequest">The SIP request to send.</param> /// default channel that matches the destination end point should be used.</param> public void SendTransparent(SIPEndPoint dstSIPEndPoint, SIPRequest sipRequest, IPAddress publicIPAddress) { try { if (!IsDestinationValid(sipRequest, dstSIPEndPoint)) { logger.Debug("SendTransparent failed destination check."); return; } // Determine the external SIP endpoint that the proxy will use to send this request. SIPEndPoint localSIPEndPoint = null; if (!sipRequest.Header.ProxySendFrom.IsNullOrBlank()) { SIPChannel proxyChannel = m_sipTransport.FindSIPChannel(SIPEndPoint.ParseSIPEndPoint(sipRequest.Header.ProxySendFrom)); localSIPEndPoint = (proxyChannel != null) ? proxyChannel.SIPChannelEndPoint : null; } localSIPEndPoint = localSIPEndPoint ?? m_sipTransport.GetDefaultSIPEndPoint(dstSIPEndPoint); // Create the single Via header for the outgoing request. It uses the passed in branchid which has been taken from the // request that's being forwarded. If this proxy is behind a NAT and the public IP is known that's also set on the Via. string proxyBranch = sipRequest.Header.Vias.PopTopViaHeader().Branch; sipRequest.Header.Vias = new SIPViaSet(); SIPViaHeader via = new SIPViaHeader(localSIPEndPoint, proxyBranch); if (publicIPAddress != null) { via.Host = publicIPAddress.ToString(); } sipRequest.Header.Vias.PushViaHeader(via); if (sipRequest.Method != SIPMethodsEnum.REGISTER) { AdjustContactHeader(sipRequest.Header, localSIPEndPoint, publicIPAddress); } // If dispatcher is being used record the transaction so responses are sent to the correct internal socket. if (m_dispatcher != null && sipRequest.Method != SIPMethodsEnum.REGISTER && sipRequest.Method != SIPMethodsEnum.ACK && sipRequest.Method != SIPMethodsEnum.NOTIFY) { //Log("RecordDispatch for " + sipRequest.Method + " " + sipRequest.URI.ToString() + " to " + sipRequest.RemoteSIPEndPoint.ToString() + "."); m_dispatcher.RecordDispatch(sipRequest, sipRequest.RemoteSIPEndPoint); } // Proxy sepecific headers that don't need to be seen by external UAs. sipRequest.Header.ProxyReceivedOn = null; sipRequest.Header.ProxyReceivedFrom = null; sipRequest.Header.ProxySendFrom = null; sipRequest.LocalSIPEndPoint = localSIPEndPoint; m_sipTransport.SendRequest(dstSIPEndPoint, sipRequest); } catch (Exception excp) { logger.Error("Exception SendTransparent. " + excp.Message); logger.Error(sipRequest.ToString()); throw; } }
public void TestMethod1() { Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); string sipMsg = @"INVITE sip:[email protected];unknownparam SIP/2.0 TO : sip:[email protected] ; tag = 1918181833n from : ""J Rosenberg \\\"""" <sip:[email protected]> ; tag = 98asjd8 MaX-fOrWaRdS: 0068 Call-ID: [email protected] Content-Length : 150 cseq: 0009 INVITE Via : SIP / 2.0 /UDP 192.0.2.2;branch=390skdjuw s : NewFangledHeader: newfangled value continued newfangled value UnknownHeaderWithUnusualValue: ;;,,;;,; Content-Type: application/sdp Route: <sip:services.example.com;lr;unknownwith=value;unknown-no-value> v: SIP / 2.0 / TCP spindle.example.com ; branch = z9hG4bK9ikj8 , SIP / 2.0 / UDP 192.168.255.111 ; branch= z9hG4bK30239 m:""Quoted string \""\"""" <sip:[email protected]> ; newparam = newvalue ; secondparam ; q = 0.33 v=0 o=mhandley 29739 7272939 IN IP4 192.0.2.3 s=- c=IN IP4 192.0.2.4 t=0 0 m=audio 49217 RTP/AVP 0 12 m=video 3227 RTP/AVP 31 a=rtpmap:31 LPC"; SIPMessage sipMessage = SIPMessage.ParseSIPMessage(Encoding.UTF8.GetBytes(sipMsg), null, null); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessage); Console.WriteLine(inviteReq.ToString()); Console.WriteLine("-----------------------------------------"); }
/// <summary> /// Used to send a SIP request received from an external user agent to an internal SIP server agent. /// </summary> /// <param name="receivedFromEP">The SIP end point the proxy received the request from.</param> /// <param name="receivedOnEP">The SIP end point the proxy received the request on.</param> /// <param name="dstSocket">The internal socket to send the request to.</param> /// <param name="sipRequest">The SIP request to send.</param> /// <param name="proxyBranch">The branch to set on the Via header when sending the request. The branch should be calculated /// by the proxy core so that looped requests can be detected.</param> /// <param name="sendFromSocket">The proxy socket to send the request from.</param> public void SendInternal(SIPEndPoint receivedFromEP, SIPEndPoint receivedOnEP, string dstSocket, SIPRequest sipRequest, string proxyBranch, string sendFromSocket) { try { if (!IsDestinationValid(sipRequest, dstSocket)) { logger.Debug("SendInternal failed destination check."); return; } sipRequest.Header.ProxyReceivedFrom = receivedFromEP.ToString(); sipRequest.Header.ProxyReceivedOn = receivedOnEP.ToString(); SIPEndPoint dstSIPEndPoint = SIPEndPoint.ParseSIPEndPoint(dstSocket); SIPEndPoint localSIPEndPoint = SIPEndPoint.ParseSIPEndPoint(sendFromSocket); if (receivedOnEP != localSIPEndPoint) { // The proxy is being requested to send the request on a different socket to the one it was received on. // A second Via header is added to ensure the response can navigate back the same path. The calculated branch // parameter needs to go on the top Via header so that whichever internal socket the request is being sent to can // determine re-transmits. SIPViaHeader via = new SIPViaHeader(receivedOnEP, CallProperties.CreateBranchId()); sipRequest.Header.Vias.PushViaHeader(via); SIPViaHeader topVia = new SIPViaHeader(localSIPEndPoint, proxyBranch); sipRequest.Header.Vias.PushViaHeader(topVia); } else { // Only a single Via header is required as any response to this request will be sent from the same socket it gets received on. SIPViaHeader via = new SIPViaHeader(localSIPEndPoint, proxyBranch); sipRequest.Header.Vias.PushViaHeader(via); } sipRequest.LocalSIPEndPoint = localSIPEndPoint; m_sipTransport.SendRequest(dstSIPEndPoint, sipRequest); } catch (Exception excp) { logger.Error("Exception SIPRequest SendInternal. " + excp.Message); logger.Error(sipRequest.ToString()); throw; } }
public async Task GotNotificationRequest(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) { try { logger.LogDebug("SIPNotifierClient GotNotificationRequest for " + sipRequest.Method + " " + sipRequest.URI.ToString() + " " + sipRequest.Header.CSeq + "."); SIPResponse okResponse = SIPResponse.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Ok, null); await m_sipTransport.SendResponseAsync(okResponse).ConfigureAwait(false); //logger.LogDebug(sipRequest.ToString()); if (sipRequest.Method == SIPMethodsEnum.NOTIFY && sipRequest.Header.CallId == m_subscribeCallID && sipRequest.Header.Event == m_sipEventPackage.ToString() && sipRequest.Body != null) { if (sipRequest.Header.CSeq <= m_remoteCSeq) { logger.LogWarning( "A duplicate NOTIFY request received by SIPNotifierClient for subscription Call-ID " + m_subscribeCallID + "."); } else { //logger.LogDebug("New dialog info notification request received."); m_remoteCSeq = sipRequest.Header.CSeq; T sipEvent = new T(); sipEvent.Load(sipRequest.Body); NotificationReceived(sipEvent); } } else { logger.LogWarning( "A request received by SIPNotifierClient did not match the subscription details, request Call-ID=" + sipRequest.Header.CallId + ", subscribed Call-ID=" + m_subscribeCallID + "."); logger.LogDebug(sipRequest.ToString()); } } catch (Exception excp) { logger.LogError("Exception GotNotificationRequest. " + excp.Message); } }
public async Task TestSetRequestCustomHeaderFuncUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPEndPoint dummyEP = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 5060)); string inviteReqStr = @"INVITE sip:[email protected]:12014 SIP/2.0 Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27 To: <sip:[email protected]:12014> From: <sip:[email protected]>;tag=2062917371 Call-ID: 8ae45c15425040179a4285d774ccbaf6 CSeq: 1 INVITE Contact: <sip:127.0.0.1:1234> Max-Forwards: 70 User-Agent: unittest Content-Length: 5 Content-Type: application/sdp dummy"; var sipReqBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummyEP, dummyEP); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipReqBuffer); using (var transport = new SIPTransport()) { transport.AddSIPChannel(new MockSIPChannel(dummyEP.GetIPEndPoint())); string contactHost = "devcall.sipsorcery.com"; transport.CustomiseRequestHeader = (local, dst, req) => { var hdr = req.Header.Copy(); hdr.Contact[0].ContactURI.Host = contactHost; return(hdr); }; await transport.SendRequestAsync(inviteReq); logger.LogDebug(inviteReq.ToString()); Assert.Equal(contactHost, inviteReq.Header.Contact[0].ContactURI.Host); } }
public SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum serverType, SIPMonitorEventTypesEnum eventType, string message, SIPRequest sipRequest, SIPResponse sipResponse, SIPEndPoint localEndPoint, SIPEndPoint remoteEndPoint, SIPCallDirection callDirection) { m_serialisationPrefix = SERIALISATION_PREFIX; ClientType = SIPMonitorClientTypesEnum.Console; ServerType = serverType; EventType = eventType; Message = message; RemoteEndPoint = remoteEndPoint; ServerEndPoint = localEndPoint; Created = DateTimeOffset.UtcNow; #if !SILVERLIGHT ProcessID = Process.GetCurrentProcess().Id; #endif string dirn = (callDirection == SIPCallDirection.In) ? CALLDIRECTION_IN_STRING : CALLDIRECTION_OUT_STRING; if (sipRequest != null) { Message = "REQUEST (" + Created.ToString("HH:mm:ss:fff") + "): " + localEndPoint + dirn + remoteEndPoint + "\r\n" + sipRequest.ToString(); } else if (sipResponse != null) { Message = "RESPONSE (" + Created.ToString("HH:mm:ss:fff") + "): " + localEndPoint + dirn + remoteEndPoint + "\r\n" + sipResponse.ToString(); } }
private static void SIPRequestInTraceEvent(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) { logger.DebugFormat("REQUEST IN {0}->{1}", remoteEndPoint.ToString(), localSIPEndPoint.ToString()); logger.Debug(sipRequest.ToString()); }
/// <summary> /// Used to send a request from an internal server agent to an external SIP user agent. The difference between this method and /// the SendTransparent method is that this one will set Via headers in accordance with RFC3261. /// </summary> /// <param name="receivedOnEP">The proxy SIP end point the request was received on.</param> /// <param name="dstSocket">The SIP end point the request is being sent to.</param> /// <param name="sipRequest">The SIP request to send.</param> /// <param name="proxyBranch">The branch parameter for the top Via header that has been pre-calculated by the proxy core.</param> /// <param name="sendFromSocket">The proxy SIP end point to send this request from. If the SIP request has its ProxySendFrom header /// value set that will overrule this parameter.</param> public void SendExternal(SIPEndPoint receivedOnEP, SIPEndPoint dstSIPEndPoint, SIPRequest sipRequest, string proxyBranch, IPAddress publicIPAddress) { try { if (!IsDestinationValid(sipRequest, dstSIPEndPoint)) { logger.Debug("SendExternal failed destination check."); return; } // Determine the external SIP endpoint that the proxy will use to send this request. SIPEndPoint localSIPEndPoint = m_sipTransport.GetDefaultSIPEndPoint(dstSIPEndPoint); if (!sipRequest.Header.ProxySendFrom.IsNullOrBlank()) { SIPChannel proxyChannel = m_sipTransport.FindSIPChannel(SIPEndPoint.ParseSIPEndPoint(sipRequest.Header.ProxySendFrom)); if (proxyChannel == null) { logger.Warn("No SIP channel could be found for\n" + sipRequest.ToString()); } localSIPEndPoint = (proxyChannel != null) ? proxyChannel.SIPChannelEndPoint : localSIPEndPoint; } if (receivedOnEP != localSIPEndPoint) { // The proxy is being requested to send the request on a different socket to the one it was received on. // A second Via header is added to ensure the response can navigate back the same path. The calculated branch // parameter needs to go on the top Via header so that whichever internal socket the request is being sent to can // determine re-transmits. SIPViaHeader via = new SIPViaHeader(receivedOnEP, CallProperties.CreateBranchId()); sipRequest.Header.Vias.PushViaHeader(via); SIPViaHeader externalVia = new SIPViaHeader(localSIPEndPoint, proxyBranch); sipRequest.Header.Vias.PushViaHeader(externalVia); } else { // Only a single Via header is required as any response to this request will be sent from the same socket it gets received on. SIPViaHeader via = new SIPViaHeader(localSIPEndPoint, proxyBranch); sipRequest.Header.Vias.PushViaHeader(via); } if (sipRequest.Method != SIPMethodsEnum.REGISTER) { AdjustContactHeader(sipRequest.Header, localSIPEndPoint, publicIPAddress); } sipRequest.LocalSIPEndPoint = localSIPEndPoint; // Proxy sepecific headers that don't need to be seen by external UAs. sipRequest.Header.ProxyReceivedOn = null; sipRequest.Header.ProxyReceivedFrom = null; sipRequest.Header.ProxySendFrom = null; m_sipTransport.SendRequest(dstSIPEndPoint, sipRequest); } catch (Exception excp) { logger.Error("Exception SIPRequest SendExternal. " + excp.Message); logger.Error(sipRequest.ToString()); throw; } }
void sipTransport2_SIPRequestInTraceEvent(SIPEndPoint localEndPoint, SIPEndPoint fromEndPoint, SIPRequest sipRequest) { Console.WriteLine("Request Received: " + localEndPoint.ToString() + "<-" + fromEndPoint.ToString() + "\r\n" + sipRequest.ToString()); }
public void GotRequest(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) { FireTransactionTraceMessage("Received Request " + localSIPEndPoint.ToString() + "<-" + remoteEndPoint.ToString() + m_crLF + sipRequest.ToString()); if (TransactionRequestReceived != null) { TransactionRequestReceived(localSIPEndPoint, remoteEndPoint, this, sipRequest); } }
void transport_SIPRequestInTraceEvent(SIPEndPoint localEndPoint, SIPEndPoint fromEndPoint, SIPRequest sipRequest) { logger.LogDebug("Request In: " + localEndPoint + "<-" + fromEndPoint.ToString() + "\n" + sipRequest.ToString()); }
private void LogSIPRequestOut(SIPEndPoint localSIPEndPoint, SIPEndPoint endPoint, SIPRequest sipRequest) { string message = "App Svr Sent: " + localSIPEndPoint.ToString() + "->" + endPoint.ToString() + "\r\n" + sipRequest.ToString(); //logger.Debug("as: request out " + sipRequest.Method + " " + localSIPEndPoint.ToString() + "->" + endPoint.ToString() + ", callid=" + sipRequest.Header.CallId + "."); string fromUser = (sipRequest.Header.From != null && sipRequest.Header.From.FromURI != null) ? sipRequest.Header.From.FromURI.User : "******"; FireSIPMonitorEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.FullSIPTrace, message, fromUser, localSIPEndPoint, endPoint)); }
void transport_SIPRequestOutTraceEvent(SIPEndPoint localEndPoint, SIPEndPoint toEndPoint, SIPRequest sipRequest) { logger.LogDebug("Request Out: " + localEndPoint + "->" + toEndPoint.ToString() + "\n" + sipRequest.ToString()); }
private void LogSIPRequestIn(SIPEndPoint localSIPEndPoint, SIPEndPoint endPoint, SIPRequest sipRequest) { string message = "Proxy Request Received: " + localSIPEndPoint.ToString() + "<-" + endPoint.ToString() + "\r\n" + sipRequest.ToString(); //logger.Debug("pr: request in " + sipRequest.Method + " " + localSIPEndPoint.ToString() + "<-" + endPoint.ToString() + ", callid=" + sipRequest.Header.CallId + "."); string fromUser = (sipRequest.Header.From != null && sipRequest.Header.From.FromURI != null) ? sipRequest.Header.From.FromURI.User : "******"; FireSIPMonitorEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.SIPProxy, SIPMonitorEventTypesEnum.FullSIPTrace, message, fromUser, localSIPEndPoint, endPoint)); }
public void SendRequest(SIPRequest sipRequest) { SIPEndPoint dstEndPoint = m_sipTransport.GetRequestEndPoint(sipRequest, OutboundProxy, true).GetSIPEndPoint(); if (dstEndPoint != null) { FireTransactionTraceMessage("Send Request " + LocalSIPEndPoint.ToString() + "->" + dstEndPoint.ToString() + m_crLF + sipRequest.ToString()); if (sipRequest.Method == SIPMethodsEnum.ACK) { m_ackRequest = sipRequest; m_ackRequestIPEndPoint = dstEndPoint; } else { RemoteEndPoint = dstEndPoint; } m_sipTransport.SendRequest(dstEndPoint, sipRequest); } else { throw new ApplicationException("Could not send Transaction Request as request end point could not be determined.\r\n" + sipRequest.ToString()); } }
public void SendRequest(SIPEndPoint dstEndPoint, SIPRequest sipRequest) { FireTransactionTraceMessage("Send Request " + LocalSIPEndPoint.ToString() + "->" + dstEndPoint + m_crLF + sipRequest.ToString()); if (sipRequest.Method == SIPMethodsEnum.ACK) { m_ackRequest = sipRequest; m_ackRequestIPEndPoint = dstEndPoint; } m_sipTransport.SendRequest(dstEndPoint, sipRequest); }
private static void SIPRequestOutTraceEvent(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) { logger.LogDebug("REQUEST OUT {0}->{1}", localSIPEndPoint.ToString(), remoteEndPoint.ToString()); logger.LogDebug(sipRequest.ToString()); }
void transport_SIPRequestInTraceEvent(SIPEndPoint localEndPoint, SIPEndPoint fromEndPoint, SIPRequest sipRequest) { Console.WriteLine("Request In: " + localEndPoint + "<-" + fromEndPoint.ToString() + "\n" + sipRequest.ToString()); }
private void SIPRequestOutTraceEvent(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPRequest sipRequest) { logger.Debug($"Request Sent {localEP}<-{remoteEP}: {sipRequest.StatusLine}."); if (_homerSIPClient != null) { var hepBuffer = HepPacket.GetBytes(localEP, remoteEP, DateTime.Now, 333, "myHep", sipRequest.ToString()); _homerSIPClient.SendAsync(hepBuffer, hepBuffer.Length, HOMER_SERVER_ADDRESS, HOMER_SERVER_PORT); } }
void sipTransport1_SIPRequestOutTraceEvent(SIPEndPoint localEndPoint, SIPEndPoint toEndPoint, SIPRequest sipRequest) { Console.WriteLine("Request Sent: " + localEndPoint.ToString() + "<-" + toEndPoint.ToString() + "\r\n" + sipRequest.ToString()); }
void transport_SIPRequestOutTraceEvent(SIPEndPoint localEndPoint, SIPEndPoint toEndPoint, SIPRequest sipRequest) { Console.WriteLine("Request Out: " + localEndPoint + "->" + toEndPoint.ToString() + "\n" + sipRequest.ToString()); }
private static void SIPRequestReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) { Console.WriteLine("SIP request received from " + remoteEndPoint + "."); Console.WriteLine(sipRequest.ToString()); }