internal int ValidateAddress(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return(1);
            }
            string un, host;
            int    port;

            if (!VATRPCall.ParseSipAddress(input, out un, out host, out port))
            {
                return(2);
            }
            if (!ValidateUsername(un))
            {
                return(3);
            }
            if (!ValidateHost(host))
            {
                return(4);
            }
            if (port < 0 || port > 65535)
            {
                return(5);
            }

            return(0);
        }
        internal bool CheckReceiverContact()
        {
            //****************************************************************************************
            // Check Chat message receiver contact. it should not be null.
            //*****************************************************************************************
            var receiver = string.Empty;

            if (ReceiverAddress != null)
            {
                receiver = ReceiverAddress.Trim();
            }

            if (ChatViewContact != null && receiver == ChatViewContact.Contact.RegistrationName)
            {
                return(true);
            }

            VATRPContact contact = _chatsManager.FindContact(new ContactID(receiver, IntPtr.Zero));

            if (contact == null)
            {
                string un, host, dn;
                int    port;
                if (!VATRPCall.ParseSipAddress(receiver, out un,
                                               out host, out port))
                {
                    un = "";
                }

                if (!un.NotBlank())
                {
                    return(false);
                }

                if (string.IsNullOrEmpty(host))
                {
                    host = App.CurrentAccount.ProxyHostname;
                }
                var contactAddress = string.Format("{0}@{1}", un, host);
                var contactID      = new ContactID(contactAddress, IntPtr.Zero);

                contact = new VATRPContact(contactID)
                {
                    DisplayName      = un,
                    Fullname         = un,
                    SipUsername      = un,
                    RegistrationName = contactAddress
                };
                _contactsManager.AddContact(contact, "");
            }

            SetActiveChatContact(contact, IntPtr.Zero);
            if (ReceiverAddress != contact.RegistrationName)
            {
                ReceiverAddress = contact.RegistrationName;
            }

            return(true);
        }
        private void LoadProviders()
        {
            var providersList = ServiceManager.Instance.ProviderService.GetProviderListFullInfo();

            providersList.Sort((a, b) => String.Compare(a.Label, b.Label, StringComparison.Ordinal));
            string un, domain;
            int    port;

            VATRPCall.ParseSipAddress(_contactSipUsername, out un, out domain, out port);
            ProviderViewModel selectedProvider = null;

            foreach (var s in providersList)
            {
                if (s.Label == "_nologo")
                {
                    continue;
                }
                var providerModel = new ProviderViewModel(s);
                Providers.Add(providerModel);
                if (s.Address == domain && domain.NotBlank())
                {
                    selectedProvider = providerModel;
                }
                if (App.CurrentAccount != null && s.Address == App.CurrentAccount.ProxyHostname)
                {
                    _currentProvider = providerModel;
                }
            }

            var nlp = ServiceManager.Instance.ProviderService.FindProviderLooseSearch("_nologo");

            if (nlp != null)
            {
                _nologoProvider = new ProviderViewModel(nlp);
            }

            if (selectedProvider == null)
            {
                if (_currentProvider == null)
                {
                    _currentProvider = _nologoProvider;
                }
                _contactInitialSipHost = string.Empty;
            }

            if (_isAddMode)
            {
                SelectedProvider = selectedProvider ?? _currentProvider;
            }
            else
            {
                if (selectedProvider == null)
                {
                    _contactInitialSipHost = domain;
                }
                SelectedProvider = selectedProvider ?? _nologoProvider;
            }
        }
