summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2016-03-28 21:19:39 -0400
committerPatrick Griffis <tingping@tingping.se>2016-03-28 21:19:39 -0400
commit6cbcc73a79a0eea92fd18f2ee1bff819b28123c4 (patch)
tree0f5a8c9fb76af34aad0bf8dcb0c29414cdb446a9 /src
parentedcd9af47fbfe4172f9aa0e05a45688d778f2600 (diff)
chanopt: Ensure values are 0-2
If chanopt was set to any other value it would overwrite
other values in the plugin API for channel flags.
Diffstat (limited to 'src')
-rw-r--r--src/common/chanopt.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/common/chanopt.c b/src/common/chanopt.c
index 7bd66b4a..cfa41ba1 100644
--- a/src/common/chanopt.c
+++ b/src/common/chanopt.c
@@ -79,11 +79,24 @@ chanopt_value (guint8 val)
 		return "OFF";
 	case SET_ON:
 		return "ON";
-	default:
+	case SET_DEFAULT:
 		return "{unset}";
+	default:
+		g_assert_not_reached ();
 	}
 }
 
+static guint8
+str_to_chanopt (const char *str)
+{
+	if (!g_ascii_strcasecmp (str, "ON") || !strcmp (str, "1"))
+		return SET_ON;
+	else if (!g_ascii_strcasecmp (str, "OFF") || !strcmp (str, "0"))
+		return SET_OFF;
+	else
+		return SET_DEFAULT;
+}
+
 /* handle the /CHANOPT command */
 
 int
@@ -106,14 +119,7 @@ chanopt_command (session *sess, char *tbuf, char *word[], char *word_eol[])
 
 	if (word[offset][0])
 	{
-		if (!g_ascii_strcasecmp (word[offset], "ON"))
-			newval = 1;
-		else if (!g_ascii_strcasecmp (word[offset], "OFF"))
-			newval = 0;
-		else if (word[offset][0] == 'u')
-			newval = SET_DEFAULT;
-		else
-			newval = atoi (word[offset]);
+		newval = str_to_chanopt (word[offset]);
 	}
 
 	if (!quiet)
@@ -281,7 +287,7 @@ chanopt_load_all (void)
 			else
 			{
 				if (current)
-					chanopt_add_opt (current, buf, atoi (eq + 2));
+					chanopt_add_opt (current, buf, str_to_chanopt (eq + 2));
 			}
 
 		}