Merge pull request #862 from slingamn/forcedtrailings

upgrade irc-go, force 353 RPL_NAMREPLY to use a trailing
This commit is contained in:
Shivaram Lingamneni 2020-03-11 23:22:43 -07:00 committed by GitHub
commit 3c1344c3ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 20 deletions

2
go.mod
View File

@ -8,7 +8,7 @@ require (
github.com/go-ldap/ldap/v3 v3.1.7 github.com/go-ldap/ldap/v3 v3.1.7
github.com/go-sql-driver/mysql v1.5.0 github.com/go-sql-driver/mysql v1.5.0
github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940 // indirect github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940 // indirect
github.com/goshuirc/irc-go v0.0.0-20190713001546-05ecc95249a0 github.com/goshuirc/irc-go v0.0.0-20200311142257-57fd157327ac
github.com/mattn/go-colorable v0.1.4 github.com/mattn/go-colorable v0.1.4
github.com/mattn/go-isatty v0.0.10 // indirect github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b

3
go.sum
View File

@ -2,6 +2,7 @@ code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c h1:2RuXx1+tSNWR
code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc= code.cloudfoundry.org/bytefmt v0.0.0-20190819182555-854d396b647c/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48 h1:/EMHruHCFXR9xClkGV/t0rmHrdhX4+trQUcBqjwc9xE= code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48 h1:/EMHruHCFXR9xClkGV/t0rmHrdhX4+trQUcBqjwc9xE=
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc= code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
github.com/DanielOaks/go-idn v0.0.0-20160120021903-76db0e10dc65/go.mod h1:GYIaL2hleNQvfMUBTes1Zd/lDTyI/p2hv3kYB4jssyU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
@ -22,6 +23,8 @@ github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940 h1:KmRLPRstEJiE/9Oj
github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940/go.mod h1:VOmrX6cmj7zwUeexC9HzznUdTIObHqIXUrWNYS+Ik7w= github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940/go.mod h1:VOmrX6cmj7zwUeexC9HzznUdTIObHqIXUrWNYS+Ik7w=
github.com/goshuirc/irc-go v0.0.0-20190713001546-05ecc95249a0 h1:unxsR0de0MIS708eZI7lKa6HiP8FS0PhGCWwwEt9+vQ= github.com/goshuirc/irc-go v0.0.0-20190713001546-05ecc95249a0 h1:unxsR0de0MIS708eZI7lKa6HiP8FS0PhGCWwwEt9+vQ=
github.com/goshuirc/irc-go v0.0.0-20190713001546-05ecc95249a0/go.mod h1:rhIkxdehxNqK9iwJXWzQnxlGuuUR4cHu7PN64VryKXk= github.com/goshuirc/irc-go v0.0.0-20190713001546-05ecc95249a0/go.mod h1:rhIkxdehxNqK9iwJXWzQnxlGuuUR4cHu7PN64VryKXk=
github.com/goshuirc/irc-go v0.0.0-20200311142257-57fd157327ac h1:0JSojWrghcpK9/wx1RpV9Bv2d+3TbBWtHWubKjU2tao=
github.com/goshuirc/irc-go v0.0.0-20200311142257-57fd157327ac/go.mod h1:BRnLblzpqH2T5ANCODHBZLytz0NZN2KaMJ+di8oh3EM=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=

View File

@ -1412,21 +1412,19 @@ var (
RPL_WHOISCHANNELS: true, RPL_WHOISCHANNELS: true,
RPL_USERHOST: true, RPL_USERHOST: true,
// mirc's handling of RPL_NAMREPLY is broken:
// https://forums.mirc.com/ubbthreads.php/topics/266939/re-nick-list
RPL_NAMREPLY: true,
} }
) )
// SendRawMessage sends a raw message to the client. // SendRawMessage sends a raw message to the client.
func (session *Session) SendRawMessage(message ircmsg.IrcMessage, blocking bool) error { func (session *Session) SendRawMessage(message ircmsg.IrcMessage, blocking bool) error {
// use dumb hack to force the last param to be a trailing param if required // use dumb hack to force the last param to be a trailing param if required
var usedTrailingHack bool
config := session.client.server.Config() config := session.client.server.Config()
if config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[message.Command] && len(message.Params) > 0 { if config.Server.Compatibility.forceTrailing && commandsThatMustUseTrailing[message.Command] {
lastParam := message.Params[len(message.Params)-1] message.ForceTrailing()
// to force trailing, we ensure the final param contains a space
if strings.IndexByte(lastParam, ' ') == -1 {
message.Params[len(message.Params)-1] = lastParam + " "
usedTrailingHack = true
}
} }
// assemble message // assemble message
@ -1446,12 +1444,6 @@ func (session *Session) SendRawMessage(message ircmsg.IrcMessage, blocking bool)
return err return err
} }
// if we used the trailing hack, we need to strip the final space we appended earlier on
if usedTrailingHack {
copy(line[len(line)-3:], "\r\n")
line = line[:len(line)-1]
}
if session.client.server.logger.IsLoggingRawIO() { if session.client.server.logger.IsLoggingRawIO() {
logline := string(line[:len(line)-2]) // strip "\r\n" logline := string(line[:len(line)-2]) // strip "\r\n"
session.client.server.logger.Debug("useroutput", session.client.Nick(), " ->", logline) session.client.server.logger.Debug("useroutput", session.client.Nick(), " ->", logline)

View File

@ -52,10 +52,19 @@ type IrcMessage struct {
Prefix string Prefix string
Command string Command string
Params []string Params []string
forceTrailing bool
tags map[string]string tags map[string]string
clientOnlyTags map[string]string clientOnlyTags map[string]string
} }
// ForceTrailing ensures that when the message is serialized, the final parameter
// will be encoded as a "trailing parameter" (preceded by a colon). This is
// almost never necessary and should not be used except when having to interact
// with broken implementations that don't correctly interpret IRC messages.
func (msg *IrcMessage) ForceTrailing() {
msg.forceTrailing = true
}
// GetTag returns whether a tag is present, and if so, what its value is. // GetTag returns whether a tag is present, and if so, what its value is.
func (msg *IrcMessage) GetTag(tagName string) (present bool, value string) { func (msg *IrcMessage) GetTag(tagName string) (present bool, value string) {
if len(tagName) == 0 { if len(tagName) == 0 {
@ -321,6 +330,10 @@ func (ircmsg *IrcMessage) LineBytesStrict(fromClient bool, truncateLen int) ([]b
return ircmsg.line(tagLimit, clientOnlyTagDataLimit, serverAddedTagDataLimit, truncateLen) return ircmsg.line(tagLimit, clientOnlyTagDataLimit, serverAddedTagDataLimit, truncateLen)
} }
func paramRequiresTrailing(param string) bool {
return len(param) == 0 || strings.IndexByte(param, ' ') != -1 || param[0] == ':'
}
// line returns a sendable line created from an IrcMessage. // line returns a sendable line created from an IrcMessage.
func (ircmsg *IrcMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagDataLimit, truncateLen int) ([]byte, error) { func (ircmsg *IrcMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagDataLimit, truncateLen int) ([]byte, error) {
if len(ircmsg.Command) < 1 { if len(ircmsg.Command) < 1 {
@ -376,11 +389,12 @@ func (ircmsg *IrcMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagD
for i, param := range ircmsg.Params { for i, param := range ircmsg.Params {
buf.WriteByte(' ') buf.WriteByte(' ')
if len(param) < 1 || strings.IndexByte(param, ' ') != -1 || param[0] == ':' { requiresTrailing := paramRequiresTrailing(param)
if i != len(ircmsg.Params)-1 { lastParam := i == len(ircmsg.Params)-1
return nil, ErrorBadParam if (requiresTrailing || ircmsg.forceTrailing) && lastParam {
}
buf.WriteByte(':') buf.WriteByte(':')
} else if requiresTrailing && !lastParam {
return nil, ErrorBadParam
} }
buf.WriteString(param) buf.WriteString(param)
} }

2
vendor/modules.txt vendored
View File

@ -15,7 +15,7 @@ github.com/go-sql-driver/mysql
# github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940 # github.com/goshuirc/e-nfa v0.0.0-20160917075329-7071788e3940
## explicit ## explicit
github.com/goshuirc/e-nfa github.com/goshuirc/e-nfa
# github.com/goshuirc/irc-go v0.0.0-20190713001546-05ecc95249a0 # github.com/goshuirc/irc-go v0.0.0-20200311142257-57fd157327ac
## explicit ## explicit
github.com/goshuirc/irc-go/ircfmt github.com/goshuirc/irc-go/ircfmt
github.com/goshuirc/irc-go/ircmatch github.com/goshuirc/irc-go/ircmatch