Пример #1
0
        private SipRequest CreateRegisterRequest(string user)
        {
            FormHelper.ValidateIsNotEmpty(_txtCallId.Text, "device id");

            var requestUri   = AddressFactory.CreateUri(null, MainForm.Configuration.RegistrarDomain);
            var toAddressUri = AddressFactory.CreateUri(user, MainForm.Configuration.RegistrarDomain);
            var toAddress    = AddressFactory.CreateAddress(null, toAddressUri);
            var toHeader     = HeaderFactory.CreateToHeader(toAddress);
            var fromHeader   = HeaderFactory.CreateFromHeader(toAddress, SipUtil.CreateTag());
            var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Register, ++commandSequence);
            var callIdheader = HeaderFactory.CreateCallIdHeader(_txtCallId.Text);
            var viaHeader    = HeaderFactory.CreateViaHeader(SipProvider.ListeningPoint.Address,
                                                             SipProvider.ListeningPoint.Port, SipConstants.Udp,
                                                             SipUtil.CreateBranch());
            var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader();
            var request           = MessageFactory.CreateRequest(
                requestUri,
                SipMethods.Register,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            /*add routes and contacts*/
            var proxyServerUri = AddressFactory.CreateUri(null, MainForm.SipStack.OutBoundProxy.ToString());
            var routeHeader    = HeaderFactory.CreateRouteHeader(proxyServerUri);
            var localHostUri   = AddressFactory.CreateUri(null, _txtContactAddress.Text);
            var contactHeader  = HeaderFactory.CreateContactHeader(localHostUri);

            request.Routes.Add(routeHeader);

            return(request);
        }
Пример #2
0
        private SipRequest CreateRegisterRequest()
        {
            var requestUri   = AddressFactory.CreateUri(null, "registrar.ocean.com");
            var toAddressUri = AddressFactory.CreateUri("hannes", "ocean.com");
            var toAddress    = AddressFactory.CreateAddress("hannes", toAddressUri);
            var toHeader     = HeaderFactory.CreateToHeader(toAddress);
            var fromHeader   = HeaderFactory.CreateFromHeader(toAddress, SipUtil.CreateTag());
            var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Register, 1028);
            var callId       = SipUtil.CreateCallId();
            var callIdheader = HeaderFactory.CreateCallIdHeader(callId);
            var viaHeader    = HeaderFactory.CreateViaHeader(SipProvider.ListeningPoint.Address, SipProvider.ListeningPoint.Port, SipConstants.Udp,
                                                             SipUtil.CreateBranch());
            var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader();
            var request           = MessageFactory.CreateRequest(
                requestUri,
                SipMethods.Register,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            var proxyServerUri = AddressFactory.CreateUri(null, MainForm.SipStack.OutBoundProxy.ToString());
            var localHostUri   = AddressFactory.CreateUri(null, MainForm.SipProvider.ListeningPoint.ToString());
            var routeHeader    = HeaderFactory.CreateRouteHeader(proxyServerUri);
            var contactHeader  = HeaderFactory.CreateContactHeader(localHostUri);

            request.Routes.Add(routeHeader);
            request.Contacts.Add(contactHeader);
            return(request);
        }
