Handle upstream multi-line SASL
References: https://todo.sr.ht/~emersion/soju/173
This commit is contained in:
parent
e7f9d2332b
commit
fe564af756
@ -983,7 +983,7 @@ func (dc *downstreamConn) handleAuthenticateCommand(msg *irc.Message) (result *d
|
||||
|
||||
dc.sasl.pendingResp.WriteString(chunk)
|
||||
|
||||
if len(chunk) == 400 {
|
||||
if len(chunk) == maxSASLLength {
|
||||
return nil, nil // Multi-line response, wait for the next command
|
||||
}
|
||||
|
||||
|
1
irc.go
1
irc.go
@ -25,6 +25,7 @@ const (
|
||||
const (
|
||||
maxMessageLength = 512
|
||||
maxMessageParams = 15
|
||||
maxSASLLength = 400
|
||||
)
|
||||
|
||||
// The server-time layout, as defined in the IRCv3 spec.
|
||||
|
16
upstream.go
16
upstream.go
@ -619,16 +619,26 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: send response in multiple chunks if >= 400 bytes
|
||||
// <= instead of < because we need to send a final empty response if
|
||||
// the last chunk is exactly 400 bytes long
|
||||
for i := 0; i <= len(resp); i += maxSASLLength {
|
||||
j := i + maxSASLLength
|
||||
if j > len(resp) {
|
||||
j = len(resp)
|
||||
}
|
||||
|
||||
chunk := resp[i:j]
|
||||
|
||||
var respStr = "+"
|
||||
if len(resp) != 0 {
|
||||
respStr = base64.StdEncoding.EncodeToString(resp)
|
||||
if len(chunk) != 0 {
|
||||
respStr = base64.StdEncoding.EncodeToString(chunk)
|
||||
}
|
||||
|
||||
uc.SendMessage(ctx, &irc.Message{
|
||||
Command: "AUTHENTICATE",
|
||||
Params: []string{respStr},
|
||||
})
|
||||
}
|
||||
case irc.RPL_LOGGEDIN:
|
||||
if err := parseMessageParams(msg, nil, nil, &uc.account); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user