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.
This commit is contained in:
		
							parent
							
								
									edcd9af47f
								
							
						
					
					
						commit
						6cbcc73a79
					
				
					 1 changed files with 16 additions and 10 deletions
				
			
		| 
						 | 
					@ -79,11 +79,24 @@ chanopt_value (guint8 val)
 | 
				
			||||||
		return "OFF";
 | 
							return "OFF";
 | 
				
			||||||
	case SET_ON:
 | 
						case SET_ON:
 | 
				
			||||||
		return "ON";
 | 
							return "ON";
 | 
				
			||||||
	default:
 | 
						case SET_DEFAULT:
 | 
				
			||||||
		return "{unset}";
 | 
							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 */
 | 
					/* handle the /CHANOPT command */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
| 
						 | 
					@ -106,14 +119,7 @@ chanopt_command (session *sess, char *tbuf, char *word[], char *word_eol[])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (word[offset][0])
 | 
						if (word[offset][0])
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (!g_ascii_strcasecmp (word[offset], "ON"))
 | 
							newval = str_to_chanopt (word[offset]);
 | 
				
			||||||
			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]);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!quiet)
 | 
						if (!quiet)
 | 
				
			||||||
| 
						 | 
					@ -281,7 +287,7 @@ chanopt_load_all (void)
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				if (current)
 | 
									if (current)
 | 
				
			||||||
					chanopt_add_opt (current, buf, atoi (eq + 2));
 | 
										chanopt_add_opt (current, buf, str_to_chanopt (eq + 2));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue