Beispiel #1
0
        public void RecordDispatch(SIPRequest sipRequest, SIPEndPoint internalEndPoint)
        {
            lock (m_transactionEndPoints)
            {
                if (m_transactionEndPoints.ContainsKey(sipRequest.Header.CallId))
                {
                    if (m_transactionEndPoints[sipRequest.Header.CallId] == internalEndPoint.ToString())
                    {
                        // The application server end point has not changed for this Call-Id
                        return;
                    }
                    else
                    {
                        // The application server end point has changed within the lifetime of the Call-Id. Remove the old mapping.
                        lock (m_transactionEndPoints)
                        {
                            m_transactionEndPoints.Remove(sipRequest.Header.CallId);
                        }
                    }
                }

                m_transactionEndPoints.Add(sipRequest.Header.CallId, internalEndPoint.ToString());
                m_transactionIDAddedAt.Add(sipRequest.Header.CallId, DateTime.Now);
                //ProxyLogger_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.SIPProxy, SIPMonitorEventTypesEnum.CallDispatcher, "Record dispatch for " + sipRequest.Method + " " + sipRequest.URI.ToString() + " to " + internalEndPoint.ToString() + " (id=" + transactionID + ").", null));
            }

            if (m_lastRemove < DateTime.Now.AddSeconds(REMOVE_EXPIREDS_SECONDS * -1))
            {
                RemoveExpiredDispatchRecords();
            }
        }
        /// <summary>
        /// 实时视频请求
        /// </summary>
        /// <param name="deviceId">设备编码</param>
        public void RealVideoReq()
        {
            //lock (_msgCore.RemoteTrans)
            //{
            //    if (!_msgCore.RemoteTrans.ContainsKey(_remoteEndPoint.ToString()))
            //    {
            //        OnSIPServiceChange(_deviceName + "-" + _deviceId + _remoteEndPoint.ToString(), SipServiceStatus.Wait);
            //        return;
            //    }
            //}

            if (!_initComplate)
            {
                OnSIPServiceChange(_deviceName + "-" + _deviceId + _remoteEndPoint.ToString(), SipServiceStatus.Wait);
                return;
            }

            _mediaPort = _msgCore.SetMediaPort();
            this.Stop();
            ByeVideoReq();
            SIPRequest realReq = RealVideoReq(_mediaPort);

            _msgCore.Transport.SendRequest(_remoteEndPoint, realReq);

            //_realTask = new TaskTiming(realReq, _msgCore.Transport);
            //_msgCore.SendRequestTimeout += _realTask.MessageSendRequestTimeout;
            //_realTask.OnCloseRTPChannel += Task_OnCloseRTPChannel;
            //_realTask.Start();
        }
