SIPSorcery.SIP.SIPTransportConfig.ParseSIPChannelsNode C# (CSharp) Method

ParseSIPChannelsNode() public static method

public static ParseSIPChannelsNode ( XmlNode sipChannelsNode ) : List
sipChannelsNode System.Xml.XmlNode
return List
        public static List<SIPChannel> ParseSIPChannelsNode(XmlNode sipChannelsNode)
        {
            List<SIPChannel> sipChannels = new List<SIPChannel>();

            foreach (XmlNode sipSocketNode in sipChannelsNode.ChildNodes)
            {
                logger.Debug("Creating SIP Channel for " + sipSocketNode.OuterXml + ".");

                string localSocket = sipSocketNode.InnerText;

                SIPProtocolsEnum protocol = SIPProtocolsEnum.udp;
                if (sipSocketNode.Attributes.GetNamedItem(SIP_PROTOCOL_PARAMETER) != null)
                {
                    protocol = SIPProtocolsType.GetProtocolType(sipSocketNode.Attributes.GetNamedItem(SIP_PROTOCOL_PARAMETER).Value);
                }

                List<SIPEndPoint> nodeSIPEndPoints = GetSIPEndPoints(localSocket, protocol);

                foreach (SIPEndPoint sipEndPoint in nodeSIPEndPoints)
                {
                    try
                    {
                        if (protocol == SIPProtocolsEnum.udp)
                        {
                            logger.Debug(" attempting to create SIP UDP channel for " + sipEndPoint.GetIPEndPoint() + ".");
                            SIPUDPChannel udpChannel = new SIPUDPChannel(sipEndPoint.GetIPEndPoint());
                            sipChannels.Add(udpChannel);
                        }
                        else if (protocol == SIPProtocolsEnum.tcp)
                        {
                            logger.Debug(" attempting to create SIP TCP channel for " + sipEndPoint.GetIPEndPoint() + ".");

                            SIPTCPChannel tcpChannel = new SIPTCPChannel(sipEndPoint.GetIPEndPoint());
                            sipChannels.Add(tcpChannel);
                        }
                        else if (protocol == SIPProtocolsEnum.tls)
                        {
                            if (sipSocketNode.Attributes.GetNamedItem(CERTIFICATE_PATH_PARAMETER) == null)
                            {
                                logger.Warn("Could not create SIPTLSChannel from XML configuration node as no " + CERTIFICATE_PATH_PARAMETER + " attribute was present.");
                            }
                            else
                            {
                                string certificateType = "machinestore";
                                if (sipSocketNode.Attributes.GetNamedItem(CERTIFICATE_TYPE_PARAMETER) != null)
                                {
                                    certificateType = sipSocketNode.Attributes.GetNamedItem(CERTIFICATE_TYPE_PARAMETER).Value;
                                }

                                string certificatePath = (sipSocketNode.Attributes.GetNamedItem(CERTIFICATE_PATH_PARAMETER) != null) ? sipSocketNode.Attributes.GetNamedItem(CERTIFICATE_PATH_PARAMETER).Value : null;
                                string certificateKeyPassword = (sipSocketNode.Attributes.GetNamedItem(CERTIFICATE_KEY_PASSWORD_PARAMETER) != null) ? sipSocketNode.Attributes.GetNamedItem(CERTIFICATE_KEY_PASSWORD_PARAMETER).Value : String.Empty;
                                logger.Debug(" attempting to create SIP TLS channel for " + sipEndPoint.GetIPEndPoint() + " and certificate type of " + certificateType + " at " + certificatePath + ".");
                                X509Certificate2 certificate = LoadCertificate(certificateType, certificatePath, certificateKeyPassword);
                                if (certificate != null)
                                {
                                    SIPTLSChannel tlsChannel = new SIPTLSChannel(certificate, sipEndPoint.GetIPEndPoint());
                                    sipChannels.Add(tlsChannel);
                                }
                                else
                                {
                                    logger.Warn("A SIP TLS channel was not created because the certificate could not be loaded.");
                                }
                            }
                        }
                        else
                        {
                            logger.Warn("Could not create a SIP channel for protocol " + protocol + ".");
                        }
                    }
                    catch (Exception excp)
                    {
                        logger.Warn("Exception SIPTransportConfig Adding SIP Channel for " + sipEndPoint.ToString() + ". " + excp.Message);
                    }
                }
            }

            return sipChannels;
        }