Skip to content

Commit cbf2892

Browse files
committed
Support CLIENTTAGDENY isupport value
1 parent bd46463 commit cbf2892

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* * Copyright (C) 2013-2021 Matt Baxter https://kitteh.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use, copy,
8+
* modify, merge, publish, distribute, sublicense, and/or sell copies
9+
* of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.kitteh.irc.client.library.defaults.element.isupport;
25+
26+
import org.checkerframework.checker.nullness.qual.NonNull;
27+
import org.checkerframework.checker.nullness.qual.Nullable;
28+
import org.kitteh.irc.client.library.Client;
29+
import org.kitteh.irc.client.library.defaults.element.DefaultISupportParameter;
30+
import org.kitteh.irc.client.library.element.ISupportParameter;
31+
32+
import java.util.Arrays;
33+
import java.util.Collections;
34+
import java.util.List;
35+
36+
/**
37+
* Default implementation of {@link ClientTagDeny}.
38+
*/
39+
public class DefaultISupportClientTagDeny extends DefaultISupportParameter implements ISupportParameter.ClientTagDeny {
40+
private final List<String> list;
41+
42+
/**
43+
* Constructs the object.
44+
*
45+
* @param client client
46+
* @param name parameter name
47+
* @param value parameter value, if present
48+
*/
49+
public DefaultISupportClientTagDeny(@NonNull Client client, @NonNull String name, @Nullable String value) {
50+
super(client, name, value);
51+
this.list = (value == null || value.isEmpty()) ? Collections.emptyList() : Collections.unmodifiableList(Arrays.asList(value.split(",")));
52+
}
53+
54+
@Override
55+
public @NonNull List<String> getList() {
56+
return this.list;
57+
}
58+
}

src/main/java/org/kitteh/irc/client/library/defaults/feature/DefaultISupportManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportChanModes;
3434
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportChanTypes;
3535
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportChannelLen;
36+
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportClientTagDeny;
3637
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportEList;
3738
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportExcepts;
3839
import org.kitteh.irc.client.library.defaults.element.isupport.DefaultISupportExtBan;
@@ -75,6 +76,7 @@ public DefaultISupportManager(Client.WithManagement client) {
7576
this.registerParameter(ISupportParameter.ChanLimit.NAME, DefaultISupportChanLimit::new);
7677
this.registerParameter(ISupportParameter.ChanModes.NAME, DefaultISupportChanModes::new);
7778
this.registerParameter(ISupportParameter.ChanTypes.NAME, DefaultISupportChanTypes::new);
79+
this.registerParameter(ISupportParameter.ClientTagDeny.NAME, DefaultISupportClientTagDeny::new);
7880
this.registerParameter(ISupportParameter.EList.NAME, DefaultISupportEList::new);
7981
this.registerParameter(ISupportParameter.Excepts.NAME, DefaultISupportExcepts::new);
8082
this.registerParameter(ISupportParameter.ExtBan.NAME, DefaultISupportExtBan::new);

src/main/java/org/kitteh/irc/client/library/element/ISupportParameter.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,52 @@ interface ChanTypes extends ISupportParameter {
150150
@NonNull List<Character> getTypes();
151151
}
152152

153+
/**
154+
* Represents a listing of client tags that will be blocked and dropped
155+
*/
156+
interface ClientTagDeny extends ISupportParameter {
157+
String NAME = "CLIENTTAGDENY";
158+
159+
/**
160+
* Gets the list of items provided by the server. An asterisk first
161+
* means all client tags are blocked, with the exception of any
162+
* subsequent tags listed with a hyphen prefix.
163+
*
164+
* @return list of returned items, which may be empty
165+
*/
166+
@NonNull List<String> getList();
167+
168+
/**
169+
* Gets if a given client tag is allowed by the server.
170+
*
171+
* @param tag tag to test
172+
* @return true if allowed, false if denied
173+
*/
174+
default boolean isAllowed(@NonNull String tag) {
175+
List<String> list = this.getList();
176+
if (list.isEmpty()) {
177+
return true;
178+
}
179+
if (list.get(0).equals("*")) {
180+
if (list.size() == 1) {
181+
return false;
182+
}
183+
for (String item : list) {
184+
if (item.charAt(0) == '-' && item.substring(1).equalsIgnoreCase(tag)) {
185+
return true;
186+
}
187+
}
188+
return false;
189+
}
190+
for (String item : list) {
191+
if (item.equalsIgnoreCase(tag)) {
192+
return false;
193+
}
194+
}
195+
return true;
196+
}
197+
}
198+
153199
/**
154200
* Represents the LIST extensions supported.
155201
*/

0 commit comments

Comments
 (0)