Beispiel #3
0
        public void Dispatch(string remoteEndPoint, SIPRequest sipRequest)
        {
            try {
                //logger.Debug("Dispatch SIPRequest from " + remoteEndPoint + " " + sipRequest.Method + " callid=" + sipRequest.Header.CallId + ".");
                SIPEndPoint dispatchEndPoint = m_outboundProxy;

                if (remoteEndPoint == m_outboundProxy.ToString())
                {
                    if (m_callIdEndPoints.ContainsKey(sipRequest.Header.CallId))
                    {
                        // Request from proxy that matches an existing dispatched callid.
                        dispatchEndPoint = SIPEndPoint.ParseSIPEndPoint(m_callIdEndPoints[sipRequest.Header.CallId]);
                        m_sipTransport.SendRequest(dispatchEndPoint, sipRequest);
                    }
                    else
                    {
                        // A new request from proxy that needs to have a decision made about which app server to dispatch to.

                        // A new request has arrived from the proxy.

                        /*if (m_appServerIndex > m_appServerEndPoints.Count - 1) {
                         *  m_appServerIndex = 0;
                         * }
                         * dispatchEndPoint = m_appServerEndPoints[m_appServerIndex++];
                         * FireProxyLogEvent(new SIPMonitorControlClientEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Dispatching new " + sipRequest.Method + " request to " + dispatchEndPoint.ToString() + ", callid=" + sipRequest.Header.CallId + ".", null));
                         * m_callIdEndPoints.Add(sipRequest.Header.CallId, dispatchEndPoint.ToString());
                         * m_callIdAddedAt.Add(sipRequest.Header.CallId, DateTime.Now);*/

                        m_compiledScript.DefaultScope.SetVariable("dispatcher", this);
                        m_compiledScript.DefaultScope.SetVariable("request", sipRequest);
                        m_compiledScript.Execute();
                        //DispatchRequest("127.0.0.1:5070", sipRequest);
                    }
                }
                else if (!m_callIdEndPoints.ContainsKey(sipRequest.Header.CallId))
                {
                    // A new request has originated from an App Server.
                    //logger.Debug("CalLDispatcher adding endpoint for callid=" + sipRequest.Header.CallId + " as " + remoteEndPoint.ToString() + ".");
                    m_callIdEndPoints.Add(sipRequest.Header.CallId, remoteEndPoint.ToString());
                    m_callIdAddedAt.Add(sipRequest.Header.CallId, DateTime.Now);
                    m_sipTransport.SendRequest(dispatchEndPoint, sipRequest);
                }
                else
                {
                    // A request from an app server that matches an existing dispatched callid.
                    m_sipTransport.SendRequest(dispatchEndPoint, sipRequest);
                }

                //logger.Debug("Dispatching " + sipRequest.Method + " from " + remoteEndPoint.ToString() + " to " + dispatchEndPoint.ToString() + ", callid=" + sipRequest.Header.CallId + ".");

                RemoveExpiredCallIds();
            }
            catch (Exception excp) {
                logger.Error("Exception Dispatch SIPRequest. " + excp.Message);
                throw;
            }
        }