Пример #3
0
        private void Invite()
        {
            FormHelper.ValidateCondition(SipUtil.IsSipUri(_txtFromUri.Text), "From-uri");

            FormHelper.ValidateCondition(SipUtil.IsSipUri(_txtToUri.Text), "To-uri");

            var fromUri = SipUtil.ParseSipUri(_txtFromUri.Text);
            var toUri   = SipUtil.ParseSipUri(_txtToUri.Text);

            if (_chkPeerToPeer.Checked)
            {
                FormHelper.ValidateCondition(SipUtil.IsIpEndPoint(toUri.Host), "To-uri");
            }

            var requestUri   = toUri;
            var toAddress    = AddressFactory.CreateAddress(_txtToAlias.Text, toUri);
            var fromAddress  = AddressFactory.CreateAddress(_txtFromAlias.Text, fromUri);
            var toHeader     = HeaderFactory.CreateToHeader(toAddress);
            var fromHeader   = HeaderFactory.CreateFromHeader(fromAddress, SipUtil.CreateTag());
            var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Invite, ++commandSequence);
            var callIdheader = HeaderFactory.CreateCallIdHeader(SipUtil.CreateCallId());
            var viaHeader    = HeaderFactory.CreateViaHeader(SipProvider.ListeningPoint.Address,
                                                             SipProvider.ListeningPoint.Port, SipConstants.Udp,
                                                             SipUtil.CreateBranch());
            var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader(1);
            var request           = MessageFactory.CreateRequest(
                requestUri,
                SipMethods.Invite,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            /*add routes and contacts*/
            if (!_chkPeerToPeer.Checked)
            {
                var proxyServerUri = AddressFactory.CreateUri(null, MainForm.SipStack.OutBoundProxy.ToString());
                proxyServerUri.IsLooseRouting = true;
                var routeHeader = HeaderFactory.CreateRouteHeader(proxyServerUri);
                request.Routes.Add(routeHeader);
            }
            var contactUri    = AddressFactory.CreateUri(fromUri.User, viaHeader.SentBy.ToString());
            var contactHeader = HeaderFactory.CreateContactHeader(contactUri);

            request.Contacts.Add(contactHeader);

            var transaction = SipProvider.CreateClientTransaction(request);

            _dialog = SipProvider.CreateClientDialog(transaction);
            transaction.SendRequest();
        }
Пример #4
0
        private void _btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                var requestUri   = AddressFactory.CreateUri(null, "registrar." + MainForm.Configuration.RegistrarDomain);
                var toAddressUri = AddressFactory.CreateUri("hannes", MainForm.Configuration.RegistrarDomain);
                var toAddress    = AddressFactory.CreateAddress("hannes", toAddressUri);
                var toHeader     = HeaderFactory.CreateToHeader(toAddress);
                var fromHeader   = HeaderFactory.CreateFromHeader(toAddress, SipUtil.CreateTag());
                var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Register, 1028);
                var callId       = SipUtil.CreateCallId();
                var callIdheader = HeaderFactory.CreateCallIdHeader(callId);
                var viaHeader    = HeaderFactory.CreateViaHeader(SipProvider.ListeningPoint.Address, SipProvider.ListeningPoint.Port, SipConstants.Udp,
                                                                 SipUtil.CreateBranch());
                var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader();
                var request           = MessageFactory.CreateRequest(
                    requestUri,
                    SipMethods.Register,
                    callIdheader,
                    cseqHeader,
                    fromHeader,
                    toHeader,
                    viaHeader,
                    maxForwardsHeader);

                var proxyServerUri = AddressFactory.CreateUri(null, MainForm.SipStack.OutBoundProxy.ToString());
                var localHostUri   = AddressFactory.CreateUri(null, MainForm.SipProvider.ListeningPoint.ToString());
                var routeHeader    = HeaderFactory.CreateRouteHeader(proxyServerUri);
                var contactHeader  = HeaderFactory.CreateContactHeader(localHostUri);
                request.Routes.Add(routeHeader);
                request.Contacts.Add(contactHeader);

                EventAggregator.Instance.Publish(
                    new LogEvent(">>>>" + SipFormatter.FormatMessageEnvelope(request) + Environment.NewLine));

                if (_chbSendStateFull.Checked)
                {
                    var transaction = SipProvider.CreateClientTransaction(request);
                    transaction.SendRequest();
                }
                else
                {
                    SipProvider.SendRequest(request);
                }
            }
            catch (Exception ex)
            {
                MainForm.HandleException(ex);
            }
        }
Пример #5
0
        private void _btnRegister_Click(object sender, EventArgs e)
        {
            int expirationTime = 0;

            FormHelper.ValidateIsNotEmpty(_txtUser.Text, "user");
            FormHelper.ValidateCondition(SipUtil.IsIpEndPoint(_txtContactAddress.Text), "host");
            FormHelper.ValidateCondition(int.TryParse(_txtExpirationTime.Text, out expirationTime), "expiration time");
            SendRequest(() =>
            {
                var request           = CreateRegisterRequest(_txtUser.Text);
                var localHostUri      = AddressFactory.CreateUri(null, _txtContactAddress.Text);
                var contactHeader     = HeaderFactory.CreateContactHeader(localHostUri);
                contactHeader.Expires = expirationTime;
                request.Contacts.Add(contactHeader);
                return(request);
            });
        }
