mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
bump irc-go to include new ircutils function
This commit is contained in:
parent
e447c61c73
commit
074a5a077e
7 changed files with 136 additions and 2 deletions
9
vendor/github.com/goshuirc/irc-go/ircutils/doc.go
generated
vendored
Normal file
9
vendor/github.com/goshuirc/irc-go/ircutils/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// written by Daniel Oaks <daniel@danieloaks.net>
|
||||
// released under the ISC license
|
||||
|
||||
/*
|
||||
Package ircutils provides small, useful utility functions and classes.
|
||||
|
||||
This package is in an alpha stage.
|
||||
*/
|
||||
package ircutils
|
||||
41
vendor/github.com/goshuirc/irc-go/ircutils/hostnames.go
generated
vendored
Normal file
41
vendor/github.com/goshuirc/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
|
||||
}
|
||||
25
vendor/github.com/goshuirc/irc-go/ircutils/unicode.go
generated
vendored
Normal file
25
vendor/github.com/goshuirc/irc-go/ircutils/unicode.go
generated
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) 2021 Shivaram Lingamneni
|
||||
// Released under the MIT License
|
||||
|
||||
package ircutils
|
||||
|
||||
import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// truncate a message, taking care not to make valid UTF8 into invalid UTF8
|
||||
func TruncateUTF8Safe(message string, byteLimit int) (result string) {
|
||||
if len(message) <= byteLimit {
|
||||
return message
|
||||
}
|
||||
message = message[:byteLimit]
|
||||
for i := 0; i < (utf8.UTFMax - 1); i++ {
|
||||
r, n := utf8.DecodeLastRuneInString(message)
|
||||
if r == utf8.RuneError && n <= 1 {
|
||||
message = message[:len(message)-1]
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return message
|
||||
}
|
||||
56
vendor/github.com/goshuirc/irc-go/ircutils/userhost.go
generated
vendored
Normal file
56
vendor/github.com/goshuirc/irc-go/ircutils/userhost.go
generated
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// written by Daniel Oaks <daniel@danieloaks.net>
|
||||
// released under the ISC license
|
||||
|
||||
package ircutils
|
||||
|
||||
import "strings"
|
||||
|
||||
// UserHost holds a username+host combination
|
||||
type UserHost struct {
|
||||
Nick string
|
||||
User string
|
||||
Host string
|
||||
}
|
||||
|
||||
// ParseUserhost takes a userhost string and returns a UserHost instance.
|
||||
func ParseUserhost(userhost string) UserHost {
|
||||
var uh UserHost
|
||||
|
||||
if len(userhost) == 0 {
|
||||
return uh
|
||||
}
|
||||
|
||||
if strings.Contains(userhost, "!") {
|
||||
usersplit := strings.SplitN(userhost, "!", 2)
|
||||
var rest string
|
||||
if len(usersplit) == 2 {
|
||||
uh.Nick = usersplit[0]
|
||||
rest = usersplit[1]
|
||||
} else {
|
||||
rest = usersplit[0]
|
||||
}
|
||||
|
||||
hostsplit := strings.SplitN(rest, "@", 2)
|
||||
if len(hostsplit) == 2 {
|
||||
uh.User = hostsplit[0]
|
||||
uh.Host = hostsplit[1]
|
||||
} else {
|
||||
uh.User = hostsplit[0]
|
||||
}
|
||||
} else {
|
||||
hostsplit := strings.SplitN(userhost, "@", 2)
|
||||
if len(hostsplit) == 2 {
|
||||
uh.Nick = hostsplit[0]
|
||||
uh.Host = hostsplit[1]
|
||||
} else {
|
||||
uh.User = hostsplit[0]
|
||||
}
|
||||
}
|
||||
|
||||
return uh
|
||||
}
|
||||
|
||||
// // Canonical returns the canonical string representation of the userhost.
|
||||
// func (uh *UserHost) Canonical() string {
|
||||
// return ""
|
||||
// }
|
||||
Loading…
Add table
Add a link
Reference in a new issue