Beispiel #4
0
        public void IPv6LoopbackToStringTest()
        {
            logger.LogDebug(System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPEndPoint sipEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.IPv6Loopback, 0));

            logger.LogDebug("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.True(sipEndPoint.ToString() == "udp:[::1]:5060", "The SIP end point string representation was not correct.");
        }
 /// <summary>
 /// 初始化远程sip
 /// </summary>
 /// <param name="localEndPoint">本地终结点</param>
 /// <param name="remoteEndPoint">远程终结点</param>
 /// <param name="request">sip请求</param>
 private void SIPTransportInit(SIPEndPoint localEndPoint, SIPEndPoint remoteEndPoint, SIPRequest request)
 {
     lock (RemoteTrans)
     {
         if (!RemoteTrans.ContainsKey(remoteEndPoint.ToString()))
         {
             Console.ForegroundColor = ConsoleColor.Green;
             RemoteTrans.Add(remoteEndPoint.ToString(), request.Header.From.FromURI.User);
             logger.Debug("RemoteTrans Init:Remote:" + remoteEndPoint.ToHost() + "-----User:" + request.Header.From.FromURI.User);
             Console.ForegroundColor = ConsoleColor.White;
         }
     }
 }
        public bool AuthenticateCall()
        {
            m_isAuthenticated = false;

            try
            {
                if (m_sipAccount == null)
                {
                    logger.LogWarning($"Rejecting authentication required call for {m_uasTransaction.TransactionRequestFrom}, SIP account not found.");
                    Reject(SIPResponseStatusCodesEnum.Forbidden, null, null);
                }
                else
                {
                    SIPRequest  sipRequest       = m_uasTransaction.TransactionRequest;
                    SIPEndPoint localSIPEndPoint = (!sipRequest.Header.ProxyReceivedOn.IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(sipRequest.Header.ProxyReceivedOn) : sipRequest.LocalSIPEndPoint;
                    SIPEndPoint remoteEndPoint   = (!sipRequest.Header.ProxyReceivedFrom.IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(sipRequest.Header.ProxyReceivedFrom) : sipRequest.RemoteSIPEndPoint;

                    var authenticationResult = SIPRequestAuthenticator.AuthenticateSIPRequest(localSIPEndPoint, remoteEndPoint, sipRequest, m_sipAccount);
                    if (authenticationResult.Authenticated)
                    {
                        if (authenticationResult.WasAuthenticatedByIP)
                        {
                            logger.LogDebug("New call from " + remoteEndPoint.ToString() + " successfully authenticated by IP address.");
                        }
                        else
                        {
                            logger.LogDebug("New call from " + remoteEndPoint.ToString() + " successfully authenticated by digest.");
                        }

                        m_isAuthenticated = true;
                    }
                    else
                    {
                        // Send authorisation failure or required response
                        SIPResponse authReqdResponse = SIPResponse.GetResponse(sipRequest, authenticationResult.ErrorResponse, null);
                        authReqdResponse.Header.AuthenticationHeader = authenticationResult.AuthenticationRequiredHeader;
                        logger.LogWarning($"Call not authenticated for {m_sipAccount.SIPUsername}@{m_sipAccount.SIPDomain}, responding with {authenticationResult.ErrorResponse}.");
                        m_uasTransaction.SendFinalResponse(authReqdResponse);
                    }
                }
            }
            catch (Exception excp)
            {
                logger.LogError("Exception SIPServerUserAgent AuthenticateCall. " + excp.Message);
                Reject(SIPResponseStatusCodesEnum.InternalServerError, null, null);
            }

            return(m_isAuthenticated);
        }
        public void GotResponse(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPResponse sipResponse)
        {
            if (m_transactionState == SIPTransactionStatesEnum.Completed ||
                m_transactionState == SIPTransactionStatesEnum.Confirmed)
            {
                FireTransactionTraceMessage("Received Duplicate Response " + localSIPEndPoint.ToString() + "<-" +
                                            remoteEndPoint + m_crLF + sipResponse.ToString());

                if (sipResponse.Header.CSeqMethod == SIPMethodsEnum.INVITE)
                {
                    if (sipResponse.StatusCode >= 100 && sipResponse.StatusCode <= 199)
                    {
                        // Ignore info response on completed transaction.
                    }
                    else
                    {
                        ResendAckRequest();
                    }
                }

                TransactionDuplicateResponse?.Invoke(localSIPEndPoint, remoteEndPoint, this, sipResponse);
            }
            else
            {
                FireTransactionTraceMessage("Received Response " + localSIPEndPoint.ToString() + "<-" + remoteEndPoint +
                                            m_crLF + sipResponse.ToString());

                if (sipResponse.StatusCode >= 100 && sipResponse.StatusCode <= 199)
                {
                    UpdateTransactionState(SIPTransactionStatesEnum.Proceeding);

                    if (sipResponse.Header.CSeqMethod == SIPMethodsEnum.INVITE)
                    {
                        //ignore the respose of 100 trying
                    }
                    else
                    {
                        TransactionInformationResponseReceived?.Invoke(localSIPEndPoint, remoteEndPoint, this,
                                                                       sipResponse);
                    }
                }
                else
                {
                    m_transactionFinalResponse = sipResponse;
                    UpdateTransactionState(SIPTransactionStatesEnum.Completed);
                    TransactionFinalResponseReceived?.Invoke(localSIPEndPoint, remoteEndPoint, this, sipResponse);
                }
            }
        }
        public override string ToCSV()
        {
            try
            {
                string serverEndPointValue = (ServerEndPoint != null) ? ServerEndPoint.ToString() : null;
                string remoteEndPointValue = (RemoteEndPoint != null) ? RemoteEndPoint.ToString() : null;
                string dstEndPointValue    = (DestinationEndPoint != null) ? DestinationEndPoint.ToString() : null;

                string csvEvent =
                    SERIALISATION_PREFIX + "|" +
                    SessionID + "|" +
                    MonitorServerID + "|" +
                    ServerType + "|" +
                    EventType + "|" +
                    Created.ToString(SERIALISATION_DATETIME_FORMAT) + "|" +
                    serverEndPointValue + "|" +
                    remoteEndPointValue + "|" +
                    dstEndPointValue + "|" +
                    Username + "|" +
                    ProcessID + "|" +
                    Message + END_MESSAGE_DELIMITER;

                return(csvEvent);
            }
            catch (Exception excp)
            {
                Logger.Logger.Error("Exception SIPMonitorConsoleEvent ToCSV. ->" + excp.Message);
                return(null);
            }
        }
Beispiel #9
0
 public void DispatchRequest(SIPEndPoint dispatchEndPoint, SIPRequest sipRequest)
 {
     FireProxyLogEvent(new SIPMonitorControlClientEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "Dispatching new " + sipRequest.Method + " request to " + dispatchEndPoint.ToString() + ", callid=" + sipRequest.Header.CallId + ".", null));
     m_callIdEndPoints.Add(sipRequest.Header.CallId, dispatchEndPoint.ToString());
     m_callIdAddedAt.Add(sipRequest.Header.CallId, DateTime.Now);
     m_sipTransport.SendRequest(dispatchEndPoint, sipRequest);
 }
Beispiel #10
0
        private static void SIPTransportRequestReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest)
        {
            if (sipRequest.Method == SIPMethodsEnum.INVITE)
            {
                Console.WriteLine("INVITE received from  " + localSIPEndPoint.ToString());
                IPEndPoint sipPhoneEndPoint = SDP.GetSDPRTPEndPoint(sipRequest.Body);

                UASInviteTransaction uasTransaction = m_sipTransport.CreateUASTransaction(sipRequest, remoteEndPoint, localSIPEndPoint, null);
                SIPServerUserAgent   uas            = new SIPServerUserAgent(m_sipTransport, null, null, null, SIPCallDirection.In, null, null, null, uasTransaction);

                SIPResponse tryingResponse = SIPTransport.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Trying, null);
                uasTransaction.SendInformationalResponse(tryingResponse);

                if (m_xmppClient == null)
                {
                    m_xmppClient = new XMPPClient(XMPP_SERVER, XMPP_SERVER_PORT, XMPP_REALM, m_xmppUsername, m_xmppPassword);
                    m_xmppClient.Disconnected += XMPPDisconnected;
                    m_xmppClient.IsBound      += () => { XMPPPlaceCall(uas); };
                    ThreadPool.QueueUserWorkItem(delegate { m_xmppClient.Connect(); });
                }
                else
                {
                    XMPPPlaceCall(uas);
                }
            }
            else if (sipRequest.Method == SIPMethodsEnum.CANCEL)
            {
                UASInviteTransaction inviteTransaction = (UASInviteTransaction)m_sipTransport.GetTransaction(SIPTransaction.GetRequestTransactionId(sipRequest.Header.Vias.TopViaHeader.Branch, SIPMethodsEnum.INVITE));

                if (inviteTransaction != null)
                {
                    Console.WriteLine("Matching CANCEL request received " + sipRequest.URI.ToString() + ".");
                    SIPCancelTransaction cancelTransaction = m_sipTransport.CreateCancelTransaction(sipRequest, remoteEndPoint, localSIPEndPoint, inviteTransaction);
                    cancelTransaction.GotRequest(localSIPEndPoint, remoteEndPoint, sipRequest);
                }
                else
                {
                    Console.WriteLine("No matching transaction was found for CANCEL to " + sipRequest.URI.ToString() + ".");
                    SIPResponse noCallLegResponse = SIPTransport.GetResponse(sipRequest, SIPResponseStatusCodesEnum.CallLegTransactionDoesNotExist, null);
                    m_sipTransport.SendResponse(noCallLegResponse);
                }
            }
            else if (sipRequest.Method == SIPMethodsEnum.BYE)
            {
                Console.WriteLine("BYE request received.");

                if (m_activeCalls.ContainsKey(sipRequest.Header.CallId))
                {
                    SIPResponse okResponse = SIPTransport.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Ok, null);
                    m_sipTransport.SendResponse(okResponse);
                    m_activeCalls[sipRequest.Header.CallId].TerminateXMPPCall();
                    m_activeCalls.Remove(sipRequest.Header.CallId);
                }
                else
                {
                    SIPResponse doesntExistResponse = SIPTransport.GetResponse(sipRequest, SIPResponseStatusCodesEnum.CallLegTransactionDoesNotExist, null);
                    m_sipTransport.SendResponse(doesntExistResponse);
                }
            }
        }
        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 SIPRegistrarBinding RefreshBinding(
            Guid id,
            int expiry,
            SIPEndPoint remoteSIPEndPoint,
            SIPEndPoint proxySIPEndPoint,
            SIPEndPoint registrarSIPEndPoint,
            bool dontMangle)
        {
            using (var db = new SIPAssetsDbContext())
            {
                var existing = db.SIPRegistrarBindings.Where(x => x.ID == id).SingleOrDefault();

                if (existing == null)
                {
                    throw new ApplicationException("The SIP Registrar Binding to update could not be found.");
                }

                existing.LastUpdate         = DateTime.UtcNow;
                existing.Expiry             = expiry;
                existing.ExpiryTime         = DateTime.UtcNow.AddSeconds(expiry);
                existing.RemoteSIPSocket    = remoteSIPEndPoint?.ToString();
                existing.ProxySIPSocket     = proxySIPEndPoint?.ToString();
                existing.RegistrarSIPSocket = registrarSIPEndPoint?.ToString();

                db.SaveChanges();

                return(existing);
            }
        }
