public bool Persist(ConfigParams i_ConfigParams, string i_sPath) { bool bRet = true; string sSipProxy = ""; string sSipPassword = ""; string sDisplayNamePrefix = ""; string sSipTransport = ""; string sSipRegistrarIp = ""; string sSipRegistrationExpiration = ""; string sRtpPortMax = ""; string sNatIpAddr = ""; string sAudioMgrIp = ""; string sLogLevel = ""; string sLogFilenamePrefix = ""; string sMasterIp = ""; string sSlaveIp = ""; string sVirtualIp = ""; string sSipProfileType = ""; // The following are numbers instead of strings since they are different in each configuration file // and their value depends on which channel number that configuration file corresponds to. int iSipFirstExt = 0; int iFirstLocalSipPort = 0; int iRtpPortMin = 0; int iAudioMgrSendPortFirst = 0; int iAudioMgrRecvPortFirst = 0; try { int iNumParams = i_ConfigParams.Count; for (int jj = 0; jj < iNumParams; ++jj) { ConfigParams.ConfigParam paramTmp = i_ConfigParams[jj]; switch (paramTmp.Name) { case m_csSipProxyLabel: { sSipProxy = paramTmp.Value; } break; case m_csSipFirstExtLabel: { iSipFirstExt = Int32.Parse(paramTmp.Value); } break; case m_csSipPasswordLabel: { if (paramTmp.Value.Length > 0) { sSipPassword = paramTmp.Value; } } break; case m_csSipNumExtLabel: { if (Int32.Parse(paramTmp.Value) != m_iMaxSessions) { // FIX - log warning } } break; case m_csFirstLocalSipPortLabel: { iFirstLocalSipPort = Int32.Parse(paramTmp.Value); } break; case m_csDisplayNamePrefixLabel: { sDisplayNamePrefix = paramTmp.Value; } break; case m_csSipTransportLabel: { sSipTransport = paramTmp.Value; } break; case m_csSipRegistrarIpLabel: { sSipRegistrarIp = paramTmp.Value; } break; case m_csSipRegistrationExpirationLabel: { sSipRegistrationExpiration = paramTmp.Value; } break; case m_csRtpPortMinLabel: { iRtpPortMin = Int32.Parse(paramTmp.Value); } break; case m_csRtpPortMaxLabel: { sRtpPortMax = paramTmp.Value; } break; case m_csNatIpAddrLabel: { sNatIpAddr = paramTmp.Value; } break; case m_csAudioMgrIpLabel: { sAudioMgrIp = paramTmp.Value; } break; case m_csAudioMgrSendPortFirstLabel: { iAudioMgrSendPortFirst = Int32.Parse(paramTmp.Value); } break; case m_csAudioMgrRecvPortFirstLabel: { iAudioMgrRecvPortFirst = Int32.Parse(paramTmp.Value); } break; case m_csLogLevelLabel: { sLogLevel = paramTmp.Value; } break; case m_csLogFilenamePrefixLabel: { sLogFilenamePrefix = paramTmp.Value; } break; case m_csSaveAudioLabel: { // FIX } break; case m_csMasterIpLabel: { sMasterIp = paramTmp.Value; } break; case m_csSlaveIpLabel: { sSlaveIp = paramTmp.Value; } break; case m_csVirtualIpLabel: { sVirtualIp = paramTmp.Value; } break; case m_csSipProfileTypeLabel: { sSipProfileType = paramTmp.Value; } break; default: { // FIX - log warning } break; } // switch } // for(jj) // If it looks like we aren't configured for a redundant configuration then // set those values such that the configuration files will be correctly generated // for a non-redundant system. if (String.IsNullOrEmpty(sMasterIp) || String.IsNullOrEmpty(sSlaveIp) || String.IsNullOrEmpty(sVirtualIp)) { sMasterIp = sSipProxy; sSlaveIp = sSipProxy; sVirtualIp = sSipProxy; } int iNumFiles = m_iMaxSessions; // Write out user agent config files (typically /opt/speechbridge/config/X.cfg) for (int ii = 0; ii < iNumFiles; ++ii) { string sFileName; if (i_sPath.EndsWith("/")) { sFileName = String.Format("{0}{1}.cfg", i_sPath, ii); } else { sFileName = String.Format("{0}/{1}.cfg", i_sPath, ii); } using (StreamWriter sw = new StreamWriter(sFileName, false, new UTF8Encoding(false))) //$$$ LP - Should UTF8 Identifier be emitted to file (if yes, can use Encoding.UTF8). { string sSipExt = (iSipFirstExt + ii).ToString(); string sFirstLocalSipPort = (iFirstLocalSipPort + ii).ToString(); string sRtpPortMin = (iRtpPortMin + (ii * 2)).ToString(); string sAudioMgrSendPortFirst = (iAudioMgrSendPortFirst + (ii * 2)).ToString(); string sAudioMgrRecvPortFirst = (iAudioMgrRecvPortFirst + (ii * 2)).ToString(); sw.Write(FormatAudioRouterEntry(m_csSipProxyCfgtag, sVirtualIp)); sw.Write(FormatAudioRouterEntry(m_csSipExtCfgtag, sSipExt)); sw.Write(FormatAudioRouterEntry(m_csSipPasswordCfgtag, sSipPassword)); sw.Write(FormatAudioRouterEntry(m_csLocalSipPortCfgtag, sFirstLocalSipPort)); sw.Write(FormatAudioRouterEntry(m_csDisplayNameCfgtag, sDisplayNamePrefix + sSipExt)); sw.Write(FormatAudioRouterEntry(m_csSipTransportCfgtag, sSipTransport)); sw.Write(FormatAudioRouterEntry(m_csSipRegistrarIpCfgtag, sSipRegistrarIp)); sw.Write(FormatAudioRouterEntry(m_csSipRegistrationExpirationCfgtag, sSipRegistrationExpiration)); sw.Write(FormatAudioRouterEntry(m_csRtpPortMinCfgtag, sRtpPortMin)); sw.Write(FormatAudioRouterEntry(m_csRtpPortMaxCfgtag, sRtpPortMax)); sw.Write(FormatAudioRouterEntry(m_csNatIpAddrCfgtag, sNatIpAddr)); sw.Write(FormatAudioRouterEntry(m_csAudioMgrIpCfgtag, sAudioMgrIp)); sw.Write(FormatAudioRouterEntry(m_csAudioMgrSendPortCfgtag, sAudioMgrSendPortFirst)); sw.Write(FormatAudioRouterEntry(m_csAudioMgrRecvPortCfgtag, sAudioMgrRecvPortFirst)); sw.Write(FormatAudioRouterEntry(m_csLogLevelCfgtag, sLogLevel)); sw.Write(FormatAudioRouterEntry(m_csLogFilenameCfgtag, sLogFilenamePrefix + sSipExt + m_csLogExtension)); sw.Write(FormatAudioRouterEntry(m_csSipProfileTypeCfgtag, sSipProfileType)); } } // for(ii) } catch (Exception) { bRet = false; } try { string sFileName; // Write out SIP proxy server config file (typically /opt/speechbridge/config/ProxySrv.config) if (i_sPath.EndsWith("/")) { sFileName = String.Format("{0}ProxySrv.config", i_sPath); } else { sFileName = String.Format("{0}/ProxySrv.config", i_sPath); } using (StreamWriter sw = new StreamWriter(sFileName, false, new UTF8Encoding(false))) //$$$ LP - Should UTF8 Identifier be emitted to file (if yes, can use Encoding.UTF8). { // FIX - Clean this up to read from a template!!! // Write out header for (int ii = 0; ii < m_csProxyConfigHeader.Length; ii++) { sw.Write(m_csProxyConfigHeader[ii]); } // Write out routes //sw.Write("Route Array Size={0}\r\n", m_iMaxSessions); // Only 2 routes now. sw.Write("Route Array Size=2\r\n"); // Only 2 routes now. string sRelayRoutes = GenerateRelayRoutes(sMasterIp, sSlaveIp, iSipFirstExt, iFirstLocalSipPort); sw.Write("Route 1=[sip:*@{0}:5060] {1}\r\n", sVirtualIp, sRelayRoutes); sw.Write("Route 2=[sip:*@{0}] {1}\r\n", sVirtualIp, sRelayRoutes); // For now the relay route string is the same, but will it always be? // Write out footer for (int ii = 0; ii < m_csProxyConfigFooter.Length; ii++) { sw.Write(m_csProxyConfigFooter[ii]); } } } catch (Exception) { bRet = false; } // Write out /etc/hosts, if on linux #if (false) try { string sFileName; if (RunningSystem.RunningPlatform == CLRPlatform.Mono) { if (i_sPath.EndsWith("/")) { sFileName = String.Format("{0}hosts", i_sPath); } else { sFileName = String.Format("{0}/hosts", i_sPath); } } else // For testing only!!! { sFileName = "g:/proj/work/incendonet/engineering/testing/config/hosts"; } using (StreamWriter sw = new StreamWriter(sFileName, false, new UTF8Encoding(false))) //$$$ LP - Should UTF8 Identifier be emitted to file (if yes, can use Encoding.UTF8). { for (int ii = 0; ii < m_csHostsHeader.Length; ++ii) { sw.Write(m_csHostsHeader[ii]); } sw.Write("{0} speechbridge1 speechbridge1\r\n", sProxyAddr); // FIX - Can't assume that!!! They may change name, and need to be able to have more than one SB on a net. } } catch (Exception) { bRet = false; } #endif return(bRet); }
/// <summary> /// /// </summary> public SIP() { m_iMaxSessions = ConfigParams.GetNumExt(); }