Пример #6
0
        private void SendRinging()
        {
            if (_ringingResponse == null)
            {
                _ringingResponse        = _inviteRequest.CreateResponse(SipResponseCodes.x180_Ringing);
                _ringingResponse.To.Tag = SipUtil.CreateTag();
                var contactUri = AddressFactory.CreateUri("", MainForm.SipProvider.ListeningPoint.ToString());
                _ringingResponse.Contacts.Add(HeaderFactory.CreateContactHeader(contactUri));

                _inviteTransaction =
                    (SipInviteServerTransaction)SipProvider.CreateServerTransaction(_inviteRequest);
                _dialog = SipProvider.CreateServerDialog(_inviteTransaction);
                _inviteTransaction.SendResponse(_ringingResponse);
            }
            else
            {
                _inviteTransaction.SendResponse(_ringingResponse);
            }
        }
Пример #7
0
        private void OnPhoneCallStarted(IInternalPhoneCall phoneCall)
        {
            Check.Require(phoneCall, "phoneCall");
            Check.IsTrue(InternalState == _stateProvider.GetIdle(), string.Format("Failed to start the call. The phone can only start calls while in 'IDLE' state. CurrentState: '{0}'", CurrentState));
            Check.IsTrue(_isRunning, "Failed to start the call. The phone must be started first.");

            _pendingPhoneCall = phoneCall;

            if (_logger.IsInfoEnabled)
            {
                _logger.Info("Starting new phonecall...");
            }
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Creating 'INVITE' request...");
            }
            var thisUri = AddressFactory.CreateUri(string.Empty, ListeningPoint.ToString());

            var requestUri   = phoneCall.GetToUri();
            var toAddress    = AddressFactory.CreateAddress(string.Empty, phoneCall.GetToUri());
            var fromAddress  = AddressFactory.CreateAddress(string.Empty, thisUri);
            var toHeader     = HeaderFactory.CreateToHeader(toAddress);
            var fromHeader   = HeaderFactory.CreateFromHeader(fromAddress, SipUtil.CreateTag());
            var cseqHeader   = HeaderFactory.CreateSCeqHeader(SipMethods.Invite, MessageCounter++);
            var callIdheader = HeaderFactory.CreateCallIdHeader(SipUtil.CreateCallId());
            var viaHeader    = HeaderFactory.CreateViaHeader(ListeningPoint.Address,
                                                             ListeningPoint.Port, SipConstants.Udp,
                                                             SipUtil.CreateBranch());
            var maxForwardsHeader = HeaderFactory.CreateMaxForwardsHeader(1);
            var request           = MessageFactory.CreateRequest(
                requestUri,
                SipMethods.Invite,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            /*add contactheader*/
            var contactUri    = AddressFactory.CreateUri(thisUri.User, viaHeader.SentBy.ToString());
            var contactHeader = HeaderFactory.CreateContactHeader(contactUri);

            request.Contacts.Add(contactHeader);

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("'INVITE' request created. Sending to callee..");
            }

            var clientTransaction = SipProvider.CreateClientTransaction(request);
            var dialog            = SipProvider.CreateClientDialog(clientTransaction as SipInviteClientTransaction);

            clientTransaction.SendRequest();

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("'INVITE' sent.");
            }

            if (_logger.IsInfoEnabled)
            {
                _logger.Info("Request sent. Transitioning to 'WAITPROVISIONAL' state...");
            }

            PendingInvite = new InviteInfo()
            {
                OriginalRequest = request,
                From            = request.From.SipUri,
                To = request.To.SipUri,
                InviteClientTransaction = (SipInviteClientTransaction)clientTransaction,
                IsIncomingCall          = false,
                Dialog = dialog
            };

            ChangeState(_stateProvider.GetWaitProvisional());
        }