Beispiel #13
0
        public void Dispatch(SIPEndPoint remoteEndPoint, SIPResponse sipResponse)
        {
            try {
                //logger.Debug("Dispatch SIPResponse from " + remoteEndPoint + " " + sipResponse.Header.CSeqMethod + " " + sipResponse.StatusCode + ".");
                SIPEndPoint dispatchEndPoint = m_outboundProxy;

                if (remoteEndPoint.ToString() == m_outboundProxy.ToString())
                {
                    if (m_callIdEndPoints.ContainsKey(sipResponse.Header.CallId))
                    {
                        dispatchEndPoint = SIPEndPoint.ParseSIPEndPoint(m_callIdEndPoints[sipResponse.Header.CallId]);
                    }
                    else
                    {
                        dispatchEndPoint = null;
                    }
                }

                if (dispatchEndPoint != null)
                {
                    m_sipTransport.SendResponse(dispatchEndPoint, sipResponse);
                }
                else
                {
                    FireProxyLogEvent(new SIPMonitorControlClientEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.DialPlan, "The callid for an " + sipResponse.Header.CSeqMethod + " response was not found in the dispatcher callids lookup table, dropping, callid=" + sipResponse.Header.CallId + ".", null));
                }
            }
            catch (Exception excp) {
                logger.Error("Exception Dispatch SIPResponse. " + excp.Message);
                throw;
            }
        }
        public void GotRequest(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest)
        {
            FireTransactionTraceMessage("Received Request " + localSIPEndPoint.ToString() + "<-" +
                                        remoteEndPoint.ToString() + m_crLF + sipRequest.ToString());

            TransactionRequestReceived?.Invoke(localSIPEndPoint, remoteEndPoint, this, sipRequest);
        }
