mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 10:10:08 -08:00
use ergochat/irc-go instead of goshuirc/irc-go
This commit is contained in:
parent
66af8cd63c
commit
4910aefa37
32 changed files with 95 additions and 53 deletions
41
vendor/github.com/ergochat/irc-go/ircutils/hostnames.go
generated
vendored
Normal file
41
vendor/github.com/ergochat/irc-go/ircutils/hostnames.go
generated
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// written by Daniel Oaks <daniel@danieloaks.net>
|
||||
// released under the ISC license
|
||||
|
||||
package ircutils
|
||||
|
||||
import "strings"
|
||||
|
||||
var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."
|
||||
|
||||
// HostnameIsValid provides a way for servers to check whether a looked-up client
|
||||
// hostname is valid (see InspIRCd #1033 for why this is required).
|
||||
//
|
||||
// This function shouldn't be called by clients since they don't need to validate
|
||||
// hostnames for IRC use, just by servers that need to confirm hostnames of incoming
|
||||
// clients.
|
||||
//
|
||||
// In addition to this function, servers should impose their own limits on max
|
||||
// hostname length -- this function limits it to 200 but most servers will probably
|
||||
// want to make it smaller than that.
|
||||
func HostnameIsValid(hostname string) bool {
|
||||
// IRC hostnames specifically require a period, rough limit of 200 chars
|
||||
if !strings.Contains(hostname, ".") || len(hostname) < 1 || len(hostname) > 200 {
|
||||
return false
|
||||
}
|
||||
|
||||
// ensure each part of hostname is valid
|
||||
for _, part := range strings.Split(hostname, ".") {
|
||||
if len(part) < 1 || len(part) > 63 || strings.HasPrefix(part, "-") || strings.HasSuffix(part, "-") {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// ensure all chars of hostname are valid
|
||||
for _, char := range strings.Split(strings.ToLower(hostname), "") {
|
||||
if !strings.Contains(allowedHostnameChars, char) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue