private SIPRequest GetDummyINVITERequest(SIPURI dummyURI)
        {
            string     dummyFrom     = "<sip:[email protected]>";
            SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, dummyURI);

            SIPHeader inviteHeader = new SIPHeader(SIPFromHeader.ParseFromHeader(dummyFrom), new SIPToHeader(null, dummyURI, null), 1, CallProperties.CreateNewCallId());

            inviteHeader.From.FromTag = CallProperties.CreateNewTag();
            inviteHeader.Contact      = new List <SIPContactHeader> {
                SIPContactHeader.GetDefaultSIPContactHeader(inviteRequest.URI.Scheme)
            };
            inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE;
            inviteHeader.UserAgent  = "unittest";
            inviteRequest.Header    = inviteHeader;

            SIPViaHeader viaHeader = SIPViaHeader.GetDefaultSIPViaHeader();

            inviteRequest.Header.Vias.PushViaHeader(viaHeader);

            inviteRequest.Body = "dummy";
            inviteRequest.Header.ContentLength = inviteRequest.Body.Length;
            inviteRequest.Header.ContentType   = "application/sdp";

            return(inviteRequest);
        }
Ejemplo n.º 2
0
        private SIPRequest GetAuthenticatedRegistrationRequest(SIPRequest registerRequest, SIPResponse sipResponse)
        {
            SIPAuthorisationDigest authRequest = sipResponse.Header.AuthenticationHeader.SIPDigest;
            string username = (m_authUsername != null) ? m_authUsername : m_sipAccountAOR.User;

            authRequest.SetCredentials(username, m_password, registerRequest.URI.ToString(), SIPMethodsEnum.REGISTER.ToString());
            if (!this.m_realm.IsNullOrBlank())
            {
                authRequest.Realm = this.m_realm;
            }

            SIPRequest regRequest = registerRequest.Copy();

            regRequest.SetSendFromHints(registerRequest.LocalSIPEndPoint);

            regRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId();
            regRequest.Header.From.FromTag             = CallProperties.CreateNewTag();
            regRequest.Header.To.ToTag = null;
            regRequest.Header.CSeq     = ++m_cseq;

            regRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authRequest);
            regRequest.Header.AuthenticationHeader.SIPDigest.Response = authRequest.Digest;

            return(regRequest);
        }
        /// <summary>
        /// PTZ云台控制
        /// </summary>
        /// <param name="deviceId">设备ID</param>
        /// <param name="ucommand">控制命令</param>
        /// <param name="dwStop">开始或结束</param>
        /// <param name="dwSpeed">速度</param>
        public void PtzContrl(string deviceId, int ucommand, int dwStop, int dwSpeed)
        {
            if (LocalEndPoint == null)
            {
                OnSIPServiceChange(deviceId, SipServiceStatus.Wait);
                return;
            }
            string     fromTag    = CallProperties.CreateNewTag();
            string     toTag      = CallProperties.CreateNewTag();
            int        cSeq       = CallProperties.CreateNewCSeq();
            string     callId     = CallProperties.CreateNewCallId();
            SIPRequest catalogReq = QueryItems(fromTag, toTag, cSeq, callId);
            string     cmdStr     = GetPtzCmd(ucommand, dwStop, dwSpeed);

            PTZControl ptz = new PTZControl()
            {
                CommandType = CommandType.DeviceControl,
                DeviceID    = deviceId,
                SN          = new Random().Next(9999),
                PTZCmd      = cmdStr
            };
            string xmlBody = PTZControl.Instance.Save <PTZControl>(ptz);

            catalogReq.Body = xmlBody;
            Transport.SendRequest(RemoteEndPoint, catalogReq);
            _catalogTask             = new TaskTiming(catalogReq, Transport);
            this.SendRequestTimeout += _catalogTask.MessageSendRequestTimeout;
            _catalogTask.Start();
        }
        /// <summary>
        /// 设备目录查询
        /// </summary>
        /// <param name="deviceId">目的设备编码</param>
        public void DeviceCatalogQuery(string deviceId)
        {
            if (LocalEndPoint == null)
            {
                OnSIPServiceChange(deviceId, SipServiceStatus.Wait);
                return;
            }
            string       fromTag    = CallProperties.CreateNewTag();
            string       toTag      = CallProperties.CreateNewTag();
            int          cSeq       = CallProperties.CreateNewCSeq();
            string       callId     = CallProperties.CreateNewCallId();
            SIPRequest   catalogReq = QueryItems(fromTag, toTag, cSeq, callId);
            CatalogQuery catalog    = new CatalogQuery()
            {
                CommandType = CommandType.Catalog,
                DeviceID    = deviceId,
                SN          = new Random().Next(9999)
            };
            string xmlBody = CatalogQuery.Instance.Save <CatalogQuery>(catalog);

            catalogReq.Body = xmlBody;
            Transport.SendRequest(RemoteEndPoint, catalogReq);
            _catalogTask             = new TaskTiming(catalogReq, Transport);
            this.SendRequestTimeout += _catalogTask.MessageSendRequestTimeout;
            _catalogTask.Start();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 暂停录像播放
        /// </summary>
        public void BackVideoPauseControlReq()
        {
            if (_msgCore.LocalEndPoint == null)
            {
                OnSIPServiceChange(_deviceName + "-" + _deviceId, SipServiceStatus.Wait);
                return;
            }
            if (_mediaPort == null)
            {
                _mediaPort = _msgCore.SetMediaPort();
            }

            string localIp = _msgCore.LocalEndPoint.Address.ToString();
            string fromTag = CallProperties.CreateNewTag();
            int    cSeq    = CallProperties.CreateNewCSeq();
            string callId  = CallProperties.CreateNewCallId();
            //this.Stop();
            SIPRequest realReq = BackVideoPauseControlReq(localIp, _mediaPort, fromTag, cSeq, callId);

            _msgCore.Transport.SendRequest(_msgCore.RemoteEndPoint, realReq);
            _realTask = new TaskTiming(realReq, _msgCore.Transport);
            _msgCore.SendRequestTimeout += _realTask.MessageSendRequestTimeout;
            _realTask.OnCloseRTPChannel += Task_OnCloseRTPChannel;
            _realTask.Start();
        }
        private SIPRequest GetRegistrationRequest()
        {
            SIPURI registerURI = m_sipAccountAOR.CopyOf();

            registerURI.User = null;

            SIPRequest registerRequest = SIPRequest.GetRequest(
                SIPMethodsEnum.REGISTER,
                registerURI,
                new SIPToHeader(this.UserDisplayName, m_sipAccountAOR, null),
                new SIPFromHeader(this.UserDisplayName, m_sipAccountAOR, CallProperties.CreateNewTag()));

            registerRequest.Header.Contact = new List <SIPContactHeader> {
                new SIPContactHeader(this.UserDisplayName, m_contactURI)
            };
            registerRequest.Header.CSeq      = ++m_cseq;
            registerRequest.Header.CallId    = m_callID;
            registerRequest.Header.UserAgent = (!UserAgent.IsNullOrBlank()) ? UserAgent : SIPConstants.SipUserAgentVersionString;
            registerRequest.Header.Expires   = m_expiry;

            if (m_customHeaders != null && m_customHeaders.Length > 0)
            {
                foreach (var header in m_customHeaders)
                {
                    registerRequest.Header.UnknownHeaders.Add(header);
                }
            }

            if (AdjustRegister == null)
            {
                return(registerRequest);
            }

            return(AdjustRegister(registerRequest));
        }
Ejemplo n.º 7
0
        public SIPRequest GetRegisterRequest(string server, string toURIStr, string contactStr)
        {
            try
            {
                IPEndPoint localSIPEndPoint = m_sipTransport.GetDefaultTransportContact(SIPProtocolsEnum.UDP);

                SIPRequest registerRequest = new SIPRequest(SIPMethodsEnum.REGISTER, "sip:" + server);
                SIPHeader  registerHeader  = new SIPHeader(SIPFromHeader.ParseFromHeader(toURIStr), SIPToHeader.ParseToHeader(toURIStr), 1, CallProperties.CreateNewCallId());
                registerHeader.From.FromTag = CallProperties.CreateNewTag();
                registerHeader.Contact      = SIPContactHeader.ParseContactHeader(contactStr);
                SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId());
                registerHeader.Via.PushViaHeader(viaHeader);
                registerHeader.CSeqMethod = SIPMethodsEnum.REGISTER;
                registerHeader.Expires    = SIPConstants.DEFAULT_REGISTEREXPIRY_SECONDS;

                registerRequest.Header = registerHeader;

                return(registerRequest);
            }
            catch (Exception excp)
            {
                logger.Error("Exception GetRegisterRequest. " + excp.Message);
                throw new ApplicationException("GetRegisterRequest " + excp.GetType().ToString() + ".  " + excp.Message);
            }
        }
        private SIPRequest GetAuthenticatedRegistrationRequest(SIPRequest registerRequest, SIPResponse sipResponse)
        {
            try
            {
                SIPAuthorisationDigest authRequest = sipResponse.Header.AuthenticationHeader.SIPDigest;
                string username = (m_authUsername != null) ? m_authUsername : m_sipAccountAOR.User;
                authRequest.SetCredentials(username, m_password, registerRequest.URI.ToString(), SIPMethodsEnum.REGISTER.ToString());

                SIPRequest regRequest = registerRequest.Copy();
                regRequest.LocalSIPEndPoint = registerRequest.LocalSIPEndPoint;
                regRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId();
                regRequest.Header.From.FromTag             = CallProperties.CreateNewTag();
                regRequest.Header.To.ToTag = null;
                regRequest.Header.CSeq     = ++m_cseq;

                regRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authRequest);
                regRequest.Header.AuthenticationHeader.SIPDigest.Response = authRequest.Digest;

                return(regRequest);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception GetAuthenticatedRegistrationRequest. " + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 查询设备目录请求
        /// </summary>
        /// <returns></returns>
        private SIPRequest QueryItems(SIPEndPoint remoteEndPoint, string remoteSIPId)
        {
            string fromTag = CallProperties.CreateNewTag();
            string toTag   = CallProperties.CreateNewTag();
            int    cSeq    = CallProperties.CreateNewCSeq();
            string callId  = CallProperties.CreateNewCallId();

            SIPURI        remoteUri = new SIPURI(RemoteSIPId, RemoteEndPoint.ToHost(), "");
            SIPURI        localUri  = new SIPURI(LocalSIPId, LocalEndPoint.ToHost(), "");
            SIPFromHeader from      = new SIPFromHeader(null, localUri, fromTag);
            //SIPToHeader to = new SIPToHeader(null, remoteUri, toTag);
            SIPToHeader to         = new SIPToHeader(null, remoteUri, null);
            SIPRequest  catalogReq = Transport.GetRequest(SIPMethodsEnum.MESSAGE, remoteUri);

            catalogReq.Header.From        = from;
            catalogReq.Header.Contact     = null;
            catalogReq.Header.Allow       = null;
            catalogReq.Header.To          = to;
            catalogReq.Header.UserAgent   = UserAgent;
            catalogReq.Header.CSeq        = cSeq;
            catalogReq.Header.CallId      = callId;
            catalogReq.Header.ContentType = "application/MANSCDP+xml";

            return(catalogReq);
        }
Ejemplo n.º 10
0
        private SIPRequest GetRegistrationRequest()
        {
            try
            {
                SIPURI registerURI = m_sipAccountAOR.CopyOf();
                registerURI.User = null;

                SIPRequest registerRequest = SIPRequest.GetRequest(
                    SIPMethodsEnum.REGISTER,
                    registerURI,
                    new SIPToHeader(this.UserDisplayName, m_sipAccountAOR, null),
                    new SIPFromHeader(this.UserDisplayName, m_sipAccountAOR, CallProperties.CreateNewTag()));

                registerRequest.Header.Contact = new List <SIPContactHeader> {
                    new SIPContactHeader(this.UserDisplayName, m_contactURI)
                };
                registerRequest.Header.CSeq      = ++m_cseq;
                registerRequest.Header.CallId    = m_callID;
                registerRequest.Header.UserAgent = (!UserAgent.IsNullOrBlank()) ? UserAgent : m_userAgent;
                registerRequest.Header.Expires   = m_expiry;

                return(registerRequest);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception GetRegistrationRequest. " + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// PTZ云台控制
        /// </summary>
        /// <param name="ucommand">控制命令</param>
        /// <param name="dwStop">开始或结束</param>
        /// <param name="dwSpeed">速度</param>
        public void PtzContrl(int ucommand, int dwStop, int dwSpeed)
        {
            lock (_msgCore.RemoteTrans)
            {
                if (!_msgCore.RemoteTrans.ContainsKey(_remoteEndPoint.ToString()))
                {
                    OnSIPServiceChange(_deviceName + "-" + _deviceId + _remoteEndPoint.ToString(), SipServiceStatus.Wait);
                    return;
                }
            }

            string     fromTag    = CallProperties.CreateNewTag();
            string     toTag      = CallProperties.CreateNewTag();
            int        cSeq       = CallProperties.CreateNewCSeq();
            string     callId     = CallProperties.CreateNewCallId();
            SIPRequest catalogReq = PTZRequest(fromTag, toTag, cSeq, callId);
            string     cmdStr     = GetPtzCmd(ucommand, dwStop, dwSpeed);

            PTZControl ptz = new PTZControl()
            {
                CommandType = CommandType.DeviceControl,
                DeviceID    = _deviceId,
                SN          = new Random().Next(9999),
                PTZCmd      = cmdStr
            };
            string xmlBody = PTZControl.Instance.Save <PTZControl>(ptz);

            catalogReq.Body = xmlBody;
            _msgCore.Transport.SendRequest(_remoteEndPoint, catalogReq);
        }
        private SIPResponse GetAuthReqdResponse(SIPRequest sipRequest, string nonce, string realm)
        {
            try
            {
                SIPResponse authReqdResponse =
                    SIPTransport.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Unauthorised, null);
                SIPAuthenticationHeader authHeader =
                    new SIPAuthenticationHeader(SIPAuthorisationHeadersEnum.WWWAuthenticate, realm, nonce);
                SIPHeader requestHeader = sipRequest.Header;
                SIPHeader unauthHeader  = new SIPHeader(requestHeader.Contact, requestHeader.From, requestHeader.To,
                                                        requestHeader.CSeq, requestHeader.CallId);

                if (unauthHeader.To.ToTag == null || unauthHeader.To.ToTag.Trim().Length == 0)
                {
                    unauthHeader.To.ToTag = CallProperties.CreateNewTag();
                }

                unauthHeader.CSeqMethod           = requestHeader.CSeqMethod;
                unauthHeader.Vias                 = requestHeader.Vias;
                unauthHeader.AuthenticationHeader = authHeader;
                //unauthHeader.Server = m_serverAgent;
                unauthHeader.UserAgent   = m_serverAgent;
                unauthHeader.MaxForwards = Int32.MinValue;

                authReqdResponse.Header = unauthHeader;

                return(authReqdResponse);
            }
            catch (Exception excp)
            {
                Logger.Logger.Error("Exception GetAuthReqdResponse. ->" + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 目录订阅请求
        /// </summary>
        /// <returns></returns>
        private SIPRequest SubscribeCatalog(SIPEndPoint remoteEndPoint, string remoteSIPId)
        {
            string fromTag = CallProperties.CreateNewTag();
            int    cSeq    = CallProperties.CreateNewCSeq();
            string callId  = CallProperties.CreateNewCallId();

            SIPURI        remoteUri  = new SIPURI(remoteSIPId, remoteEndPoint.ToHost(), "");
            SIPURI        localUri   = new SIPURI(LocalSIPId, LocalEP.ToHost(), "");
            SIPFromHeader from       = new SIPFromHeader(null, localUri, fromTag);
            SIPToHeader   to         = new SIPToHeader(null, remoteUri, null);
            SIPRequest    catalogReq = _transport.GetRequest(SIPMethodsEnum.SUBSCRIBE, remoteUri);

            catalogReq.Header.From    = from;
            catalogReq.Header.Contact = new List <SIPContactHeader>
            {
                new SIPContactHeader(null, localUri)
            };
            catalogReq.Header.Allow       = null;
            catalogReq.Header.To          = to;
            catalogReq.Header.UserAgent   = SIPConstants.SIP_USERAGENT_STRING;
            catalogReq.Header.Event       = "Catalog";//"presence";//"Catalog;id=1894";
            catalogReq.Header.Expires     = 60000;
            catalogReq.Header.CSeq        = cSeq;
            catalogReq.Header.CallId      = callId;
            catalogReq.Header.ContentType = "application/MANSCDP+xml";//"Application/MANSCDP+xml"

            return(catalogReq);
        }
Ejemplo n.º 14
0
            private SIPRequest GetDummyINVITERequest(SIPURI dummyURI)
            {
                string     dummyFrom     = "<sip:[email protected]>";
                string     dummyContact  = "sip:127.0.0.1:1234";
                SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, dummyURI);

                SIPHeader inviteHeader =
                    new SIPHeader(SIPFromHeader.ParseFromHeader(dummyFrom), new SIPToHeader(null, dummyURI, null), 1, CallProperties.CreateNewCallId());

                inviteHeader.From.FromTag = CallProperties.CreateNewTag();
                inviteHeader.Contact      = SIPContactHeader.ParseContactHeader(dummyContact);
                inviteHeader.CSeqMethod   = SIPMethodsEnum.INVITE;
                inviteHeader.UserAgent    = "unittest";
                inviteRequest.Header      = inviteHeader;

                SIPViaHeader viaHeader =
                    new SIPViaHeader("127.0.0.1", 1234, CallProperties.CreateBranchId(), SIPProtocolsEnum.udp);

                inviteRequest.Header.Vias.PushViaHeader(viaHeader);

                inviteRequest.Body = "dummy";
                inviteRequest.Header.ContentLength = inviteRequest.Body.Length;
                inviteRequest.Header.ContentType   = "application/sdp";

                return(inviteRequest);
            }
        private SIPRequest GetRequest(SIPMethodsEnum method)
        {
            try
            {
                SIPURI uri = SIPURI.ParseSIPURIRelaxed(m_callDescriptor.Uri);

                SIPRequest    request    = new SIPRequest(method, uri);
                SIPFromHeader fromHeader = m_callDescriptor.GetFromHeader();
                fromHeader.FromTag = CallProperties.CreateNewTag();
                SIPToHeader toHeader = new SIPToHeader(null, uri, null);
                int         cseq     = Crypto.GetRandomInt(10000, 20000);

                SIPHeader header = new SIPHeader(fromHeader, toHeader, cseq, CallProperties.CreateNewCallId());
                header.CSeqMethod = method;
                header.UserAgent  = m_userAgent;
                request.Header    = header;

                header.Vias.PushViaHeader(SIPViaHeader.GetDefaultSIPViaHeader());

                try
                {
                    if (m_callDescriptor.CustomHeaders != null && m_callDescriptor.CustomHeaders.Count > 0)
                    {
                        foreach (string customHeader in m_callDescriptor.CustomHeaders)
                        {
                            if (customHeader.IsNullOrBlank())
                            {
                                continue;
                            }
                            else if (customHeader.Trim().StartsWith(SIPHeaders.SIP_HEADER_USERAGENT))
                            {
                                request.Header.UserAgent = customHeader.Substring(customHeader.IndexOf(":") + 1).Trim();
                            }
                            else
                            {
                                request.Header.UnknownHeaders.Add(customHeader);
                            }
                        }
                    }
                }
                catch (Exception excp)
                {
                    logger.LogError("Exception Parsing CustomHeader for SIPNonInviteClientUserAgent GetRequest. " + excp.Message + m_callDescriptor.CustomHeaders);
                }

                if (!m_callDescriptor.Content.IsNullOrBlank())
                {
                    request.Body = m_callDescriptor.Content;
                    request.Header.ContentType   = m_callDescriptor.ContentType;
                    request.Header.ContentLength = request.Body.Length;
                }

                return(request);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception SIPNonInviteClientUserAgent GetRequest. " + excp.Message);
                throw;
            }
        }
Ejemplo n.º 16
0
        private SIPResponse GetResponse(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPResponseStatusCodesEnum responseCode, string reasonPhrase, SIPRequest request)
        {
            try
            {
                SIPResponse    response  = new SIPResponse(responseCode, reasonPhrase, localSIPEndPoint);
                SIPSchemesEnum sipScheme = (localSIPEndPoint.Protocol == SIPProtocolsEnum.tls) ? SIPSchemesEnum.sips : SIPSchemesEnum.sip;
                SIPFromHeader  from      = request.Header.From;
                from.FromTag = request.Header.From.FromTag;
                SIPToHeader to = request.Header.To;
                response.Header = new SIPHeader(from, to, request.Header.CSeq, request.Header.CallId)
                {
                    CSeqMethod = request.Header.CSeqMethod,
                    Vias       = request.Header.Vias,
                    UserAgent  = SIPConstants.SIP_USERAGENT_STRING,
                    CSeq       = request.Header.CSeq
                };

                if (response.Header.To.ToTag == null || request.Header.To.ToTag.Trim().Length == 0)
                {
                    response.Header.To.ToTag = CallProperties.CreateNewTag();
                }

                return(response);
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPTransport GetResponse. " + excp.Message);
                throw;
            }
        }
        private SIPResponse GetErrorResponse(SIPRequest sipRequest, SIPResponseStatusCodesEnum errorResponseCode, string errorMessage)
        {
            try
            {
                SIPResponse errorResponse = SIPTransport.GetResponse(sipRequest, errorResponseCode, null);
                if (errorMessage != null)
                {
                    errorResponse.ReasonPhrase = errorMessage;
                }

                SIPHeader requestHeader = sipRequest.Header;
                SIPHeader errorHeader   = new SIPHeader(requestHeader.Contact, requestHeader.From, requestHeader.To, requestHeader.CSeq, requestHeader.CallId);

                if (errorHeader.To.ToTag == null || errorHeader.To.ToTag.Trim().Length == 0)
                {
                    errorHeader.To.ToTag = CallProperties.CreateNewTag();
                }

                errorHeader.CSeqMethod  = requestHeader.CSeqMethod;
                errorHeader.Vias        = requestHeader.Vias;
                errorHeader.Server      = m_serverAgent;
                errorHeader.MaxForwards = Int32.MinValue;

                errorResponse.Header = errorHeader;

                return(errorResponse);
            }
            catch (Exception excp)
            {
                logger.Error("Exception GetErrorResponse. " + excp.Message);
                throw excp;
            }
        }
        private SIPRequest GetAuthenticatedRequest(SIPRequest originalRequest, SIPResponse sipResponse)
        {
            try
            {
                SIPAuthorisationDigest digest = sipResponse.Header.AuthenticationHeader.SIPDigest;
                m_lastServerNonce = digest.Nonce;
                string username = (m_callDescriptor.AuthUsername != null) ? m_callDescriptor.AuthUsername : m_callDescriptor.Username;
                digest.SetCredentials(username, m_callDescriptor.Password, originalRequest.URI.ToString(), originalRequest.Method.ToString());

                SIPRequest authRequest = originalRequest.Copy();
                authRequest.SetSendFromHints(originalRequest.LocalSIPEndPoint);
                authRequest.Header.Vias.TopViaHeader.Branch = CallProperties.CreateBranchId();
                authRequest.Header.From.FromTag             = CallProperties.CreateNewTag();
                authRequest.Header.To.ToTag = null;
                authRequest.Header.CallId   = CallProperties.CreateNewCallId();
                authRequest.Header.CSeq     = originalRequest.Header.CSeq + 1;

                authRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(digest);
                authRequest.Header.AuthenticationHeader.SIPDigest.Response = digest.Digest;

                return(authRequest);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception SIPNonInviteClientUserAgent GetAuthenticatedRequest. " + excp.Message);
                throw;
            }
        }
Ejemplo n.º 19
0
        public SIPRequest GetSIPRequest(SIPMethodsEnum sipMethod, string requestURIStr, string fromURIStr, int cseq, string callId, string contentType, string body)
        {
            SIPURI requestURI = (requestURIStr.StartsWith("sip:")) ? SIPURI.ParseSIPURI(requestURIStr) : SIPURI.ParseSIPURI("sip:" + requestURIStr);
            SIPURI fromURI    = (fromURIStr.StartsWith("sip:")) ? SIPURI.ParseSIPURI(fromURIStr) : SIPURI.ParseSIPURI("sip:" + fromURIStr);

            SIPFromHeader fromHeader = new SIPFromHeader(null, fromURI, CallProperties.CreateNewTag());
            SIPToHeader   toHeader   = new SIPToHeader(null, requestURI, null);

            SIPRequest sipRequest = new SIPRequest(sipMethod, requestURI);

            IPEndPoint localSIPEndPoint = m_sipTransport.GetIPEndPointsList()[0];
            SIPHeader  sipHeader        = new SIPHeader(fromHeader, toHeader, cseq, callId);

            sipHeader.Contact    = SIPContactHeader.ParseContactHeader("sip:" + localSIPEndPoint.ToString());
            sipHeader.CSeqMethod = sipMethod;
            sipRequest.Header    = sipHeader;

            SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId());

            sipRequest.Header.Via.PushViaHeader(viaHeader);

            if (body != null && body.Trim().Length > 0)
            {
                sipRequest.Body = body;
                //sipRequest.Body = "Signal=5\r\nDuration=250";
                //sipRequest.Body = "<rtcp>blah blah blah</rtcp>";
                sipRequest.Header.ContentLength = sipRequest.Body.Length;
                sipRequest.Header.ContentType   = contentType;
            }

            return(sipRequest);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 录像点播请求
        /// </summary>
        /// <param name="localIp">本地ip</param>
        /// <param name="mediaPort">端口号</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="stopTime">结束时间</param>
        /// <param name="fromTag">from tag</param>
        /// <param name="cSeq">序号</param>
        /// <param name="callId">呼叫编号</param>
        /// <returns></returns>
        private SIPRequest BackVideoReq(int[] mediaPort, uint startTime, uint stopTime)
        {
            string localIp = _msgCore.LocalEndPoint.Address.ToString();
            string fromTag = CallProperties.CreateNewTag();
            int    cSeq    = CallProperties.CreateNewCSeq();
            string callId  = CallProperties.CreateNewCallId();

            SIPURI           remoteUri     = new SIPURI(_deviceId, _remoteEndPoint.ToHost(), "");
            SIPURI           localUri      = new SIPURI(_msgCore.LocalSIPId, _msgCore.LocalEndPoint.ToHost(), "");
            SIPFromHeader    from          = new SIPFromHeader(null, localUri, fromTag);
            SIPToHeader      to            = new SIPToHeader(null, remoteUri, null);
            SIPRequest       backReq       = _msgCore.Transport.GetRequest(SIPMethodsEnum.INVITE, remoteUri);
            SIPContactHeader contactHeader = new SIPContactHeader(null, localUri);

            backReq.Header.Contact.Clear();
            backReq.Header.Contact.Add(contactHeader);

            backReq.Header.Allow       = null;
            backReq.Header.From        = from;
            backReq.Header.To          = to;
            backReq.Header.UserAgent   = _msgCore.UserAgent;
            backReq.Header.CSeq        = cSeq;
            backReq.Header.CallId      = callId;
            backReq.Header.Subject     = SetSubject();
            backReq.Header.ContentType = "application/sdp";

            backReq.Body    = SetMediaReq(localIp, mediaPort, startTime, stopTime);
            _realReqSession = backReq;
            return(backReq);
        }
        private SIPResponse GetOkResponse(SIPRequest sipRequest)
        {
            try
            {
                SIPResponse okResponse    = SIPTransport.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Ok, null);
                SIPHeader   requestHeader = sipRequest.Header;
                okResponse.Header = new SIPHeader(requestHeader.Contact, requestHeader.From, requestHeader.To,
                                                  requestHeader.CSeq, requestHeader.CallId);

                // RFC3261 has a To Tag on the example in section "24.1 Registration".
                if (okResponse.Header.To.ToTag == null || okResponse.Header.To.ToTag.Trim().Length == 0)
                {
                    okResponse.Header.To.ToTag = CallProperties.CreateNewTag();
                }

                okResponse.Header.CSeqMethod = requestHeader.CSeqMethod;
                okResponse.Header.Vias       = requestHeader.Vias;
                //okResponse.Header.Server = m_serverAgent;
                okResponse.Header.UserAgent   = m_serverAgent;
                okResponse.Header.MaxForwards = Int32.MinValue;
                okResponse.Header.SetDateHeader();

                return(okResponse);
            }
            catch (Exception excp)
            {
                Logger.Logger.Error("Exception GetOkResponse. ->" + excp.Message);
                throw excp;
            }
        }
 public SIPNotifierClient(
     SIPMonitorLogDelegate logDelegate,
     SIPTransport sipTransport,
     SIPEndPoint outboundProxy,
     SIPEventPackage sipEventPackage,
     SIPURI resourceURI,
     string authUsername,
     string authDomain,
     string authPassword,
     int expiry,
     string filter)
 {
     Log_External          = logDelegate;
     m_sipTransport        = sipTransport;
     m_outboundProxy       = outboundProxy;
     m_sipEventPackage     = sipEventPackage;
     m_authUsername        = authUsername;
     m_authDomain          = authDomain;
     m_authPassword        = authPassword;
     m_expiry              = (expiry > 0) ? expiry : DEFAULT_SUBSCRIBE_EXPIRY;
     m_filter              = filter;
     m_resourceURI         = resourceURI.CopyOf();
     m_subscribeCallID     = CallProperties.CreateNewCallId();
     m_subscriptionFromTag = CallProperties.CreateNewTag();
 }
        private SIPRequest GetInviteRequest(string callURI, SIPCallDescriptor sipCallDescriptor)
        {
            SIPFromHeader fromHeader = sipCallDescriptor.GetFromHeader();

            SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, SIPURI.ParseSIPURI(callURI))
            {
                LocalSIPEndPoint = m_blackhole
            };

            SIPHeader inviteHeader = new SIPHeader(fromHeader, new SIPToHeader(null, inviteRequest.URI, null), 1,
                                                   CallProperties.CreateNewCallId());

            inviteHeader.From.FromTag = CallProperties.CreateNewTag();

            // For incoming calls forwarded via the dial plan the username needs to go into the Contact header.
            inviteHeader.Contact = new List <SIPContactHeader>()
            {
                new SIPContactHeader(null, new SIPURI(inviteRequest.URI.Scheme, m_blackhole))
            };
            inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE;
            inviteRequest.Header    = inviteHeader;

            SIPViaHeader viaHeader = new SIPViaHeader(m_blackhole, CallProperties.CreateBranchId());

            inviteRequest.Header.Vias.PushViaHeader(viaHeader);

            try
            {
                if (sipCallDescriptor.CustomHeaders != null && sipCallDescriptor.CustomHeaders.Count > 0)
                {
                    foreach (string customHeader in sipCallDescriptor.CustomHeaders)
                    {
                        if (customHeader.IsNullOrBlank())
                        {
                            continue;
                        }
                        else if (customHeader.Trim().StartsWith(SIPHeaders.SIP_HEADER_USERAGENT))
                        {
                            inviteRequest.Header.UserAgent =
                                customHeader.Substring(customHeader.IndexOf(":") + 1).Trim();
                        }
                        else
                        {
                            inviteRequest.Header.UnknownHeaders.Add(customHeader);
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception Parsing CustomHeader for GetInviteRequest. " + excp.Message +
                             sipCallDescriptor.CustomHeaders);
            }

            return(inviteRequest);
        }
Ejemplo n.º 24
0
        public SIPRequest GetInviteRequest(string inviteURIStr, string fromURIStr, string body, int rtpPort)
        {
            SIPURI        inviteURI  = (inviteURIStr.StartsWith("sip:")) ? SIPURI.ParseSIPURI(inviteURIStr) : SIPURI.ParseSIPURI("sip:" + inviteURIStr);
            SIPFromHeader fromHeader = SIPFromHeader.ParseFromHeader(fromURIStr); // (fromURIStr.StartsWith("sip:")) ? SIPFromHeader.ParseFromHeader(fromURIStr) : SIPFromHeader.ParseFromHeader("sip:" + fromURIStr);
            SIPToHeader   toHeader   = new SIPToHeader(null, inviteURI, null);

            SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, inviteURI);

            IPEndPoint localSIPEndPoint = m_sipTransport.GetIPEndPointsList()[0];
            SIPHeader  inviteHeader     = new SIPHeader(fromHeader, toHeader, 1, CallProperties.CreateNewCallId());

            inviteHeader.From.FromTag = CallProperties.CreateNewTag();
            inviteHeader.Contact      = SIPContactHeader.ParseContactHeader("sip:" + localSIPEndPoint.ToString());
            inviteHeader.CSeqMethod   = SIPMethodsEnum.INVITE;
            //inviteHeader.UnknownHeaders.Add("BlueFace-Test: 12324");
            inviteRequest.Header = inviteHeader;

            SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId());

            inviteRequest.Header.Via.PushViaHeader(viaHeader);

            rtpPort = (rtpPort != 0) ? rtpPort : Crypto.GetRandomInt(10000, 20000);
            string sessionId = Crypto.GetRandomInt(1000, 5000).ToString();

            if (body != null && body.Trim().Length > 0)
            {
                inviteRequest.Body = body;
            }
            else
            {
                inviteRequest.Body =
                    "v=0" + CRLF +
                    "o=- " + sessionId + " " + sessionId + " IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF +
                    "s=session" + CRLF +
                    "c=IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF +
                    "t=0 0" + CRLF +
                    "m=audio " + rtpPort + " RTP/AVP 0 101" + CRLF +
                    "a=rtpmap:0 PCMU/8000" + CRLF +
                    "a=rtpmap:101 telephone-event/8000" + CRLF +
                    "a=fmtp:101 0-16" + CRLF +
                    "a=sendrecv";
            }

            inviteRequest.Header.ContentLength = inviteRequest.Body.Length;
            inviteRequest.Header.ContentType   = "application/sdp";

            return(inviteRequest);
        }
Ejemplo n.º 25
0
        public SIPRequest GetAuthenticatedRequest(SIPRequest origRequest, SIPResponse authReqdResponse, string username, string password)
        {
            SIPRequest authRequest = origRequest;

            authRequest.Header.Via.TopViaHeader.Branch = CallProperties.CreateBranchId();
            authRequest.Header.From.FromTag            = CallProperties.CreateNewTag();
            authRequest.Header.CSeq = origRequest.Header.CSeq + 1;

            AuthorizationRequest authorizationRequest = authReqdResponse.Header.AuthenticationHeader.AuthRequest;

            authorizationRequest.SetCredentials(username, password, origRequest.URI.ToString(), origRequest.Method.ToString());

            authRequest.Header.AuthenticationHeader = new SIPAuthenticationHeader(authorizationRequest);
            authRequest.Header.AuthenticationHeader.AuthRequest.Response = authorizationRequest.Digest;

            return(authRequest);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 查询设备目录请求
        /// </summary>
        /// <returns></returns>
        private SIPRequest QueryItems()
        {
            SIPURI        remoteUri = new SIPURI(_sipAccount.RemoteSipId, _remoteEndPoint.ToHost(), "");
            SIPURI        localUri  = new SIPURI(_sipAccount.LocalSipId, _localEndPoint.ToHost(), "");
            SIPFromHeader from      = new SIPFromHeader(null, localUri, CallProperties.CreateNewTag());
            SIPToHeader   to        = new SIPToHeader(null, remoteUri, null);
            SIPRequest    queryReq  = _m_sipTransport.GetRequest(SIPMethodsEnum.DO, remoteUri);

            queryReq.Header.From        = from;
            queryReq.Header.Contact     = null;
            queryReq.Header.Allow       = null;
            queryReq.Header.To          = to;
            queryReq.Header.CSeq        = CallProperties.CreateNewCSeq();
            queryReq.Header.CallId      = CallProperties.CreateNewCallId();
            queryReq.Header.ContentType = "Application/DDCP";
            return(queryReq);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// 监控视频请求
        /// </summary>
        /// <returns></returns>
        private SIPRequest InviteRequest()
        {
            SIPURI        uri           = new SIPURI(_cameraId, _remoteEndPoint.ToHost(), "");
            SIPRequest    inviteRequest = _m_sipTransport.GetRequest(SIPMethodsEnum.INVITE, uri);
            SIPFromHeader from          = new SIPFromHeader(null, _sipRequest.URI, CallProperties.CreateNewTag());
            SIPHeader     header        = new SIPHeader(from, inviteRequest.Header.To, CallProperties.CreateNewCSeq(), CallProperties.CreateNewCallId());

            header.ContentType        = "application/DDCP";
            header.Expires            = inviteRequest.Header.Expires;
            header.CSeqMethod         = inviteRequest.Header.CSeqMethod;
            header.Vias               = inviteRequest.Header.Vias;
            header.MaxForwards        = inviteRequest.Header.MaxForwards;
            header.UserAgent          = _userAgent;
            inviteRequest.Header.From = from;
            inviteRequest.Header      = header;
            _realReqSession           = inviteRequest;
            return(inviteRequest);
        }
        private SIPRequest GetRegistrationRequest()
        {
            try
            {
                SIPURI registerURI = m_sipAccountAOR.CopyOf();
                registerURI.User = null;

                SIPRequest registerRequest = SIPRequest.GetRequest(
                    SIPMethodsEnum.REGISTER,
                    registerURI,
                    new SIPToHeader(this.UserDisplayName, m_sipAccountAOR, null),
                    new SIPFromHeader(this.UserDisplayName, m_sipAccountAOR, CallProperties.CreateNewTag()));

                registerRequest.Header.Contact = new List <SIPContactHeader>
                {
                    new SIPContactHeader(this.UserDisplayName, m_contactURI)
                };
                registerRequest.Header.CSeq      = ++m_cseq;
                registerRequest.Header.CallId    = m_callID;
                registerRequest.Header.UserAgent = (!UserAgent.IsNullOrBlank()) ? UserAgent : m_userAgent;
                registerRequest.Header.Expires   = m_expiry;

                if (m_customHeaders != null && m_customHeaders.Length > 0)
                {
                    foreach (var header in m_customHeaders)
                    {
                        registerRequest.Header.UnknownHeaders.Add(header);
                    }
                }

                if (AdjustRegister == null)
                {
                    return(registerRequest);
                }

                return(AdjustRegister(registerRequest));
            }
            catch (Exception excp)
            {
                Logger.Logger.Error("Exception GetRegistrationRequest. ->" + excp.Message);
                throw excp;
            }
        }
        public UASInviteTransaction(
            SIPTransport sipTransport,
            SIPRequest sipRequest,
            SIPEndPoint dstEndPoint,
            SIPEndPoint localSIPEndPoint,
            SIPEndPoint outboundProxy,
            IPAddress contactIPAddress,
            bool noCDR = false)
            : base(sipTransport, sipRequest, dstEndPoint, localSIPEndPoint, outboundProxy)
        {
            TransactionType    = SIPTransactionTypesEnum.Invite;
            m_remoteTag        = sipRequest.Header.From.FromTag;
            m_contactIPAddress = contactIPAddress;

            if (sipRequest.Header.To.ToTag == null)
            {
                // This UAS needs to set the To Tag.
                m_localTag = CallProperties.CreateNewTag();
            }
            else
            {
                // This is a re-INVITE.
                m_localTag = sipRequest.Header.To.ToTag;
            }

            //logger.Debug("New UASTransaction (" + TransactionId + ") for " + TransactionRequest.URI.ToString() + " to " + RemoteEndPoint + ".");
            SIPEndPoint localEP  = SIPEndPoint.TryParse(sipRequest.Header.ProxyReceivedOn) ?? localSIPEndPoint;
            SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipRequest.Header.ProxyReceivedFrom) ?? dstEndPoint;

            if (!noCDR)
            {
                CDR = new SIPCDR(SIPCallDirection.In, sipRequest.URI, sipRequest.Header.From, sipRequest.Header.CallId,
                                 localEP, remoteEP);
            }

            //UpdateTransactionState(SIPTransactionStatesEnum.Proceeding);

            TransactionRequestReceived             += UASInviteTransaction_TransactionRequestReceived;
            TransactionInformationResponseReceived += UASInviteTransaction_TransactionResponseReceived;
            TransactionFinalResponseReceived       += UASInviteTransaction_TransactionResponseReceived;
            TransactionTimedOut += UASInviteTransaction_TransactionTimedOut;
            TransactionRemoved  += UASInviteTransaction_TransactionRemoved;
        }
Ejemplo n.º 30
0
        private SIPResponse GetOkResponse(SIPRequest sipRequest)
        {
            SIPResponse okResponse    = SIPResponse.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Ok, null);
            SIPHeader   requestHeader = sipRequest.Header;

            okResponse.Header = new SIPHeader(requestHeader.Contact, requestHeader.From, requestHeader.To, requestHeader.CSeq, requestHeader.CallId);

            // RFC3261 has a To Tag on the example in section "24.1 Registration".
            if (okResponse.Header.To.ToTag == null || okResponse.Header.To.ToTag.Trim().Length == 0)
            {
                okResponse.Header.To.ToTag = CallProperties.CreateNewTag();
            }

            okResponse.Header.CSeqMethod  = requestHeader.CSeqMethod;
            okResponse.Header.Vias        = requestHeader.Vias;
            okResponse.Header.Server      = m_serverAgent;
            okResponse.Header.MaxForwards = Int32.MinValue;
            okResponse.Header.SetDateHeader();

            return(okResponse);
        }