Beispiel #15
0
        private void LogSIPRequestOut(SIPEndPoint localSIPEndPoint, SIPEndPoint endPoint, SIPRequest sipRequest)
        {
            string message = "Proxy Request Sent: " + localSIPEndPoint.ToString() + "->" + endPoint.ToString() + "\r\n" + sipRequest.ToString();
            //logger.Debug("pr: 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.SIPProxy, SIPMonitorEventTypesEnum.FullSIPTrace, message, fromUser, localSIPEndPoint, endPoint));
        }
        private void LogSIPRequestIn(SIPEndPoint localSIPEndPoint, SIPEndPoint endPoint, SIPRequest sipRequest)
        {
            string message = "App Svr Received: " + localSIPEndPoint.ToString() + "<-" + endPoint.ToString() + "\r\n" + sipRequest.ToString();
            //logger.Debug("as: 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.AppServer, SIPMonitorEventTypesEnum.FullSIPTrace, message, fromUser, localSIPEndPoint, endPoint));
        }
        private void LogSIPResponseOut(SIPEndPoint localSIPEndPoint, SIPEndPoint endPoint, SIPResponse sipResponse)
        {
            string message = "App Svr Sent: " + localSIPEndPoint.ToString() + "->" + endPoint.ToString() + "\r\n" + sipResponse.ToString();
            //logger.Debug("as: response out " + sipResponse.Header.CSeqMethod + " " + localSIPEndPoint.ToString() + "->" + endPoint.ToString() + ", callid=" + sipResponse.Header.CallId + ".");
            string fromUser = (sipResponse.Header.From != null && sipResponse.Header.From.FromURI != null) ? sipResponse.Header.From.FromURI.User : "******";

            FireSIPMonitorEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.FullSIPTrace, message, fromUser, localSIPEndPoint, endPoint));
        }
        public void UpdateAppServerPriority(SIPEndPoint appServerEndPoint, int priority)
        {
            try
            {
                string appServerEndPointsText = null;
                using (StreamReader sr = new StreamReader(m_appServerEndPointsPath))
                {
                    appServerEndPointsText = sr.ReadToEnd();
                }

                Dictionary <string, int> appServerPriorities = LoadAppServerEndPoints(appServerEndPointsText);

                bool changed = false;

                if (appServerPriorities.ContainsKey(appServerEndPoint.ToString()))
                {
                    if (appServerPriorities[appServerEndPoint.ToString()] != NEVERUSE_APPSERVER_PRIORITY)
                    {
                        appServerPriorities[appServerEndPoint.ToString()] = priority;
                        logger.Debug("SIPCallDispatcherFile updated priority on " + appServerEndPoint + " to " + priority + ".");
                        changed = true;
                    }
                    else
                    {
                        logger.Debug("SIPCallDispatcherFile did NOT priority on disabled App Server endpoint " + appServerEndPoint + ".");
                    }
                }

                if (changed)
                {
                    using (StreamWriter sw = new StreamWriter(m_appServerEndPointsPath, false, Encoding.ASCII))
                    {
                        foreach (KeyValuePair <string, int> appServerPriority in appServerPriorities)
                        {
                            sw.WriteLine(appServerPriority.Value + "," + appServerPriority.Key);
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception UpdateAppServerPriority. " + excp.Message);
            }
        }
        public void UpdateAppServerPriority(SIPEndPoint appServerEndPoint, int priority)
        {
            try
            {
                string appServerEndPointsText = null;
                using (StreamReader sr = new StreamReader(m_appServerEndPointsPath))
                {
                    appServerEndPointsText = sr.ReadToEnd();
                }

                Dictionary<string, int> appServerPriorities = LoadAppServerEndPoints(appServerEndPointsText);

                    bool changed = false;

                    if (appServerPriorities.ContainsKey(appServerEndPoint.ToString()))
                    {
                        if (appServerPriorities[appServerEndPoint.ToString()] != NEVERUSE_APPSERVER_PRIORITY)
                        {
                            appServerPriorities[appServerEndPoint.ToString()] = priority;
                            logger.Debug("SIPCallDispatcherFile updated priority on " + appServerEndPoint + " to " + priority + ".");
                            changed = true;
                        }
                        else
                        {
                            logger.Debug("SIPCallDispatcherFile did NOT priority on disabled App Server endpoint " + appServerEndPoint + ".");
                        }
                    }

                    if (changed)
                    {
                        using (StreamWriter sw = new StreamWriter(m_appServerEndPointsPath, false, Encoding.ASCII))
                        {
                            foreach (KeyValuePair<string, int> appServerPriority in appServerPriorities)
                            {
                                sw.WriteLine(appServerPriority.Value + "," + appServerPriority.Key);
                            }
                        }
                    }
            }
            catch (Exception excp)
            {
                logger.Error("Exception UpdateAppServerPriority. " + excp.Message);
            }
        }
Beispiel #20
0
        private void LogSIPBadRequestIn(SIPEndPoint localSIPEndPoint, SIPEndPoint remotePoint, string message, SIPValidationFieldsEnum errorField, string rawMessage)
        {
            string errorMessage = "Proxy Bad Request In: " + localSIPEndPoint.ToString() + "<-" + remotePoint.ToString() + ". " + errorField + ". " + message;

            FireSIPMonitorEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.SIPProxy, SIPMonitorEventTypesEnum.BadSIPMessage, errorMessage, null));
            if (rawMessage != null)
            {
                FireSIPMonitorEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.SIPProxy, SIPMonitorEventTypesEnum.FullSIPTrace, errorMessage + "\r\n" + rawMessage, null));
            }
        }
 public bool IsAppServerEndPoint(SIPEndPoint remoteEndPoint)
 {
     if (m_appServerEndPoints == null || m_appServerEndPoints.Count == 0)
     {
         return false;
     }
     else
     {
         return m_appServerEndPoints.ContainsKey(remoteEndPoint.ToString());
     }
 }
 public bool IsAppServerEndPoint(SIPEndPoint remoteEndPoint)
 {
     if (m_appServerEndPoints == null || m_appServerEndPoints.Count == 0)
     {
         return(false);
     }
     else
     {
         return(m_appServerEndPoints.ContainsKey(remoteEndPoint.ToString()));
     }
 }
