about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2012-01-15 19:07:15 +0100
committerAlexander Barton <alex@barton.de>2012-01-15 19:11:03 +0100
commit81cc5f82b50de80bff9d2d1c37fc726baea5fac5 (patch)
tree2a3c4a51c3e885a2d50752b88f9d6c48c5aca5d1
parent78a3b4c7d64e87845d6babef9a4d1619f9691aba (diff)
downloadngircd-81cc5f82b50de80bff9d2d1c37fc726baea5fac5.tar.gz
ngircd-81cc5f82b50de80bff9d2d1c37fc726baea5fac5.zip
Channel lists: Fix duplicate check and error messages
 - Check correct list for duplicates when adding items.
 - Don't generate any messages when adding duplicates or removing
   non-existing items (this is how ircd-seven and ircu behave).
 - Code cleanup: Add_Ban_Invite(), Del_Ban_Invite().
-rw-r--r--src/ngircd/irc-mode.c86
1 files changed, 53 insertions, 33 deletions
diff --git a/src/ngircd/irc-mode.c b/src/ngircd/irc-mode.c
index 82e6a5ae..0340d3f8 100644
--- a/src/ngircd/irc-mode.c
+++ b/src/ngircd/irc-mode.c
@@ -831,60 +831,80 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
 } /* IRC_AWAY */
 
 
+/**
+ * Add entries to channel ban and invite lists.
+ *
+ * @param what Can be 'I' for invite or 'b' for ban list.
+ * @param Prefix The originator of the command.
+ * @param Client The sender of the command.
+ * @param Channel The channel of which the list should be modified.
+ * @param Pattern The pattern to add to the list.
+ * @return CONNECTED or DISCONNECTED.
+ */
 static bool
-Add_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern)
+Add_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
+	       const char *Pattern)
 {
 	const char *mask;
-	bool already;
-	bool ret;
 
-	assert( Client != NULL );
-	assert( Channel != NULL );
-	assert( Pattern != NULL );
+	assert(Client != NULL);
+	assert(Channel != NULL);
+	assert(Pattern != NULL);
 	assert(what == 'I' || what == 'b');
 
 	mask = Lists_MakeMask(Pattern);
 
-	already = Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask);
-	if (!already) {
-		if (what == 'I')
-			ret = Channel_AddInvite(Channel, mask, false);
-		else
-			ret = Channel_AddBan(Channel, mask);
-		if (!ret)
+	if (what == 'I') {
+		if (Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask))
+			return CONNECTED;
+		if (!Channel_AddInvite(Channel, mask, false))
 			return CONNECTED;
-	}
-	if (already && (Client_Type(Prefix) == CLIENT_SERVER))
-		return CONNECTED;
-
-	if (what == 'I')
 		return Send_ListChange("+I", Prefix, Client, Channel, mask);
-	return Send_ListChange("+b", Prefix, Client, Channel, mask);
+	} else {
+		if (Lists_CheckDupeMask(Channel_GetListBans(Channel), mask))
+			return CONNECTED;
+		if (!Channel_AddBan(Channel, mask))
+			return CONNECTED;
+		return Send_ListChange("+b", Prefix, Client, Channel, mask);
+	}
 }
 
 
+/**
+ * Delete entries from channel ban and invite lists.
+ *
+ * @param what Can be 'I' for invite or 'b' for ban list.
+ * @param Prefix The originator of the command.
+ * @param Client The sender of the command.
+ * @param Channel The channel of which the list should be modified.
+ * @param Pattern The pattern to add to the list.
+ * @return CONNECTED or DISCONNECTED.
+ */
 static bool
-Del_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern)
+Del_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
+	       const char *Pattern)
 {
 	const char *mask;
-	struct list_head *list;
 
-	assert( Client != NULL );
-	assert( Channel != NULL );
-	assert( Pattern != NULL );
+	assert(Client != NULL);
+	assert(Channel != NULL);
+	assert(Pattern != NULL);
 	assert(what == 'I' || what == 'b');
 
-	mask = Lists_MakeMask( Pattern );
-
-	if (what == 'I')
-		list = Channel_GetListInvites(Channel);
-	else
-		list = Channel_GetListBans(Channel);
+	mask = Lists_MakeMask(Pattern);
 
-	Lists_Del(list, mask);
-	if (what == 'I')
+	if (what == 'I') {
+		if (!Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask))
+			return CONNECTED;
+		Lists_Del(Channel_GetListInvites(Channel), mask);
 		return Send_ListChange( "-I", Prefix, Client, Channel, mask );
-	return Send_ListChange( "-b", Prefix, Client, Channel, mask );
+	} else {
+		if (!Lists_CheckDupeMask(Channel_GetListBans(Channel), mask))
+			return CONNECTED;
+		Lists_Del(Channel_GetListBans(Channel), mask);
+		return Send_ListChange( "-b", Prefix, Client, Channel, mask );
+	}
+
 }