2017-09-29 09:33:29 +02:00
|
|
|
// Copyright (c) 2017 Daniel Oaks <daniel@danieloaks.net>
|
|
|
|
// released under the MIT license
|
|
|
|
|
2017-09-29 04:07:52 +02:00
|
|
|
package caps
|
|
|
|
|
2018-06-26 00:08:15 +02:00
|
|
|
import "errors"
|
|
|
|
|
2017-09-29 04:07:52 +02:00
|
|
|
// Capability represents an optional feature that a client may request from the server.
|
2018-06-26 00:08:15 +02:00
|
|
|
type Capability uint
|
2017-09-29 04:07:52 +02:00
|
|
|
|
2018-06-26 00:08:15 +02:00
|
|
|
// actual capability definitions appear in defs.go
|
2018-02-10 23:57:15 +01:00
|
|
|
|
2018-06-26 00:08:15 +02:00
|
|
|
var (
|
|
|
|
nameToCapability map[string]Capability
|
|
|
|
|
|
|
|
NoSuchCap = errors.New("Unsupported capability name")
|
2017-09-29 04:07:52 +02:00
|
|
|
)
|
|
|
|
|
2017-09-29 09:25:58 +02:00
|
|
|
// Name returns the name of the given capability.
|
|
|
|
func (capability Capability) Name() string {
|
2018-06-26 00:08:15 +02:00
|
|
|
return capabilityNames[capability]
|
|
|
|
}
|
|
|
|
|
|
|
|
func NameToCapability(name string) (result Capability, err error) {
|
|
|
|
result, found := nameToCapability[name]
|
|
|
|
if !found {
|
|
|
|
err = NoSuchCap
|
|
|
|
}
|
|
|
|
return
|
2017-09-29 04:07:52 +02:00
|
|
|
}
|
2017-10-07 14:19:37 +02:00
|
|
|
|
|
|
|
// Version is used to select which max version of CAP the client supports.
|
|
|
|
type Version uint
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Cap301 refers to the base CAP spec.
|
|
|
|
Cap301 Version = 301
|
|
|
|
// Cap302 refers to the IRCv3.2 CAP spec.
|
|
|
|
Cap302 Version = 302
|
|
|
|
)
|
2018-02-03 12:15:07 +01:00
|
|
|
|
|
|
|
// State shows whether we're negotiating caps, finished, etc for connection registration.
|
|
|
|
type State uint
|
|
|
|
|
|
|
|
const (
|
|
|
|
// NoneState means CAP hasn't been negotiated at all.
|
|
|
|
NoneState State = iota
|
|
|
|
// NegotiatingState means CAP is being negotiated and registration should be paused.
|
|
|
|
NegotiatingState State = iota
|
|
|
|
// NegotiatedState means CAP negotiation has been successfully ended and reg should complete.
|
|
|
|
NegotiatedState State = iota
|
|
|
|
)
|
2018-06-26 00:08:15 +02:00
|
|
|
|
2018-06-26 04:50:57 +02:00
|
|
|
const (
|
|
|
|
// LabelTagName is the tag name used for the labeled-response spec.
|
|
|
|
// https://ircv3.net/specs/extensions/labeled-response.html
|
|
|
|
LabelTagName = "draft/label"
|
2019-12-23 21:26:37 +01:00
|
|
|
// More draft names associated with draft/multiline:
|
|
|
|
MultilineBatchType = "draft/multiline"
|
|
|
|
MultilineConcatTag = "draft/multiline-concat"
|
2018-06-26 04:50:57 +02:00
|
|
|
)
|
|
|
|
|
2018-06-26 00:08:15 +02:00
|
|
|
func init() {
|
|
|
|
nameToCapability = make(map[string]Capability)
|
|
|
|
for capab, name := range capabilityNames {
|
|
|
|
nameToCapability[name] = Capability(capab)
|
|
|
|
}
|
|
|
|
}
|