Beispiel #23
0
        public SIPRegistrarBinding(
            SIPAccount sipAccount,
            SIPURI bindingURI,
            string callId,
            int cseq,
            string userAgent,
            SIPEndPoint remoteSIPEndPoint,
            SIPEndPoint proxySIPEndPoint,
            SIPEndPoint registrarSIPEndPoint,
            int expirySeconds)
        {
            ID           = Guid.NewGuid();
            LastUpdate   = DateTime.UtcNow;
            SIPAccountID = sipAccount.ID;
            //sipaccountname = sipAccount.sipusername + "@" + sipAccount.domain.domain;
            ContactURI = bindingURI.ToString();
            //m_mangledContactURI = m_contactURI.CopyOf();
            CallId                 = callId;
            CSeq                   = cseq;
            UserAgent              = userAgent;
            RemoteSIPEndPoint      = remoteSIPEndPoint;
            m_proxySIPEndPoint     = proxySIPEndPoint;
            m_registrarSIPEndPoint = registrarSIPEndPoint;

            ProxySIPSocket     = proxySIPEndPoint?.ToString();
            RemoteSIPSocket    = remoteSIPEndPoint.ToString();
            RegistrarSIPSocket = registrarSIPEndPoint?.ToString();
            LastUpdate         = DateTime.UtcNow;

            //if (SIPTransport.IsPrivateAddress(sipRequest.Header.Contact[0].ContactURI.Host) && m_mangleUACContact)
            //if (!sipAccount.DontMangleEnabled && Regex.Match(m_mangledContactURI.Host, @"(\d+\.){3}\d+").Success)
            //{
            //    // The Contact URI Host is used by registrars as the contact socket for the user so it needs to be changed to reflect the socket
            //    // the intial request was received on in order to work around NAT. It's no good just relying on private addresses as a lot of User Agents
            //    // determine their public IP but NOT their public port so they send the wrong port in the Contact header.

            //    //logger.Debug("Mangling contact header from " + m_mangledContactURI.Host + " to " + IPSocket.GetSocketString(uacRecvdEndPoint) + ".");

            //    m_mangledContactURI.Host = remoteSIPEndPoint.GetIPEndPoint().ToString();
            //}

            Expiry = expirySeconds;

            if (expirySeconds > 0)
            {
                ExpiryTime = DateTime.Now.AddSeconds(expirySeconds);
            }
            else
            {
                ExpiryTime = DateTime.UtcNow;
            }
        }
