Changeset 761 in code


Ignore:
Timestamp:
Dec 10, 2021, 9:46:41 AM (3 years ago)
Author:
contact
Message:

Handle upstream multi-line SASL

References: https://todo.sr.ht/~emersion/soju/173

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r760 r761  
    984984                dc.sasl.pendingResp.WriteString(chunk)
    985985
    986                 if len(chunk) == 400 {
     986                if len(chunk) == maxSASLLength {
    987987                        return nil, nil // Multi-line response, wait for the next command
    988988                }
  • trunk/irc.go

    r684 r761  
    2626        maxMessageLength = 512
    2727        maxMessageParams = 15
     28        maxSASLLength    = 400
    2829)
    2930
  • trunk/upstream.go

    r759 r761  
    620620                }
    621621
    622                 // TODO: send response in multiple chunks if >= 400 bytes
    623                 var respStr = "+"
    624                 if len(resp) != 0 {
    625                         respStr = base64.StdEncoding.EncodeToString(resp)
    626                 }
    627 
    628                 uc.SendMessage(ctx, &irc.Message{
    629                         Command: "AUTHENTICATE",
    630                         Params:  []string{respStr},
    631                 })
     622                // <= instead of < because we need to send a final empty response if
     623                // the last chunk is exactly 400 bytes long
     624                for i := 0; i <= len(resp); i += maxSASLLength {
     625                        j := i + maxSASLLength
     626                        if j > len(resp) {
     627                                j = len(resp)
     628                        }
     629
     630                        chunk := resp[i:j]
     631
     632                        var respStr = "+"
     633                        if len(chunk) != 0 {
     634                                respStr = base64.StdEncoding.EncodeToString(chunk)
     635                        }
     636
     637                        uc.SendMessage(ctx, &irc.Message{
     638                                Command: "AUTHENTICATE",
     639                                Params:  []string{respStr},
     640                        })
     641                }
    632642        case irc.RPL_LOGGEDIN:
    633643                if err := parseMessageParams(msg, nil, nil, &uc.account); err != nil {
Note: See TracChangeset for help on using the changeset viewer.