Example #4
0
        /// <summary>
        /// Method to import contacts from local machine. Prompts
        /// user to select a contacts file from the computer. Then
        /// it parses the file & stores the contacts.
        /// </summary>
        /// <returns>void</returns>
        private void ExecuteLocalImport()
        {
            var openDlg = new OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,

                Filter      = "xCard Files (*.xml, *.xml)|*.xml;*xml",
                FilterIndex = 0,

                ShowReadOnly = false,
            };

            if (openDlg.ShowDialog() != true)
            {
                return;
            }

            if (ServiceManager.Instance.LinphoneService.VCardSupported)
            {
                // System.Windows.Forms.MessageBox.Show("ExecuteImportCommand Path" + openDlg.FileName);
                var recordsImported = ServiceManager.Instance.ContactService.ImportVCards(openDlg.FileName);
            }
            else
            {
                var cardReader = new vCardReader(openDlg.FileName);

                string un, host;
                int    port;

                foreach (var card in cardReader.vCards)
                {
                    var remoteParty = card.Title.TrimSipPrefix();
                    var contact     =
                        ServiceManager.Instance.ContactService.FindContact(new ContactID(remoteParty, IntPtr.Zero));
                    if (contact != null && contact.Fullname == card.FormattedName)
                    {
                        continue;
                    }
                    VATRPCall.ParseSipAddress(remoteParty, out un, out host, out port);
                    if ((App.CurrentAccount != null && App.CurrentAccount.ProxyHostname != host) ||
                        App.CurrentAccount == null)
                    {
                        un = remoteParty;
                    }
                    ServiceManager.Instance.ContactService.AddLinphoneContact(card.FormattedName, un,
                                                                              remoteParty);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Configures the client for placing phone calls and validates user input.
        /// </summary>
        /// <remarks>
        /// Remote URI Format: sip:[email protected]
        /// </remarks>
        /// <param name="remoteUri"> The SIP URI the call is being placed to.</param>
        /// <returns>True if the call was placed successfully.</returns>
        internal static bool MakeVideoCall(string remoteUri)
        {
            string dialPadPhonePattern = @"^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$";
            string pattern             = @"[ \-\s\t\n\r\(\)\*\#\+\.]*";
            string replacement         = "";
            Regex  rgx = new Regex(pattern);
            Regex  dialPadPhoneCheckRgx = new Regex(dialPadPhonePattern);

            //string result = rgx.Replace(remoteUri, replacement);
            Match match = dialPadPhoneCheckRgx.Match(remoteUri);

            if (match.Success)
            {
                string result = rgx.Replace(remoteUri, replacement);
                // Perserving the leading 1 if there is one:
                //

                /*
                 * if (result.Length > 10 && result[0] == '1')
                 *  result = result.Remove(0, 1);*/
                remoteUri = result;
            }

            //******************************** Maake Video Call **********************************************************************************************
            // This method is called when user tap on call button on dial pad. or When user select the Contact from Contact list (All/Favorites)
            // It will called only when there is a valid number entered for a call (After validation)
            //*************************************************************************************************************************************************
            ILinphoneService _linphoneService = ServiceManager.Instance.LinphoneService;

            if (!_linphoneService.CanMakeVideoCall())
            {
                MessageBox.Show("Video call not supported yet.", "VATRP", MessageBoxButton.OK,
                                MessageBoxImage.Warning);
                return(false);
            }

            if (MainWindow.RegistrationState != LinphoneRegistrationState.LinphoneRegistrationOk)
            {
                MessageBox.Show("Not Registered. Please register first", "VATRP", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return(false);
            }
            // VATRP-2506, 2496: check to see if there is currently a call in progress. IF there is a call in progress, prevent
            //   an outgoing call.
            int callCount = ServiceManager.Instance.LinphoneService.GetActiveCallsCount; // It checks if user already connected a call. if yes then it returns false.

            if (callCount > 0)
            {
                return(false);  // i think this can be a quiet failure - the user is already in a call.
            }

            bool muteMicrophone = false;
            bool muteSpeaker    = false;
            bool enableVideo    = true;
            bool enableAudio    = true;

            if (App.CurrentAccount != null)
            {
                muteMicrophone = App.CurrentAccount.MuteMicrophone;
                muteSpeaker    = App.CurrentAccount.MuteSpeaker;
                enableVideo    = App.CurrentAccount.VideoAutomaticallyStart;
                enableAudio    = App.CurrentAccount.AudioAutomaticallyStart;
            }

            var target = string.Empty;

            string un, host;
            int    port;

            VATRPCall.ParseSipAddress(remoteUri, out un, out host, out port);

            if (!host.NotBlank())
            {
                // set proxy to selected provider
                // find selected provider host
                var provider =
                    ServiceManager.Instance.ProviderService.FindProviderLooseSearch(
                        ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                                                                         Configuration.ConfEntry.CURRENT_PROVIDER, ""));

                //Use dial-around provider if selected
                if (!string.IsNullOrEmpty(App.CurrentAccount?.DialAroundProviderAddress))
                {
                    target = string.Format("sip:{0}@{1}", un, App.CurrentAccount.DialAroundProviderAddress);
                }
                else if (provider != null)
                {
                    target = string.Format("sip:{0}@{1}", un, provider.Address);
                }
                else if (App.CurrentAccount != null)
                {
                    target = string.Format("sip:{0}@{1}", un, App.CurrentAccount.ProxyHostname);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(App.CurrentAccount?.DialAroundProviderAddress))
                {
                    target = string.Format("sip:{0}@{1}", un, App.CurrentAccount.DialAroundProviderAddress);
                }
                else
                {
                    target = string.Format("sip:{0}@{1}:{2}", un, host, port);
                }
            }

            if (!App.CurrentAccount.DisableUserPhoneTag)
            {
                // https://www.twilio.com/docs/glossary/what-e164
                // https://en.wikipedia.org/wiki/E.164
                Regex rE164  = new Regex(@"^(\+|00)?[1-9]\d{4,14}$");
                bool  isE164 = rE164.IsMatch(un);

                if (isE164)
                {
                    target += ";user=phone";
                }
                else
                {
                    target += ";user=dialstring";
                }
            }

            var privacyMask = VATRP.Core.Enums.LinphonePrivacy.LinphonePrivacyDefault;

            if (App.CurrentAccount.EnablePrivacy)
            {
                privacyMask = VATRP.Core.Enums.LinphonePrivacy.LinphonePrivacySession;
            }

            // update video policy settings prior to making a call
            _linphoneService.MakeCall(target,                                                                                  /* destination */
                                      true,                                                                                    /* videoOn */
                                      ServiceManager.Instance.ConfigurationService.Get(Configuration.ConfSection.GENERAL,
                                                                                       Configuration.ConfEntry.USE_RTT, true), /* rttEnabled */
                                      muteMicrophone,                                                                          /* muteMicrophone */
                                      muteSpeaker,                                                                             /* muteSpeaker */
                                      enableVideo,                                                                             /* enableVideo */
                                      enableAudio,
                                      App.CurrentAccount.GeolocationURI,                                                       /* geolocation */
                                      privacyMask);                                                                            /* privacyMask */
            return(true);
        }
        internal void UpdateContactAddress(bool changeProvider)
        {
            string un, host;
            int    port;

            if (VATRPCall.ParseSipAddress(_contactSipUsername, out un, out host, out port))
            {
                if (changeProvider)
                {
                    if (_selectedProvider != null)
                    {
                        if (_selectedProvider == _nologoProvider)
                        {
                            ContactSipUsername = port == 0
                            ? String.Format("{0}@{1}", un,
                                            _contactInitialSipHost)
                            : String.Format("{0}@{1}:{2}", un,
                                            _contactInitialSipHost, port);
                        }
                        else
                        {
                            ContactSipUsername = port == 0
                            ? String.Format("{0}@{1}", un,
                                            _selectedProvider.Provider.Address)
                            : String.Format("{0}@{1}:{2}", un,
                                            _selectedProvider.Provider.Address, port);
                        }
                    }
                    else
                    {
                        ContactSipUsername = port == 0
                            ? String.Format("{0}@{1}", un,
                                            _contactInitialSipHost)
                            : String.Format("{0}@{1}:{2}", un,
                                            _contactInitialSipHost, port);
                    }
                }
                else
                {
                    if (_selectedProvider != null)
                    {
                        if (host != _selectedProvider.Provider.Address && string.IsNullOrEmpty(host))
                        {
                            ContactSipUsername = port == 0
                           ? String.Format("{0}@{1}", un,
                                           _selectedProvider.Provider.Address)
                           : String.Format("{0}@{1}:{2}", un,
                                           _selectedProvider.Provider.Address, port);
                        }
                    }
                    else
                    {
                        ContactSipUsername = port == 0
                           ? String.Format("{0}@{1}", un,
                                           host)
                           : String.Format("{0}@{1}:{2}", un,
                                           host, port);
                    }
                }
            }
        }