Beispiel #24
0
        public void HostAndPortParseTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "10.0.0.100:5065";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            Console.WriteLine("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.True(sipEndPoint.Protocol == SIPProtocolsEnum.udp, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.ToString() == "10.0.0.100", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.True(sipEndPoint.Port == 5065, "The SIPEndPoint port was incorrectly parsed.");
        }
Beispiel #25
0
        public void IPv6LoopbackAndSchemeParseTest()
        {
            logger.LogDebug(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "udp:[::1]";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            logger.LogDebug("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.True(sipEndPoint.Protocol == SIPProtocolsEnum.udp, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.ToString() == "::1", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.True(sipEndPoint.Port == 5060, "The SIPEndPoint port was incorrectly parsed.");
        }
Beispiel #26
0
        public void SchemeHostTransportParseTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "sip:10.0.0.100:5063;lr;tag=123;transport=tcp;tag2=abcd";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            Console.WriteLine("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.True(sipEndPoint.Protocol == SIPProtocolsEnum.tcp, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.ToString() == "10.0.0.100", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.True(sipEndPoint.Port == 5063, "The SIPEndPoint port was incorrectly parsed.");
        }
Beispiel #27
0
        public void SecureWebSocketLoopbackAndPortParseTest()
        {
            logger.LogDebug(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "wss:[fe80::54a9:d238:b2ee:ceb]:7060";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            logger.LogDebug("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.True(sipEndPoint.Protocol == SIPProtocolsEnum.wss, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.ToString() == "fe80::54a9:d238:b2ee:ceb", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6, "The SIPEndPoint IP address family was incorrectly parsed.");
            Assert.True(sipEndPoint.Port == 7060, "The SIPEndPoint port was incorrectly parsed.");
        }
Beispiel #28
0
        public void HostOnlyParseTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "10.0.0.100";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            logger.LogDebug("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.True(sipEndPoint.Protocol == SIPProtocolsEnum.udp, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.ToString() == "10.0.0.100", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.True(sipEndPoint.Port == 5060, "The SIPEndPoint port was incorrectly parsed.");
        }
Beispiel #29
0
        public void IPv6LoopbackWithScehemeParseTest()
        {
            logger.LogDebug(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "sip:[::1]:6060";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            logger.LogDebug("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.True(sipEndPoint.Protocol == SIPProtocolsEnum.udp, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.ToString() == "::1", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6, "The SIPEndPoint IP address family was incorrectly parsed.");
            Assert.True(sipEndPoint.Port == 6060, "The SIPEndPoint port was incorrectly parsed.");
        }
Beispiel #30
0
        public void WebSocketLoopbackAndPortParseTest()
        {
            logger.LogDebug(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "ws:[::1]:6060";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            logger.LogDebug("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.AreEqual(sipEndPoint.Protocol, SIPProtocolsEnum.ws, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.AreEqual(sipEndPoint.Address.ToString(), "::1", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.AreEqual(sipEndPoint.Address.AddressFamily, System.Net.Sockets.AddressFamily.InterNetworkV6, "The SIPEndPoint IP address family was incorrectly parsed.");
            Assert.AreEqual(sipEndPoint.Port, 6060, "The SIPEndPoint port was incorrectly parsed.");
        }
Beispiel #31
0
        public void IPv6WithConnectionAndChannelIDParseTest()
        {
            logger.LogDebug(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "udp:[::1];cid=123;xid=1234567";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            logger.LogDebug("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.True(sipEndPoint.Protocol == SIPProtocolsEnum.udp, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.True(sipEndPoint.Address.ToString() == "::1", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.True(sipEndPoint.Port == 5060, "The SIPEndPoint port was incorrectly parsed.");
            Assert.True(sipEndPoint.ChannelID == "123", "The SIPEndPoint channel ID was incorrectly parsed.");
            Assert.True(sipEndPoint.ConnectionID == "1234567", "The SIPEndPoint connection ID was incorrectly parsed.");
        }
        public void AllFieldsParseTest()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string      sipEndPointStr = "sips:10.0.0.100:5060;lr;transport=tcp;";
            SIPEndPoint sipEndPoint    = SIPEndPoint.ParseSIPEndPoint(sipEndPointStr);

            Console.WriteLine("SIPEndPoint=" + sipEndPoint.ToString() + ".");

            Assert.IsTrue(sipEndPoint.Protocol == SIPProtocolsEnum.tls, "The SIPEndPoint protocol was incorrectly parsed.");
            Assert.IsTrue(sipEndPoint.Address.ToString() == "10.0.0.100", "The SIPEndPoint IP address was incorrectly parsed.");
            Assert.IsTrue(sipEndPoint.Port == 5060, "The SIPEndPoint port was incorrectly parsed.");

            Assert.IsTrue(true, "True was false.");
        }
        public SIPReferClientUserAgent(
            SIPTransport sipTransport,
            SIPEndPoint outboundProxy,
            string owner,
            string adminMemberId,
            SIPMonitorLogDelegate logDelegate)
        {
            m_sipTransport = sipTransport;
            m_outboundProxy = (outboundProxy != null) ? SIPEndPoint.ParseSIPEndPoint(outboundProxy.ToString()) : null;
            Owner = owner;
            AdminMemberId = adminMemberId;
            Log_External = logDelegate;

            // If external logging is not required assign an empty handler to stop null reference exceptions.
            if (Log_External == null)
            {
                Log_External = (e) => { };
            }
        }