Skip to content

Commit 711343f

Browse files
committed
Advertise HOSTLEN, NICKLEN, and USERLEN in ISUPPORT
1 parent 42caf17 commit 711343f

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

sable_ircd/src/server/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ impl ClientServer {
153153

154154
ret.add(ISupportEntry::string("CASEMAPPING", "ascii"));
155155

156+
ret.add(ISupportEntry::int(
157+
"HOSTLEN",
158+
Hostname::LENGTH.try_into().unwrap(),
159+
));
160+
ret.add(ISupportEntry::int(
161+
"NICKLEN",
162+
Nickname::LENGTH.try_into().unwrap(),
163+
));
164+
ret.add(ISupportEntry::int(
165+
"USERLEN",
166+
Username::LENGTH.try_into().unwrap(),
167+
));
168+
156169
let list_modes: String = ListModeType::iter().map(|t| t.mode_letter()).collect();
157170
let key_modes: String = KeyModeType::iter().map(|t| t.mode_letter()).collect();
158171
let param_modes = "";

sable_network/src/validated.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const UPPER: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4646
const DIGIT: &str = "0123456789";
4747

4848
define_validated! {
49-
Nickname(ArrayString<15> casefolded) {
49+
Nickname(ArrayString<{ Nickname::LENGTH }> casefolded) {
5050
check_allowed_chars(value, &[LOWER, UPPER, DIGIT, "-_\\|[]{}^`"])?;
5151
if let Some(first) = value.chars().next() {
5252
if DIGIT.contains(first) || first == '-' {
@@ -58,11 +58,11 @@ define_validated! {
5858
Ok(())
5959
}
6060

61-
Username(ArrayString<10>) {
61+
Username(ArrayString<{ Username::LENGTH }>) {
6262
Ok(())
6363
}
6464

65-
Hostname(ArrayString<64>) {
65+
Hostname(ArrayString<{ Hostname::LENGTH }>) {
6666
Ok(())
6767
}
6868

@@ -112,6 +112,9 @@ define_validated! {
112112
}
113113

114114
impl Nickname {
115+
/// Maximum length, in bytes
116+
pub const LENGTH: usize = 15;
117+
115118
/// Create a new Nickname, bypassing normal validation. This is only for internal use, and only when created
116119
/// nicknames for collided users
117120
pub(crate) fn new_for_collision(
@@ -122,17 +125,25 @@ impl Nickname {
122125
}
123126

124127
impl Username {
128+
/// Maximum length, in bytes
129+
pub const LENGTH: usize = 10;
130+
125131
/// Coerce the provided value into a valid `Username`, by truncating to the
126132
/// permitted length and removing any invalid characters.
127133
pub fn new_coerce(s: &str) -> Self {
128134
let mut s = s.to_string();
129135
s.retain(|c| c != '[');
130-
s.truncate(s.floor_char_boundary(10));
136+
s.truncate(s.floor_char_boundary(Self::LENGTH));
131137
// expect() is safe here; we've already truncated to the max length
132138
Self(ArrayString::try_from(s.as_str()).expect("Failed to convert string"))
133139
}
134140
}
135141

142+
impl Hostname {
143+
/// Maximum length, in bytes
144+
pub const LENGTH: usize = 64;
145+
}
146+
136147
impl ChannelKey {
137148
pub fn new_coerce(s: &str) -> <Self as Validated>::Result {
138149
let mut s = s.to_string();

0 commit comments

Comments
 (0)