示例#1
0
 public void Refresh()
 {
     lock (this.m_pOwner.VirtualServer.Server.LockSynchronizer)
     {
         this.m_pOwner.VirtualServer.Server.TCP_Client.TcpStream.WriteLine("GetSipRegistration " + TextUtils.QuoteString(this.m_pOwner.VirtualServer.VirtualServerID) + " " + TextUtils.QuoteString(this.m_AddressOfRecord));
         string text = this.m_pOwner.VirtualServer.Server.ReadLine();
         if (!text.ToUpper().StartsWith("+OK"))
         {
             throw new Exception(text);
         }
         int num = Convert.ToInt32(text.Split(new char[]
         {
             ' '
         }, 2)[1]);
         MemoryStream memoryStream = new MemoryStream();
         this.m_pOwner.VirtualServer.Server.TCP_Client.TcpStream.ReadFixedCount(memoryStream, (long)num);
         DataSet dataSet = Utils.DecompressDataSet(memoryStream);
         if (dataSet.Tables.Contains("Contacts"))
         {
             List <SipRegistrationContact> list = new List <SipRegistrationContact>();
             foreach (DataRow dataRow in dataSet.Tables["Contacts"].Rows)
             {
                 SIP_t_ContactParam sIP_t_ContactParam = new SIP_t_ContactParam();
                 sIP_t_ContactParam.Parse(new System.NetworkToolkit.StringReader(dataRow["Value"].ToString()));
                 list.Add(new SipRegistrationContact(sIP_t_ContactParam.Address.Uri.Value, sIP_t_ContactParam.Expires, sIP_t_ContactParam.QValue));
             }
             this.m_pContacts = list.ToArray();
         }
         else
         {
             this.m_pContacts = new SipRegistrationContact[0];
         }
     }
 }
