Project "FreeSWITCH user-contributed scripts, etc" received a push.

branch: master updated

       via: 510a78e4ab5f20a15f09a69e39d4417da7a1dcf3 (commit)
      from: 164b017dbbd88db3f85dbfb3a21e320b8c54e46a (commit)


= COMMIT LOG ===========================================================
committer: Mitch Capper
comments: 
Do not put empty params in the xml config unless we specifically want them as they can break things in freeswitch.  Also cleaned up the config gen a bit

diff --git a/mitchcapper/FSClient/Account.cs b/mitchcapper/FSClient/Account.cs
index 5d86035..3ed6dc9 100644
--- a/mitchcapper/FSClient/Account.cs
+++ b/mitchcapper/FSClient/Account.cs
@@ -63,7 +63,7 @@ namespace FSClient {
 
 								  };
 		#region Static Methods
-
+		private static string[] AllowedEmptyFields = new string[] { };
 		private static void callback(object state) {
 			Broker.get_instance().reload_sofia(Sofia.RELOAD_CONFIG_MODE.SOFT);
 		}
@@ -128,7 +128,7 @@ namespace FSClient {
 			account.guid = "";
 			account.guid = old_guid;
 		}
-		public static void RemoveAccount(Account account){
+		public static void RemoveAccount(Account account) {
 			account.KillGateway();
 			accounts.Remove(account);
 			ReloadSofia();
@@ -137,7 +137,7 @@ namespace FSClient {
 		public static void create_gateway_nodes(XmlNode gateways_node, bool tls_enabled) {
 			foreach (Account account in accounts) {
 				if (account.enabled)
-					account.create_gateway_node(gateways_node,tls_enabled);
+					account.create_gateway_node(gateways_node, tls_enabled);
 			}
 		}
 		public static void HandleGatewayEvent(FSEvent evt) {
@@ -177,7 +177,7 @@ namespace FSClient {
 			_guid.PropertyChanged += (s, e) => {
 
 				if (!guid_ok(this, _guid.value) || String.IsNullOrEmpty(_guid.value)) {
-					for (int i = 1; i <= 10; i++){
+					for (int i = 1; i <= 10; i++) {
 						int val = i == 10 ? 0 : i; // want 0 checked last.
 						if (guid_ok(this, val.ToString())) {
 							_guid.value = val.ToString();
@@ -267,7 +267,7 @@ namespace FSClient {
 					is_default_account = false;
 				else
 					ensure_default_account();
-				
+
 				RaisePropertyChanged("enabled");
 			}
 		}
@@ -326,7 +326,7 @@ namespace FSClient {
 
 		#endregion
 		private string old_gateway_id;
-		private void acct_status_check(){
+		private void acct_status_check() {
 			if (enabled && state == "NOREG")
 				Broker.get_instance().reload_sofia(Sofia.RELOAD_CONFIG_MODE.SOFT);
 
@@ -336,23 +336,24 @@ namespace FSClient {
 			XmlUtils.AddNodeAttrib(node, "name", gateway_id);
 			old_gateway_id = gateway_id;
 			foreach (FieldValue value in values) {
-				if (!String.IsNullOrEmpty(value.field.xml_name)){
-					if (value.field.name == "register-transport" && value.value == "tls" && ! tls_enabled){
-						MessageBox.Show("Warning the register-transport for account: " + name + " is set to tls, however you have tls disabled in your sofia settings this account will be disabled for now");
-						gateways_node.RemoveChild(node);
-						enabled = false;
-						return;
-					}
-					if (value.field.name == "sip_secure_media")
-						secure_media = value.value == "true";
-					Utils.add_xml_param(node, value.field.xml_name, value.value);
+				if (String.IsNullOrEmpty(value.field.xml_name))
+					continue;
+				if (String.IsNullOrWhiteSpace(value.value) && !AllowedEmptyFields.Contains(value.field.name))
+					continue;
+				if (value.field.name == "register-transport" && value.value == "tls" && !tls_enabled) {
+					MessageBox.Show("Warning the register-transport for account: " + name + " is set to tls, however you have tls disabled in your sofia settings this account will be disabled for now");
+					gateways_node.RemoveChild(node);
+					enabled = false;
+					return;
 				}
+				if (value.field.name == "sip_secure_media")
+					secure_media = value.value == "true";
+				Utils.add_xml_param(node, value.field.xml_name, value.value);
 			}
 			//Was preventing gateway ID from being passed to create_channel so removed (needed for incoming calls)
 			//FieldValue user = FieldValue.GetByName(values, "username");
 			//Utils.add_xml_param(node, "extension-in-contact", user.value);
 		}
-
 		public void ReloadAccount() {
 			KillGateway();
 			ReloadSofia();
diff --git a/mitchcapper/FSClient/Sofia.cs b/mitchcapper/FSClient/Sofia.cs
index 4051172..83dbbb5 100644
--- a/mitchcapper/FSClient/Sofia.cs
+++ b/mitchcapper/FSClient/Sofia.cs
@@ -68,10 +68,9 @@ namespace FSClient {
 											new Field(Field.FIELD_TYPE.Int,"RTP Hold Timeout Seconds","rtp-hold-timeout-sec","rtp-hold-timeout-sec","1800","Advanced"),
 											new Field(Field.FIELD_TYPE.Int,"RTP Tiemout Seconds","rtp-timeout-sec","rtp-timeout-sec","300","Advanced"),
 											new Field(Field.FIELD_TYPE.String,"RTP Timer Name","rtp-timer-name","rtp-timer-name","soft","Advanced"),
-
-
-
 									   };
+
+		private static string[] AllowedEmptyFields = new string[] { };
 		public FieldValue[] values = FieldValue.FieldValues(fields);
 		public void gen_config(XmlNode config_node) {
 
@@ -82,37 +81,40 @@ namespace FSClient {
 			XmlNode profile = XmlUtils.AddNodeNode(profiles, "profile");
 			XmlUtils.AddNodeAttrib(profile, "name", "softphone");
 			XmlNode gateways = XmlUtils.AddNodeNode(profile, "gateways");
-			Account.create_gateway_nodes(gateways,FieldValue.GetByName(values, "tls").value == "true");
+			Account.create_gateway_nodes(gateways, FieldValue.GetByName(values, "tls").value == "true");
 			XmlNode settings = XmlUtils.AddNodeNode(profile, "settings");
 
 			Utils.add_xml_param(settings, "context", "public");
 			Utils.add_xml_param(settings, "dialplan", "xml");
 			Utils.add_xml_param(settings, "disable-register", "true");
 			foreach (FieldValue value in values) {
-				if (!String.IsNullOrEmpty(value.field.xml_name)){
-					String param_value = value.value;
-					if (value.field.name == "tls" && value.value == "true") {//lets make sure that we have a cafile.pem
-						
-						String base_dir = FieldValue.GetByName(values, "tls-cert-dir").value;
-						if (String.IsNullOrWhiteSpace(base_dir))
-							base_dir = "conf/ssl";
-								//this is what freeswitch uses by default if its empty, if this changes this code needs to be updated
-						base_dir = base_dir.Replace('/', '\\'); //windows file path
-						if (base_dir[base_dir.Length - 1] != '\\')
-							base_dir += '\\';
-						if (!System.IO.File.Exists(base_dir + "cafile.pem")){
-							MessageBox.Show("Your sofia settings have TLS enabled however you do not have a cafile.pem in your cert folder, this will most likely cause the entire softphone profile not to load so I am disabling TLS in the profile for now");
-							param_value = "false";
-						}
-
-					}
-					Utils.add_xml_param(settings, value.field.xml_name, param_value);
-				}
+				if (String.IsNullOrEmpty(value.field.xml_name))
+					continue;
+				if (String.IsNullOrWhiteSpace(value.value) && !AllowedEmptyFields.Contains(value.field.name))
+					continue;
+				String param_value = value.value;
+				if (value.field.name == "tls" && value.value == "true" && ! tls_cert_exist_check())
+					param_value = "false";
+
+				Utils.add_xml_param(settings, value.field.xml_name, param_value);
 			}
 
 			DelayedFunction.DelayedCall("SofiaProfileCheck", sofia_profile_check, 1200);
 		}
-
+		private bool tls_cert_exist_check(){
+			String base_dir = FieldValue.GetByName(values, "tls-cert-dir").value;
+			if (String.IsNullOrWhiteSpace(base_dir))
+				base_dir = "conf/ssl";
+			//this is what freeswitch uses by default if its empty, if this changes this code needs to be updated
+			base_dir = base_dir.Replace('/', '\\'); //windows file path
+			if (base_dir[base_dir.Length - 1] != '\\')
+				base_dir += '\\';
+			if (!System.IO.File.Exists(base_dir + "cafile.pem")) {
+				MessageBox.Show("Your sofia settings have TLS enabled however you do not have a cafile.pem in your cert folder, this will most likely cause the entire softphone profile not to load so I am disabling TLS in the profile for now");
+				return false;
+			}
+			return true;
+		}
 		public enum RELOAD_CONFIG_MODE {
 			SOFT,
 			HARD,
========================================================================

Summary of changes:
 mitchcapper/FSClient/Account.cs |   35 ++++++++++++++-------------
 mitchcapper/FSClient/Sofia.cs   |   48 ++++++++++++++++++++------------------
 2 files changed, 43 insertions(+), 40 deletions(-)

this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email
For more info, see http://blog.chomperstomp.com/?p=630 --
FreeSWITCH user-contributed scripts, etc