示例#2
0
        private void addVirtualServer()
        {
            Gateway gw = InfoService.Instance.CurrentGateway; //当前网关配置。

            SIP_t_ContactParam[] contacts = new SIP_t_ContactParam[1];

            SIP_t_ContactParam c  = new SIP_t_ContactParam();
            StringReader       sr = new StringReader($"<sip:{gw.SipNumber}@{_localIP}:{gw.Port}>;expires={Expires};qvalue=1.00");

            c.Parse(sr);
            contacts[0] = c;

            string aor = $"{gw.SipNumber}@{_localIP}";

            _sipProxy.Registrar.SetRegistration(aor, contacts);

            if (_regTimer == null)
            {
                _regTimer = new System.Threading.Timer(timer_Callback, null, (int)(Expires * 0.9) * 1000, Timeout.Infinite);
            }
            else
            {
                _regTimer.Change((int)(Expires * 0.9) * 1000, Timeout.Infinite);
            }
        }
        /// <summary>
        /// Converts <b>ContactUri</b> to valid Contact header value.
        /// </summary>
        /// <returns>Returns contact header value.</returns>
        public string ToContactValue()
        {
            SIP_t_ContactParam retVal = new SIP_t_ContactParam();

            retVal.Parse(new StringReader(m_ContactURI.ToString()));
            retVal.Expires = m_Expires;

            return(retVal.ToStringValue());
        }
        /// <summary>
        /// Gets server events and binds them to this.
        /// </summary>
        private void Bind()
        {
            /* GetSipRegistrations "<virtualServerID>"
             *    Responses:
             +OK <sizeOfData>
             *      <data>
             *
             *      -ERR <errorText>
             */

            lock (m_pOwner.Server.LockSynchronizer){
                m_pOwner.Server.TcpClient.TcpStream.WriteLine("GetSipRegistrations " +
                                                              TextUtils.QuoteString(m_pOwner.VirtualServerID)
                                                              );

                string response = m_pOwner.Server.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                int          sizeOfData = Convert.ToInt32(response.Split(new char[] { ' ' }, 2)[1]);
                MemoryStream ms         = new MemoryStream();
                m_pOwner.Server.TcpClient.TcpStream.ReadFixedCount(ms, sizeOfData);

                // Decompress dataset
                DataSet ds = Utils.DecompressDataSet(ms);

                if (ds.Tables.Contains("SipRegistrations"))
                {
                    foreach (DataRow dr in ds.Tables["SipRegistrations"].Rows)
                    {
                        //--- Parse contact -------------------------------------------------------------//
                        List <SipRegistrationContact> contacts = new List <SipRegistrationContact>();
                        foreach (string contact in dr["Contacts"].ToString().Split('\t'))
                        {
                            if (!string.IsNullOrEmpty(contact))
                            {
                                SIP_t_ContactParam c = new SIP_t_ContactParam();
                                c.Parse(new LumiSoft.Net.StringReader(contact));
                                contacts.Add(new SipRegistrationContact(c.Address.Uri.Value, c.Expires, c.QValue));
                            }
                        }
                        //--------------------------------------------------------------------------------//

                        m_pRegistrations.Add(new SipRegistration(
                                                 this,
                                                 dr["UserName"].ToString(),
                                                 dr["AddressOfRecord"].ToString(),
                                                 contacts.ToArray()
                                                 ));
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Refreshes specified registration info.
        /// </summary>
        public void Refresh()
        {
            /* GetSipRegistration "<virtualServerID>" "<addressOfRecord>"
             *    Responses:
             +OK <sizeOfData>
             *      <data>
             *
             *      -ERR <errorText>
             */

            lock (m_pOwner.VirtualServer.Server.LockSynchronizer){
                m_pOwner.VirtualServer.Server.TcpClient.TcpStream.WriteLine("GetSipRegistration " +
                                                                            TextUtils.QuoteString(m_pOwner.VirtualServer.VirtualServerID) + " " +
                                                                            TextUtils.QuoteString(m_AddressOfRecord)
                                                                            );

                string response = m_pOwner.VirtualServer.Server.ReadLine();
                if (!response.ToUpper().StartsWith("+OK"))
                {
                    throw new Exception(response);
                }

                int          sizeOfData = Convert.ToInt32(response.Split(new char[] { ' ' }, 2)[1]);
                MemoryStream ms         = new MemoryStream();
                m_pOwner.VirtualServer.Server.TcpClient.TcpStream.ReadFixedCount(ms, sizeOfData);

                // Decompress dataset
                DataSet ds = Utils.DecompressDataSet(ms);

                if (ds.Tables.Contains("Contacts"))
                {
                    List <SipRegistrationContact> contacts = new List <SipRegistrationContact>();
                    foreach (DataRow dr in ds.Tables["Contacts"].Rows)
                    {
                        SIP_t_ContactParam c = new SIP_t_ContactParam();
                        c.Parse(new LumiSoft.Net.StringReader(dr["Value"].ToString()));
                        contacts.Add(new SipRegistrationContact(c.Address.Uri.Value, c.Expires, c.QValue));
                    }
                    m_pContacts = contacts.ToArray();
                }
                else
                {
                    m_pContacts = new SipRegistrationContact[0];
                }
            }
        }
示例#6
0
 private void Bind()
 {
     lock (this.m_pOwner.Server.LockSynchronizer)
     {
         this.m_pOwner.Server.TCP_Client.TcpStream.WriteLine("GetSipRegistrations " + TextUtils.QuoteString(this.m_pOwner.VirtualServerID));
         string text = this.m_pOwner.Server.ReadLine();
         if (!text.ToUpper().StartsWith("+OK"))
         {
             throw new Exception(text);
         }
         int num = Convert.ToInt32(text.Split(new char[]
         {
             ' '
         }, 2)[1]);
         MemoryStream memoryStream = new MemoryStream();
         this.m_pOwner.Server.TCP_Client.TcpStream.ReadFixedCount(memoryStream, (long)num);
         DataSet dataSet = Utils.DecompressDataSet(memoryStream);
         if (dataSet.Tables.Contains("SipRegistrations"))
         {
             foreach (DataRow dataRow in dataSet.Tables["SipRegistrations"].Rows)
             {
                 List <SipRegistrationContact> list = new List <SipRegistrationContact>();
                 string[] array = dataRow["Contacts"].ToString().Split(new char[]
                 {
                     '\t'
                 });
                 for (int i = 0; i < array.Length; i++)
                 {
                     string text2 = array[i];
                     if (!string.IsNullOrEmpty(text2))
                     {
                         SIP_t_ContactParam sIP_t_ContactParam = new SIP_t_ContactParam();
                         sIP_t_ContactParam.Parse(new System.NetworkToolkit.StringReader(text2));
                         list.Add(new SipRegistrationContact(sIP_t_ContactParam.Address.Uri.Value, sIP_t_ContactParam.Expires, sIP_t_ContactParam.QValue));
                     }
                 }
                 this.m_pRegistrations.Add(new SipRegistration(this, dataRow["UserName"].ToString(), dataRow["AddressOfRecord"].ToString(), list.ToArray()));
             }
         }
     }
 }
示例#7
0
        private void register()
        {
            SIP_t_ContactParam[] contacts = new SIP_t_ContactParam[1];

            SIP_t_ContactParam c  = new SIP_t_ContactParam();
            StringReader       sr = new StringReader($"<sip:{_localAOR}:{_gateway.Port}>;expires={Expires};qvalue=1.00");

            c.Parse(sr);
            contacts[0] = c;

            _registrar.SetRegistration(_localAOR, contacts);

            if (_regTimer == null)
            {
                _regTimer = new Timer(timer_Callback, null, (int)(Expires * 0.9) * 1000, Timeout.Infinite);
            }
            else
            {
                _regTimer.Change((int)(Expires * 0.9) * 1000, Timeout.Infinite);
            }
        }
        /// <summary>
        /// Converts <b>ContactUri</b> to valid Contact header value.
        /// </summary>
        /// <returns>Returns contact header value.</returns>
        public string ToContactValue()
        {
            SIP_t_ContactParam retVal = new SIP_t_ContactParam();
            retVal.Parse(new StringReader(m_ContactURI.ToString()));
            retVal.Expires = m_Expires;

            return retVal.ToStringValue();
        }