diff --git a/go.mod b/go.mod index 1e506b1..679bd52 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,18 @@ module gogs.inhome.blapointe.com/local-sandbox/contact go 1.20 + +replace gogs.inhome.blapointe.com/local-sandbox/contact/contact => ./contact + +require ( + gogs.inhome.blapointe.com/local-sandbox/contact/contact v0.0.0-00010101000000-000000000000 + gogs.inhome.blapointe.com/local/args v0.0.0-20230410154220-44370f257b34 +) + +require ( + github.com/bytbox/go-pop3 v0.0.0-20120201222208-3046caf0763e // indirect + github.com/emersion/go-imap v1.2.0 // indirect + github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 // indirect + golang.org/x/text v0.3.7 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..eef4926 --- /dev/null +++ b/go.sum @@ -0,0 +1,18 @@ +github.com/bytbox/go-pop3 v0.0.0-20120201222208-3046caf0763e h1:mQTN05gz0rDZSABqKMzAPMb5ATWcvvdMljRzEh0LjBo= +github.com/bytbox/go-pop3 v0.0.0-20120201222208-3046caf0763e/go.mod h1:alXX+s7a4cKaIprgjeEboqi4Tm7XR/HXEwUTxUV/ywU= +github.com/emersion/go-imap v1.2.0 h1:lyUQ3+EVM21/qbWE/4Ya5UG9r5+usDxlg4yfp3TgHFA= +github.com/emersion/go-imap v1.2.0/go.mod h1:Qlx1FSx2FTxjnjWpIlVNEuX+ylerZQNFE5NsmKFSejY= +github.com/emersion/go-message v0.15.0/go.mod h1:wQUEfE+38+7EW8p8aZ96ptg6bAb1iwdgej19uXASlE4= +github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ= +github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= +github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= +gogs.inhome.blapointe.com/local/args v0.0.0-20230410154220-44370f257b34 h1:0tuX5dfOksiOQD1vbJjVNVTVxTTIng7UrUdSLF5T+Ao= +gogs.inhome.blapointe.com/local/args v0.0.0-20230410154220-44370f257b34/go.mod h1:YG9n3Clg7683ohkVnJK2hdX8bBS9EojIsd1qPZumX0Y= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/vendor/github.com/bytbox/go-pop3/.gitignore b/vendor/github.com/bytbox/go-pop3/.gitignore deleted file mode 100644 index 1377554..0000000 --- a/vendor/github.com/bytbox/go-pop3/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.swp diff --git a/vendor/github.com/bytbox/go-pop3/LICENSE b/vendor/github.com/bytbox/go-pop3/LICENSE deleted file mode 100644 index 3256b58..0000000 --- a/vendor/github.com/bytbox/go-pop3/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2012 Scott Lawrence - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/bytbox/go-pop3/pop3.go b/vendor/github.com/bytbox/go-pop3/pop3.go deleted file mode 100644 index 52e3ecf..0000000 --- a/vendor/github.com/bytbox/go-pop3/pop3.go +++ /dev/null @@ -1,223 +0,0 @@ -// Package pop3 provides an implementation of the Post Office Protocol, Version -// 3 as defined in RFC 1939. Commands specified as optional are not -// implemented; however, this implementation may be trivially extended to -// support them. - -package pop3 - -import ( - "bufio" - "crypto/tls" - "errors" - "fmt" - "net" - "strconv" - "strings" -) - -// The POP3 client. -type Client struct { - conn net.Conn - bin *bufio.Reader -} - -// Dial creates an unsecured connection to the POP3 server at the given address -// and returns the corresponding Client. -func Dial(addr string) (*Client, error) { - conn, err := net.Dial("tcp", addr) - if err != nil { - return nil, err - } - return NewClient(conn) -} - -// DialTLS creates a TLS-secured connection to the POP3 server at the given -// address and returns the corresponding Client. -func DialTLS(addr string) (*Client, error) { - conn, err := tls.Dial("tcp", addr, nil) - if err != nil { - return nil, err - } - return NewClient(conn) -} - -// NewClient returns a new Client object using an existing connection. -func NewClient(conn net.Conn) (*Client, error) { - client := &Client{ - bin: bufio.NewReader(conn), - conn: conn, - } - // send dud command, to read a line - _, err := client.Cmd("") - if err != nil { - return nil, err - } - return client, nil -} - -// Convenience function to synchronously run an arbitrary command and wait for -// output. The terminating CRLF must be included in the format string. -// -// Output sent after the first line must be retrieved via readLines. -func (c *Client) Cmd(format string, args ...interface{}) (string, error) { - fmt.Fprintf(c.conn, format, args...) - line, _, err := c.bin.ReadLine() - if err != nil { return "", err } - l := string(line) - if l[0:3] != "+OK" { - err = errors.New(l[5:]) - } - if len(l) >= 4 { - return l[4:], err - } - return "", err -} - -func (c *Client) ReadLines() (lines []string, err error) { - lines = make([]string, 0) - l, _, err := c.bin.ReadLine() - line := string(l) - for err == nil && line != "." { - if len(line) > 0 && line[0] == '.' { - line = line[1:] - } - lines = append(lines, line) - l, _, err = c.bin.ReadLine() - line = string(l) - } - return -} - -// User sends the given username to the server. Generally, there is no reason -// not to use the Auth convenience method. -func (c *Client) User(username string) (err error) { - _, err = c.Cmd("USER %s\r\n", username) - return -} - -// Pass sends the given password to the server. The password is sent -// unencrypted unless the connection is already secured by TLS (via DialTLS or -// some other mechanism). Generally, there is no reason not to use the Auth -// convenience method. -func (c *Client) Pass(password string) (err error) { - _, err = c.Cmd("PASS %s\r\n", password) - return -} - -// Auth sends the given username and password to the server, calling the User -// and Pass methods as appropriate. -func (c *Client) Auth(username, password string) (err error) { - err = c.User(username) - if err != nil { - return - } - err = c.Pass(password) - return -} - -// Stat retrieves a drop listing for the current maildrop, consisting of the -// number of messages and the total size (in octets) of the maildrop. -// Information provided besides the number of messages and the size of the -// maildrop is ignored. In the event of an error, all returned numeric values -// will be 0. -func (c *Client) Stat() (count, size int, err error) { - l, err := c.Cmd("STAT\r\n") - if err != nil { - return 0, 0, err - } - parts := strings.Fields(l) - count, err = strconv.Atoi(parts[0]) - if err != nil { - return 0, 0, errors.New("Invalid server response") - } - size, err = strconv.Atoi(parts[1]) - if err != nil { - return 0, 0, errors.New("Invalid server response") - } - return -} - -// List returns the size of the given message, if it exists. If the message -// does not exist, or another error is encountered, the returned size will be -// 0. -func (c *Client) List(msg int) (size int, err error) { - l, err := c.Cmd("LIST %d\r\n", msg) - if err != nil { - return 0, err - } - size, err = strconv.Atoi(strings.Fields(l)[1]) - if err != nil { - return 0, errors.New("Invalid server response") - } - return size, nil -} - -// ListAll returns a list of all messages and their sizes. -func (c *Client) ListAll() (msgs []int, sizes []int, err error) { - _, err = c.Cmd("LIST\r\n") - if err != nil { - return - } - lines, err := c.ReadLines() - if err != nil { - return - } - msgs = make([]int, len(lines), len(lines)) - sizes = make([]int, len(lines), len(lines)) - for i, l := range lines { - var m, s int - fs := strings.Fields(l) - m, err = strconv.Atoi(fs[0]) - if err != nil { - return - } - s, err = strconv.Atoi(fs[1]) - if err != nil { - return - } - msgs[i] = m - sizes[i] = s - } - return -} - -// Retr downloads and returns the given message. The lines are separated by LF, -// whatever the server sent. -func (c *Client) Retr(msg int) (text string, err error) { - _, err = c.Cmd("RETR %d\r\n", msg) - if err != nil { - return "", err - } - lines, err := c.ReadLines() - text = strings.Join(lines, "\n") - return -} - -// Dele marks the given message as deleted. -func (c *Client) Dele(msg int) (err error) { - _, err = c.Cmd("DELE %d\r\n", msg) - return -} - -// Noop does nothing, but will prolong the end of the connection if the server -// has a timeout set. -func (c *Client) Noop() (err error) { - _, err = c.Cmd("NOOP\r\n") - return -} - -// Rset unmarks any messages marked for deletion previously in this session. -func (c *Client) Rset() (err error) { - _, err = c.Cmd("RSET\r\n") - return -} - -// Quit sends the QUIT message to the POP3 server and closes the connection. -func (c *Client) Quit() error { - _, err := c.Cmd("QUIT\r\n") - if err != nil { - return err - } - c.conn.Close() - return nil -} diff --git a/vendor/github.com/emersion/go-imap/.build.yml b/vendor/github.com/emersion/go-imap/.build.yml deleted file mode 100644 index 2617917..0000000 --- a/vendor/github.com/emersion/go-imap/.build.yml +++ /dev/null @@ -1,17 +0,0 @@ -image: alpine/edge -packages: - - go -sources: - - https://github.com/emersion/go-imap -artifacts: - - coverage.html -tasks: - - build: | - cd go-imap - go build -race -v ./... - - test: | - cd go-imap - go test -coverprofile=coverage.txt -covermode=atomic ./... - - coverage: | - cd go-imap - go tool cover -html=coverage.txt -o ~/coverage.html diff --git a/vendor/github.com/emersion/go-imap/.gitignore b/vendor/github.com/emersion/go-imap/.gitignore deleted file mode 100644 index 59506a2..0000000 --- a/vendor/github.com/emersion/go-imap/.gitignore +++ /dev/null @@ -1,28 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof - -/client.go -/server.go -coverage.txt diff --git a/vendor/github.com/emersion/go-imap/LICENSE b/vendor/github.com/emersion/go-imap/LICENSE deleted file mode 100644 index f55742d..0000000 --- a/vendor/github.com/emersion/go-imap/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 The Go-IMAP Authors -Copyright (c) 2016 emersion -Copyright (c) 2016 Proton Technologies AG - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/emersion/go-imap/README.md b/vendor/github.com/emersion/go-imap/README.md deleted file mode 100644 index f0f2175..0000000 --- a/vendor/github.com/emersion/go-imap/README.md +++ /dev/null @@ -1,177 +0,0 @@ -# go-imap - -[![godocs.io](https://godocs.io/github.com/emersion/go-imap?status.svg)](https://godocs.io/github.com/emersion/go-imap) -[![builds.sr.ht status](https://builds.sr.ht/~emersion/go-imap/commits.svg)](https://builds.sr.ht/~emersion/go-imap/commits?) - -An [IMAP4rev1](https://tools.ietf.org/html/rfc3501) library written in Go. It -can be used to build a client and/or a server. - -## Usage - -### Client [![godocs.io](https://godocs.io/github.com/emersion/go-imap/client?status.svg)](https://godocs.io/github.com/emersion/go-imap/client) - -```go -package main - -import ( - "log" - - "github.com/emersion/go-imap/client" - "github.com/emersion/go-imap" -) - -func main() { - log.Println("Connecting to server...") - - // Connect to server - c, err := client.DialTLS("mail.example.org:993", nil) - if err != nil { - log.Fatal(err) - } - log.Println("Connected") - - // Don't forget to logout - defer c.Logout() - - // Login - if err := c.Login("username", "password"); err != nil { - log.Fatal(err) - } - log.Println("Logged in") - - // List mailboxes - mailboxes := make(chan *imap.MailboxInfo, 10) - done := make(chan error, 1) - go func () { - done <- c.List("", "*", mailboxes) - }() - - log.Println("Mailboxes:") - for m := range mailboxes { - log.Println("* " + m.Name) - } - - if err := <-done; err != nil { - log.Fatal(err) - } - - // Select INBOX - mbox, err := c.Select("INBOX", false) - if err != nil { - log.Fatal(err) - } - log.Println("Flags for INBOX:", mbox.Flags) - - // Get the last 4 messages - from := uint32(1) - to := mbox.Messages - if mbox.Messages > 3 { - // We're using unsigned integers here, only subtract if the result is > 0 - from = mbox.Messages - 3 - } - seqset := new(imap.SeqSet) - seqset.AddRange(from, to) - - messages := make(chan *imap.Message, 10) - done = make(chan error, 1) - go func() { - done <- c.Fetch(seqset, []imap.FetchItem{imap.FetchEnvelope}, messages) - }() - - log.Println("Last 4 messages:") - for msg := range messages { - log.Println("* " + msg.Envelope.Subject) - } - - if err := <-done; err != nil { - log.Fatal(err) - } - - log.Println("Done!") -} -``` - -### Server [![godocs.io](https://godocs.io/github.com/emersion/go-imap/server?status.svg)](https://godocs.io/github.com/emersion/go-imap/server) - -```go -package main - -import ( - "log" - - "github.com/emersion/go-imap/server" - "github.com/emersion/go-imap/backend/memory" -) - -func main() { - // Create a memory backend - be := memory.New() - - // Create a new server - s := server.New(be) - s.Addr = ":1143" - // Since we will use this server for testing only, we can allow plain text - // authentication over unencrypted connections - s.AllowInsecureAuth = true - - log.Println("Starting IMAP server at localhost:1143") - if err := s.ListenAndServe(); err != nil { - log.Fatal(err) - } -} -``` - -You can now use `telnet localhost 1143` to manually connect to the server. - -## Extensions - -Support for several IMAP extensions is included in go-imap itself. This -includes: - -* [APPENDLIMIT](https://tools.ietf.org/html/rfc7889) -* [CHILDREN](https://tools.ietf.org/html/rfc3348) -* [ENABLE](https://tools.ietf.org/html/rfc5161) -* [IDLE](https://tools.ietf.org/html/rfc2177) -* [IMPORTANT](https://tools.ietf.org/html/rfc8457) -* [LITERAL+](https://tools.ietf.org/html/rfc7888) -* [MOVE](https://tools.ietf.org/html/rfc6851) -* [SASL-IR](https://tools.ietf.org/html/rfc4959) -* [SPECIAL-USE](https://tools.ietf.org/html/rfc6154) -* [UNSELECT](https://tools.ietf.org/html/rfc3691) - -Support for other extensions is provided via separate packages. See below. - -## Extending go-imap - -### Extensions - -Commands defined in IMAP extensions are available in other packages. See [the -wiki](https://github.com/emersion/go-imap/wiki/Using-extensions#using-client-extensions) -to learn how to use them. - -* [COMPRESS](https://github.com/emersion/go-imap-compress) -* [ID](https://github.com/ProtonMail/go-imap-id) -* [METADATA](https://github.com/emersion/go-imap-metadata) -* [NAMESPACE](https://github.com/foxcpp/go-imap-namespace) -* [QUOTA](https://github.com/emersion/go-imap-quota) -* [SORT and THREAD](https://github.com/emersion/go-imap-sortthread) -* [UIDPLUS](https://github.com/emersion/go-imap-uidplus) - -### Server backends - -* [Memory](https://github.com/emersion/go-imap/tree/master/backend/memory) (for testing) -* [Multi](https://github.com/emersion/go-imap-multi) -* [PGP](https://github.com/emersion/go-imap-pgp) -* [Proxy](https://github.com/emersion/go-imap-proxy) - -### Related projects - -* [go-message](https://github.com/emersion/go-message) - parsing and formatting MIME and mail messages -* [go-msgauth](https://github.com/emersion/go-msgauth) - handle DKIM, DMARC and Authentication-Results -* [go-pgpmail](https://github.com/emersion/go-pgpmail) - decrypting and encrypting mails with OpenPGP -* [go-sasl](https://github.com/emersion/go-sasl) - sending and receiving SASL authentications -* [go-smtp](https://github.com/emersion/go-smtp) - building SMTP clients and servers - -## License - -MIT diff --git a/vendor/github.com/emersion/go-imap/client/client.go b/vendor/github.com/emersion/go-imap/client/client.go deleted file mode 100644 index 8b6fc84..0000000 --- a/vendor/github.com/emersion/go-imap/client/client.go +++ /dev/null @@ -1,689 +0,0 @@ -// Package client provides an IMAP client. -// -// It is not safe to use the same Client from multiple goroutines. In general, -// the IMAP protocol doesn't make it possible to send multiple independent -// IMAP commands on the same connection. -package client - -import ( - "crypto/tls" - "fmt" - "io" - "log" - "net" - "os" - "sync" - "time" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/commands" - "github.com/emersion/go-imap/responses" -) - -// errClosed is used when a connection is closed while waiting for a command -// response. -var errClosed = fmt.Errorf("imap: connection closed") - -// errUnregisterHandler is returned by a response handler to unregister itself. -var errUnregisterHandler = fmt.Errorf("imap: unregister handler") - -// Update is an unilateral server update. -type Update interface { - update() -} - -// StatusUpdate is delivered when a status update is received. -type StatusUpdate struct { - Status *imap.StatusResp -} - -func (u *StatusUpdate) update() {} - -// MailboxUpdate is delivered when a mailbox status changes. -type MailboxUpdate struct { - Mailbox *imap.MailboxStatus -} - -func (u *MailboxUpdate) update() {} - -// ExpungeUpdate is delivered when a message is deleted. -type ExpungeUpdate struct { - SeqNum uint32 -} - -func (u *ExpungeUpdate) update() {} - -// MessageUpdate is delivered when a message attribute changes. -type MessageUpdate struct { - Message *imap.Message -} - -func (u *MessageUpdate) update() {} - -// Client is an IMAP client. -type Client struct { - conn *imap.Conn - isTLS bool - serverName string - - loggedOut chan struct{} - continues chan<- bool - upgrading bool - - handlers []responses.Handler - handlersLocker sync.Mutex - - // The current connection state. - state imap.ConnState - // The selected mailbox, if there is one. - mailbox *imap.MailboxStatus - // The cached server capabilities. - caps map[string]bool - // state, mailbox and caps may be accessed in different goroutines. Protect - // access. - locker sync.Mutex - - // A channel to which unilateral updates from the server will be sent. An - // update can be one of: *StatusUpdate, *MailboxUpdate, *MessageUpdate, - // *ExpungeUpdate. Note that blocking this channel blocks the whole client, - // so it's recommended to use a separate goroutine and a buffered channel to - // prevent deadlocks. - Updates chan<- Update - - // ErrorLog specifies an optional logger for errors accepting connections and - // unexpected behavior from handlers. By default, logging goes to os.Stderr - // via the log package's standard logger. The logger must be safe to use - // simultaneously from multiple goroutines. - ErrorLog imap.Logger - - // Timeout specifies a maximum amount of time to wait on a command. - // - // A Timeout of zero means no timeout. This is the default. - Timeout time.Duration -} - -func (c *Client) registerHandler(h responses.Handler) { - if h == nil { - return - } - - c.handlersLocker.Lock() - c.handlers = append(c.handlers, h) - c.handlersLocker.Unlock() -} - -func (c *Client) handle(resp imap.Resp) error { - c.handlersLocker.Lock() - for i := len(c.handlers) - 1; i >= 0; i-- { - if err := c.handlers[i].Handle(resp); err != responses.ErrUnhandled { - if err == errUnregisterHandler { - c.handlers = append(c.handlers[:i], c.handlers[i+1:]...) - err = nil - } - c.handlersLocker.Unlock() - return err - } - } - c.handlersLocker.Unlock() - return responses.ErrUnhandled -} - -func (c *Client) reader() { - defer close(c.loggedOut) - // Loop while connected. - for { - connected, err := c.readOnce() - if err != nil { - c.ErrorLog.Println("error reading response:", err) - } - if !connected { - return - } - } -} - -func (c *Client) readOnce() (bool, error) { - if c.State() == imap.LogoutState { - return false, nil - } - - resp, err := imap.ReadResp(c.conn.Reader) - if err == io.EOF || c.State() == imap.LogoutState { - return false, nil - } else if err != nil { - if imap.IsParseError(err) { - return true, err - } else { - return false, err - } - } - - if err := c.handle(resp); err != nil && err != responses.ErrUnhandled { - c.ErrorLog.Println("cannot handle response ", resp, err) - } - return true, nil -} - -func (c *Client) writeReply(reply []byte) error { - if _, err := c.conn.Writer.Write(reply); err != nil { - return err - } - // Flush reply - return c.conn.Writer.Flush() -} - -type handleResult struct { - status *imap.StatusResp - err error -} - -func (c *Client) execute(cmdr imap.Commander, h responses.Handler) (*imap.StatusResp, error) { - cmd := cmdr.Command() - cmd.Tag = generateTag() - - var replies <-chan []byte - if replier, ok := h.(responses.Replier); ok { - replies = replier.Replies() - } - - if c.Timeout > 0 { - err := c.conn.SetDeadline(time.Now().Add(c.Timeout)) - if err != nil { - return nil, err - } - } else { - // It's possible the client had a timeout set from a previous command, but no - // longer does. Ensure we respect that. The zero time means no deadline. - if err := c.conn.SetDeadline(time.Time{}); err != nil { - return nil, err - } - } - - // Check if we are upgrading. - upgrading := c.upgrading - - // Add handler before sending command, to be sure to get the response in time - // (in tests, the response is sent right after our command is received, so - // sometimes the response was received before the setup of this handler) - doneHandle := make(chan handleResult, 1) - unregister := make(chan struct{}) - c.registerHandler(responses.HandlerFunc(func(resp imap.Resp) error { - select { - case <-unregister: - // If an error occured while sending the command, abort - return errUnregisterHandler - default: - } - - if s, ok := resp.(*imap.StatusResp); ok && s.Tag == cmd.Tag { - // This is the command's status response, we're done - doneHandle <- handleResult{s, nil} - // Special handling of connection upgrading. - if upgrading { - c.upgrading = false - // Wait for upgrade to finish. - c.conn.Wait() - } - // Cancel any pending literal write - select { - case c.continues <- false: - default: - } - return errUnregisterHandler - } - - if h != nil { - // Pass the response to the response handler - if err := h.Handle(resp); err != nil && err != responses.ErrUnhandled { - // If the response handler returns an error, abort - doneHandle <- handleResult{nil, err} - return errUnregisterHandler - } else { - return err - } - } - return responses.ErrUnhandled - })) - - // Send the command to the server - if err := cmd.WriteTo(c.conn.Writer); err != nil { - // Error while sending the command - close(unregister) - - if err, ok := err.(imap.LiteralLengthErr); ok { - // Expected > Actual - // The server is waiting for us to write - // more bytes, we don't have them. Run. - // Expected < Actual - // We are about to send a potentially truncated message, we don't - // want this (ths terminating CRLF is not sent at this point). - c.conn.Close() - return nil, err - } - - return nil, err - } - // Flush writer if we are upgrading - if upgrading { - if err := c.conn.Writer.Flush(); err != nil { - // Error while sending the command - close(unregister) - return nil, err - } - } - - for { - select { - case reply := <-replies: - // Response handler needs to send a reply (Used for AUTHENTICATE) - if err := c.writeReply(reply); err != nil { - close(unregister) - return nil, err - } - case <-c.loggedOut: - // If the connection is closed (such as from an I/O error), ensure we - // realize this and don't block waiting on a response that will never - // come. loggedOut is a channel that closes when the reader goroutine - // ends. - close(unregister) - return nil, errClosed - case result := <-doneHandle: - return result.status, result.err - } - } -} - -// State returns the current connection state. -func (c *Client) State() imap.ConnState { - c.locker.Lock() - state := c.state - c.locker.Unlock() - return state -} - -// Mailbox returns the selected mailbox. It returns nil if there isn't one. -func (c *Client) Mailbox() *imap.MailboxStatus { - // c.Mailbox fields are not supposed to change, so we can return the pointer. - c.locker.Lock() - mbox := c.mailbox - c.locker.Unlock() - return mbox -} - -// SetState sets this connection's internal state. -// -// This function should not be called directly, it must only be used by -// libraries implementing extensions of the IMAP protocol. -func (c *Client) SetState(state imap.ConnState, mailbox *imap.MailboxStatus) { - c.locker.Lock() - c.state = state - c.mailbox = mailbox - c.locker.Unlock() -} - -// Execute executes a generic command. cmdr is a value that can be converted to -// a raw command and h is a response handler. The function returns when the -// command has completed or failed, in this case err is nil. A non-nil err value -// indicates a network error. -// -// This function should not be called directly, it must only be used by -// libraries implementing extensions of the IMAP protocol. -func (c *Client) Execute(cmdr imap.Commander, h responses.Handler) (*imap.StatusResp, error) { - return c.execute(cmdr, h) -} - -func (c *Client) handleContinuationReqs() { - c.registerHandler(responses.HandlerFunc(func(resp imap.Resp) error { - if _, ok := resp.(*imap.ContinuationReq); ok { - go func() { - c.continues <- true - }() - return nil - } - return responses.ErrUnhandled - })) -} - -func (c *Client) gotStatusCaps(args []interface{}) { - c.locker.Lock() - - c.caps = make(map[string]bool) - for _, cap := range args { - if cap, ok := cap.(string); ok { - c.caps[cap] = true - } - } - - c.locker.Unlock() -} - -// The server can send unilateral data. This function handles it. -func (c *Client) handleUnilateral() { - c.registerHandler(responses.HandlerFunc(func(resp imap.Resp) error { - switch resp := resp.(type) { - case *imap.StatusResp: - if resp.Tag != "*" { - return responses.ErrUnhandled - } - - switch resp.Type { - case imap.StatusRespOk, imap.StatusRespNo, imap.StatusRespBad: - if c.Updates != nil { - c.Updates <- &StatusUpdate{resp} - } - case imap.StatusRespBye: - c.locker.Lock() - c.state = imap.LogoutState - c.mailbox = nil - c.locker.Unlock() - - c.conn.Close() - - if c.Updates != nil { - c.Updates <- &StatusUpdate{resp} - } - default: - return responses.ErrUnhandled - } - case *imap.DataResp: - name, fields, ok := imap.ParseNamedResp(resp) - if !ok { - return responses.ErrUnhandled - } - - switch name { - case "CAPABILITY": - c.gotStatusCaps(fields) - case "EXISTS": - if c.Mailbox() == nil { - break - } - - if messages, err := imap.ParseNumber(fields[0]); err == nil { - c.locker.Lock() - c.mailbox.Messages = messages - c.locker.Unlock() - - c.mailbox.ItemsLocker.Lock() - c.mailbox.Items[imap.StatusMessages] = nil - c.mailbox.ItemsLocker.Unlock() - } - - if c.Updates != nil { - c.Updates <- &MailboxUpdate{c.Mailbox()} - } - case "RECENT": - if c.Mailbox() == nil { - break - } - - if recent, err := imap.ParseNumber(fields[0]); err == nil { - c.locker.Lock() - c.mailbox.Recent = recent - c.locker.Unlock() - - c.mailbox.ItemsLocker.Lock() - c.mailbox.Items[imap.StatusRecent] = nil - c.mailbox.ItemsLocker.Unlock() - } - - if c.Updates != nil { - c.Updates <- &MailboxUpdate{c.Mailbox()} - } - case "EXPUNGE": - seqNum, _ := imap.ParseNumber(fields[0]) - - if c.Updates != nil { - c.Updates <- &ExpungeUpdate{seqNum} - } - case "FETCH": - seqNum, _ := imap.ParseNumber(fields[0]) - fields, _ := fields[1].([]interface{}) - - msg := &imap.Message{SeqNum: seqNum} - if err := msg.Parse(fields); err != nil { - break - } - - if c.Updates != nil { - c.Updates <- &MessageUpdate{msg} - } - default: - return responses.ErrUnhandled - } - default: - return responses.ErrUnhandled - } - return nil - })) -} - -func (c *Client) handleGreetAndStartReading() error { - var greetErr error - gotGreet := false - - c.registerHandler(responses.HandlerFunc(func(resp imap.Resp) error { - status, ok := resp.(*imap.StatusResp) - if !ok { - greetErr = fmt.Errorf("invalid greeting received from server: not a status response") - return errUnregisterHandler - } - - c.locker.Lock() - switch status.Type { - case imap.StatusRespPreauth: - c.state = imap.AuthenticatedState - case imap.StatusRespBye: - c.state = imap.LogoutState - case imap.StatusRespOk: - c.state = imap.NotAuthenticatedState - default: - c.state = imap.LogoutState - c.locker.Unlock() - greetErr = fmt.Errorf("invalid greeting received from server: %v", status.Type) - return errUnregisterHandler - } - c.locker.Unlock() - - if status.Code == imap.CodeCapability { - c.gotStatusCaps(status.Arguments) - } - - gotGreet = true - return errUnregisterHandler - })) - - // call `readOnce` until we get the greeting or an error - for !gotGreet { - connected, err := c.readOnce() - // Check for read errors - if err != nil { - // return read errors - return err - } - // Check for invalid greet - if greetErr != nil { - // return read errors - return greetErr - } - // Check if connection was closed. - if !connected { - // connection closed. - return io.EOF - } - } - - // We got the greeting, now start the reader goroutine. - go c.reader() - - return nil -} - -// Upgrade a connection, e.g. wrap an unencrypted connection with an encrypted -// tunnel. -// -// This function should not be called directly, it must only be used by -// libraries implementing extensions of the IMAP protocol. -func (c *Client) Upgrade(upgrader imap.ConnUpgrader) error { - return c.conn.Upgrade(upgrader) -} - -// Writer returns the imap.Writer for this client's connection. -// -// This function should not be called directly, it must only be used by -// libraries implementing extensions of the IMAP protocol. -func (c *Client) Writer() *imap.Writer { - return c.conn.Writer -} - -// IsTLS checks if this client's connection has TLS enabled. -func (c *Client) IsTLS() bool { - return c.isTLS -} - -// LoggedOut returns a channel which is closed when the connection to the server -// is closed. -func (c *Client) LoggedOut() <-chan struct{} { - return c.loggedOut -} - -// SetDebug defines an io.Writer to which all network activity will be logged. -// If nil is provided, network activity will not be logged. -func (c *Client) SetDebug(w io.Writer) { - // Need to send a command to unblock the reader goroutine. - cmd := new(commands.Noop) - err := c.Upgrade(func(conn net.Conn) (net.Conn, error) { - // Flag connection as in upgrading - c.upgrading = true - if status, err := c.execute(cmd, nil); err != nil { - return nil, err - } else if err := status.Err(); err != nil { - return nil, err - } - - // Wait for reader to block. - c.conn.WaitReady() - - c.conn.SetDebug(w) - return conn, nil - }) - if err != nil { - log.Println("SetDebug:", err) - } - -} - -// New creates a new client from an existing connection. -func New(conn net.Conn) (*Client, error) { - continues := make(chan bool) - w := imap.NewClientWriter(nil, continues) - r := imap.NewReader(nil) - - c := &Client{ - conn: imap.NewConn(conn, r, w), - loggedOut: make(chan struct{}), - continues: continues, - state: imap.ConnectingState, - ErrorLog: log.New(os.Stderr, "imap/client: ", log.LstdFlags), - } - - c.handleContinuationReqs() - c.handleUnilateral() - if err := c.handleGreetAndStartReading(); err != nil { - return c, err - } - - plusOk, _ := c.Support("LITERAL+") - minusOk, _ := c.Support("LITERAL-") - // We don't use non-sync literal if it is bigger than 4096 bytes, so - // LITERAL- is fine too. - c.conn.AllowAsyncLiterals = plusOk || minusOk - - return c, nil -} - -// Dial connects to an IMAP server using an unencrypted connection. -func Dial(addr string) (*Client, error) { - return DialWithDialer(new(net.Dialer), addr) -} - -type Dialer interface { - // Dial connects to the given address. - Dial(network, addr string) (net.Conn, error) -} - -// DialWithDialer connects to an IMAP server using an unencrypted connection -// using dialer.Dial. -// -// Among other uses, this allows to apply a dial timeout. -func DialWithDialer(dialer Dialer, addr string) (*Client, error) { - conn, err := dialer.Dial("tcp", addr) - if err != nil { - return nil, err - } - - // We don't return to the caller until we try to receive a greeting. As such, - // there is no way to set the client's Timeout for that action. As a - // workaround, if the dialer has a timeout set, use that for the connection's - // deadline. - if netDialer, ok := dialer.(*net.Dialer); ok && netDialer.Timeout > 0 { - err := conn.SetDeadline(time.Now().Add(netDialer.Timeout)) - if err != nil { - return nil, err - } - } - - c, err := New(conn) - if err != nil { - return nil, err - } - - c.serverName, _, _ = net.SplitHostPort(addr) - return c, nil -} - -// DialTLS connects to an IMAP server using an encrypted connection. -func DialTLS(addr string, tlsConfig *tls.Config) (*Client, error) { - return DialWithDialerTLS(new(net.Dialer), addr, tlsConfig) -} - -// DialWithDialerTLS connects to an IMAP server using an encrypted connection -// using dialer.Dial. -// -// Among other uses, this allows to apply a dial timeout. -func DialWithDialerTLS(dialer Dialer, addr string, tlsConfig *tls.Config) (*Client, error) { - conn, err := dialer.Dial("tcp", addr) - if err != nil { - return nil, err - } - - serverName, _, _ := net.SplitHostPort(addr) - if tlsConfig == nil { - tlsConfig = &tls.Config{} - } - if tlsConfig.ServerName == "" { - tlsConfig = tlsConfig.Clone() - tlsConfig.ServerName = serverName - } - tlsConn := tls.Client(conn, tlsConfig) - - // We don't return to the caller until we try to receive a greeting. As such, - // there is no way to set the client's Timeout for that action. As a - // workaround, if the dialer has a timeout set, use that for the connection's - // deadline. - if netDialer, ok := dialer.(*net.Dialer); ok && netDialer.Timeout > 0 { - err := tlsConn.SetDeadline(time.Now().Add(netDialer.Timeout)) - if err != nil { - return nil, err - } - } - - c, err := New(tlsConn) - if err != nil { - return nil, err - } - - c.isTLS = true - c.serverName = serverName - return c, nil -} diff --git a/vendor/github.com/emersion/go-imap/client/cmd_any.go b/vendor/github.com/emersion/go-imap/client/cmd_any.go deleted file mode 100644 index cb0d38a..0000000 --- a/vendor/github.com/emersion/go-imap/client/cmd_any.go +++ /dev/null @@ -1,88 +0,0 @@ -package client - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/commands" -) - -// ErrAlreadyLoggedOut is returned if Logout is called when the client is -// already logged out. -var ErrAlreadyLoggedOut = errors.New("Already logged out") - -// Capability requests a listing of capabilities that the server supports. -// Capabilities are often returned by the server with the greeting or with the -// STARTTLS and LOGIN responses, so usually explicitly requesting capabilities -// isn't needed. -// -// Most of the time, Support should be used instead. -func (c *Client) Capability() (map[string]bool, error) { - cmd := &commands.Capability{} - - if status, err := c.execute(cmd, nil); err != nil { - return nil, err - } else if err := status.Err(); err != nil { - return nil, err - } - - c.locker.Lock() - caps := c.caps - c.locker.Unlock() - return caps, nil -} - -// Support checks if cap is a capability supported by the server. If the server -// hasn't sent its capabilities yet, Support requests them. -func (c *Client) Support(cap string) (bool, error) { - c.locker.Lock() - ok := c.caps != nil - c.locker.Unlock() - - // If capabilities are not cached, request them - if !ok { - if _, err := c.Capability(); err != nil { - return false, err - } - } - - c.locker.Lock() - supported := c.caps[cap] - c.locker.Unlock() - - return supported, nil -} - -// Noop always succeeds and does nothing. -// -// It can be used as a periodic poll for new messages or message status updates -// during a period of inactivity. It can also be used to reset any inactivity -// autologout timer on the server. -func (c *Client) Noop() error { - cmd := new(commands.Noop) - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - return status.Err() -} - -// Logout gracefully closes the connection. -func (c *Client) Logout() error { - if c.State() == imap.LogoutState { - return ErrAlreadyLoggedOut - } - - cmd := new(commands.Logout) - - if status, err := c.execute(cmd, nil); err == errClosed { - // Server closed connection, that's what we want anyway - return nil - } else if err != nil { - return err - } else if status != nil { - return status.Err() - } - return nil -} diff --git a/vendor/github.com/emersion/go-imap/client/cmd_auth.go b/vendor/github.com/emersion/go-imap/client/cmd_auth.go deleted file mode 100644 index a280017..0000000 --- a/vendor/github.com/emersion/go-imap/client/cmd_auth.go +++ /dev/null @@ -1,380 +0,0 @@ -package client - -import ( - "errors" - "time" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/commands" - "github.com/emersion/go-imap/responses" -) - -// ErrNotLoggedIn is returned if a function that requires the client to be -// logged in is called then the client isn't. -var ErrNotLoggedIn = errors.New("Not logged in") - -func (c *Client) ensureAuthenticated() error { - state := c.State() - if state != imap.AuthenticatedState && state != imap.SelectedState { - return ErrNotLoggedIn - } - return nil -} - -// Select selects a mailbox so that messages in the mailbox can be accessed. Any -// currently selected mailbox is deselected before attempting the new selection. -// Even if the readOnly parameter is set to false, the server can decide to open -// the mailbox in read-only mode. -func (c *Client) Select(name string, readOnly bool) (*imap.MailboxStatus, error) { - if err := c.ensureAuthenticated(); err != nil { - return nil, err - } - - cmd := &commands.Select{ - Mailbox: name, - ReadOnly: readOnly, - } - - mbox := &imap.MailboxStatus{Name: name, Items: make(map[imap.StatusItem]interface{})} - res := &responses.Select{ - Mailbox: mbox, - } - c.locker.Lock() - c.mailbox = mbox - c.locker.Unlock() - - status, err := c.execute(cmd, res) - if err != nil { - c.locker.Lock() - c.mailbox = nil - c.locker.Unlock() - return nil, err - } - if err := status.Err(); err != nil { - c.locker.Lock() - c.mailbox = nil - c.locker.Unlock() - return nil, err - } - - c.locker.Lock() - mbox.ReadOnly = (status.Code == imap.CodeReadOnly) - c.state = imap.SelectedState - c.locker.Unlock() - return mbox, nil -} - -// Create creates a mailbox with the given name. -func (c *Client) Create(name string) error { - if err := c.ensureAuthenticated(); err != nil { - return err - } - - cmd := &commands.Create{ - Mailbox: name, - } - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - return status.Err() -} - -// Delete permanently removes the mailbox with the given name. -func (c *Client) Delete(name string) error { - if err := c.ensureAuthenticated(); err != nil { - return err - } - - cmd := &commands.Delete{ - Mailbox: name, - } - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - return status.Err() -} - -// Rename changes the name of a mailbox. -func (c *Client) Rename(existingName, newName string) error { - if err := c.ensureAuthenticated(); err != nil { - return err - } - - cmd := &commands.Rename{ - Existing: existingName, - New: newName, - } - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - return status.Err() -} - -// Subscribe adds the specified mailbox name to the server's set of "active" or -// "subscribed" mailboxes. -func (c *Client) Subscribe(name string) error { - if err := c.ensureAuthenticated(); err != nil { - return err - } - - cmd := &commands.Subscribe{ - Mailbox: name, - } - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - return status.Err() -} - -// Unsubscribe removes the specified mailbox name from the server's set of -// "active" or "subscribed" mailboxes. -func (c *Client) Unsubscribe(name string) error { - if err := c.ensureAuthenticated(); err != nil { - return err - } - - cmd := &commands.Unsubscribe{ - Mailbox: name, - } - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - return status.Err() -} - -// List returns a subset of names from the complete set of all names available -// to the client. -// -// An empty name argument is a special request to return the hierarchy delimiter -// and the root name of the name given in the reference. The character "*" is a -// wildcard, and matches zero or more characters at this position. The -// character "%" is similar to "*", but it does not match a hierarchy delimiter. -func (c *Client) List(ref, name string, ch chan *imap.MailboxInfo) error { - defer close(ch) - - if err := c.ensureAuthenticated(); err != nil { - return err - } - - cmd := &commands.List{ - Reference: ref, - Mailbox: name, - } - res := &responses.List{Mailboxes: ch} - - status, err := c.execute(cmd, res) - if err != nil { - return err - } - return status.Err() -} - -// Lsub returns a subset of names from the set of names that the user has -// declared as being "active" or "subscribed". -func (c *Client) Lsub(ref, name string, ch chan *imap.MailboxInfo) error { - defer close(ch) - - if err := c.ensureAuthenticated(); err != nil { - return err - } - - cmd := &commands.List{ - Reference: ref, - Mailbox: name, - Subscribed: true, - } - res := &responses.List{ - Mailboxes: ch, - Subscribed: true, - } - - status, err := c.execute(cmd, res) - if err != nil { - return err - } - return status.Err() -} - -// Status requests the status of the indicated mailbox. It does not change the -// currently selected mailbox, nor does it affect the state of any messages in -// the queried mailbox. -// -// See RFC 3501 section 6.3.10 for a list of items that can be requested. -func (c *Client) Status(name string, items []imap.StatusItem) (*imap.MailboxStatus, error) { - if err := c.ensureAuthenticated(); err != nil { - return nil, err - } - - cmd := &commands.Status{ - Mailbox: name, - Items: items, - } - res := &responses.Status{ - Mailbox: new(imap.MailboxStatus), - } - - status, err := c.execute(cmd, res) - if err != nil { - return nil, err - } - return res.Mailbox, status.Err() -} - -// Append appends the literal argument as a new message to the end of the -// specified destination mailbox. This argument SHOULD be in the format of an -// RFC 2822 message. flags and date are optional arguments and can be set to -// nil and the empty struct. -func (c *Client) Append(mbox string, flags []string, date time.Time, msg imap.Literal) error { - if err := c.ensureAuthenticated(); err != nil { - return err - } - - cmd := &commands.Append{ - Mailbox: mbox, - Flags: flags, - Date: date, - Message: msg, - } - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - return status.Err() -} - -// Enable requests the server to enable the named extensions. The extensions -// which were successfully enabled are returned. -// -// See RFC 5161 section 3.1. -func (c *Client) Enable(caps []string) ([]string, error) { - if ok, err := c.Support("ENABLE"); !ok || err != nil { - return nil, ErrExtensionUnsupported - } - - // ENABLE is invalid if a mailbox has been selected. - if c.State() != imap.AuthenticatedState { - return nil, ErrNotLoggedIn - } - - cmd := &commands.Enable{Caps: caps} - res := &responses.Enabled{} - - if status, err := c.Execute(cmd, res); err != nil { - return nil, err - } else { - return res.Caps, status.Err() - } -} - -func (c *Client) idle(stop <-chan struct{}) error { - cmd := &commands.Idle{} - - res := &responses.Idle{ - Stop: stop, - RepliesCh: make(chan []byte, 10), - } - - if status, err := c.Execute(cmd, res); err != nil { - return err - } else { - return status.Err() - } -} - -// IdleOptions holds options for Client.Idle. -type IdleOptions struct { - // LogoutTimeout is used to avoid being logged out by the server when - // idling. Each LogoutTimeout, the IDLE command is restarted. If set to - // zero, a default is used. If negative, this behavior is disabled. - LogoutTimeout time.Duration - // Poll interval when the server doesn't support IDLE. If zero, a default - // is used. If negative, polling is always disabled. - PollInterval time.Duration -} - -// Idle indicates to the server that the client is ready to receive unsolicited -// mailbox update messages. When the client wants to send commands again, it -// must first close stop. -// -// If the server doesn't support IDLE, go-imap falls back to polling. -func (c *Client) Idle(stop <-chan struct{}, opts *IdleOptions) error { - if ok, err := c.Support("IDLE"); err != nil { - return err - } else if !ok { - return c.idleFallback(stop, opts) - } - - logoutTimeout := 25 * time.Minute - if opts != nil { - if opts.LogoutTimeout > 0 { - logoutTimeout = opts.LogoutTimeout - } else if opts.LogoutTimeout < 0 { - return c.idle(stop) - } - } - - t := time.NewTicker(logoutTimeout) - defer t.Stop() - - for { - stopOrRestart := make(chan struct{}) - done := make(chan error, 1) - go func() { - done <- c.idle(stopOrRestart) - }() - - select { - case <-t.C: - close(stopOrRestart) - if err := <-done; err != nil { - return err - } - case <-stop: - close(stopOrRestart) - return <-done - case err := <-done: - close(stopOrRestart) - if err != nil { - return err - } - } - } -} - -func (c *Client) idleFallback(stop <-chan struct{}, opts *IdleOptions) error { - pollInterval := time.Minute - if opts != nil { - if opts.PollInterval > 0 { - pollInterval = opts.PollInterval - } else if opts.PollInterval < 0 { - return ErrExtensionUnsupported - } - } - - t := time.NewTicker(pollInterval) - defer t.Stop() - - for { - select { - case <-t.C: - if err := c.Noop(); err != nil { - return err - } - case <-stop: - return nil - case <-c.LoggedOut(): - return errors.New("disconnected while idling") - } - } -} diff --git a/vendor/github.com/emersion/go-imap/client/cmd_noauth.go b/vendor/github.com/emersion/go-imap/client/cmd_noauth.go deleted file mode 100644 index f9b34d3..0000000 --- a/vendor/github.com/emersion/go-imap/client/cmd_noauth.go +++ /dev/null @@ -1,174 +0,0 @@ -package client - -import ( - "crypto/tls" - "errors" - "net" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/commands" - "github.com/emersion/go-imap/responses" - "github.com/emersion/go-sasl" -) - -var ( - // ErrAlreadyLoggedIn is returned if Login or Authenticate is called when the - // client is already logged in. - ErrAlreadyLoggedIn = errors.New("Already logged in") - // ErrTLSAlreadyEnabled is returned if StartTLS is called when TLS is already - // enabled. - ErrTLSAlreadyEnabled = errors.New("TLS is already enabled") - // ErrLoginDisabled is returned if Login or Authenticate is called when the - // server has disabled authentication. Most of the time, calling enabling TLS - // solves the problem. - ErrLoginDisabled = errors.New("Login is disabled in current state") -) - -// SupportStartTLS checks if the server supports STARTTLS. -func (c *Client) SupportStartTLS() (bool, error) { - return c.Support("STARTTLS") -} - -// StartTLS starts TLS negotiation. -func (c *Client) StartTLS(tlsConfig *tls.Config) error { - if c.isTLS { - return ErrTLSAlreadyEnabled - } - - if tlsConfig == nil { - tlsConfig = new(tls.Config) - } - if tlsConfig.ServerName == "" { - tlsConfig = tlsConfig.Clone() - tlsConfig.ServerName = c.serverName - } - - cmd := new(commands.StartTLS) - - err := c.Upgrade(func(conn net.Conn) (net.Conn, error) { - // Flag connection as in upgrading - c.upgrading = true - if status, err := c.execute(cmd, nil); err != nil { - return nil, err - } else if err := status.Err(); err != nil { - return nil, err - } - - // Wait for reader to block. - c.conn.WaitReady() - tlsConn := tls.Client(conn, tlsConfig) - if err := tlsConn.Handshake(); err != nil { - return nil, err - } - - // Capabilities change when TLS is enabled - c.locker.Lock() - c.caps = nil - c.locker.Unlock() - - return tlsConn, nil - }) - if err != nil { - return err - } - - c.isTLS = true - return nil -} - -// SupportAuth checks if the server supports a given authentication mechanism. -func (c *Client) SupportAuth(mech string) (bool, error) { - return c.Support("AUTH=" + mech) -} - -// Authenticate indicates a SASL authentication mechanism to the server. If the -// server supports the requested authentication mechanism, it performs an -// authentication protocol exchange to authenticate and identify the client. -func (c *Client) Authenticate(auth sasl.Client) error { - if c.State() != imap.NotAuthenticatedState { - return ErrAlreadyLoggedIn - } - - mech, ir, err := auth.Start() - if err != nil { - return err - } - - cmd := &commands.Authenticate{ - Mechanism: mech, - } - - irOk, err := c.Support("SASL-IR") - if err != nil { - return err - } - if irOk { - cmd.InitialResponse = ir - } - - res := &responses.Authenticate{ - Mechanism: auth, - InitialResponse: ir, - RepliesCh: make(chan []byte, 10), - } - if irOk { - res.InitialResponse = nil - } - - status, err := c.execute(cmd, res) - if err != nil { - return err - } - if err = status.Err(); err != nil { - return err - } - - c.locker.Lock() - c.state = imap.AuthenticatedState - c.caps = nil // Capabilities change when user is logged in - c.locker.Unlock() - - if status.Code == "CAPABILITY" { - c.gotStatusCaps(status.Arguments) - } - - return nil -} - -// Login identifies the client to the server and carries the plaintext password -// authenticating this user. -func (c *Client) Login(username, password string) error { - if state := c.State(); state == imap.AuthenticatedState || state == imap.SelectedState { - return ErrAlreadyLoggedIn - } - - c.locker.Lock() - loginDisabled := c.caps != nil && c.caps["LOGINDISABLED"] - c.locker.Unlock() - if loginDisabled { - return ErrLoginDisabled - } - - cmd := &commands.Login{ - Username: username, - Password: password, - } - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - if err = status.Err(); err != nil { - return err - } - - c.locker.Lock() - c.state = imap.AuthenticatedState - c.caps = nil // Capabilities change when user is logged in - c.locker.Unlock() - - if status.Code == "CAPABILITY" { - c.gotStatusCaps(status.Arguments) - } - return nil -} diff --git a/vendor/github.com/emersion/go-imap/client/cmd_selected.go b/vendor/github.com/emersion/go-imap/client/cmd_selected.go deleted file mode 100644 index 0fb71ad..0000000 --- a/vendor/github.com/emersion/go-imap/client/cmd_selected.go +++ /dev/null @@ -1,367 +0,0 @@ -package client - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/commands" - "github.com/emersion/go-imap/responses" -) - -var ( - // ErrNoMailboxSelected is returned if a command that requires a mailbox to be - // selected is called when there isn't. - ErrNoMailboxSelected = errors.New("No mailbox selected") - - // ErrExtensionUnsupported is returned if a command uses a extension that - // is not supported by the server. - ErrExtensionUnsupported = errors.New("The required extension is not supported by the server") -) - -// Check requests a checkpoint of the currently selected mailbox. A checkpoint -// refers to any implementation-dependent housekeeping associated with the -// mailbox that is not normally executed as part of each command. -func (c *Client) Check() error { - if c.State() != imap.SelectedState { - return ErrNoMailboxSelected - } - - cmd := new(commands.Check) - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - - return status.Err() -} - -// Close permanently removes all messages that have the \Deleted flag set from -// the currently selected mailbox, and returns to the authenticated state from -// the selected state. -func (c *Client) Close() error { - if c.State() != imap.SelectedState { - return ErrNoMailboxSelected - } - - cmd := new(commands.Close) - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } else if err := status.Err(); err != nil { - return err - } - - c.locker.Lock() - c.state = imap.AuthenticatedState - c.mailbox = nil - c.locker.Unlock() - return nil -} - -// Terminate closes the tcp connection -func (c *Client) Terminate() error { - return c.conn.Close() -} - -// Expunge permanently removes all messages that have the \Deleted flag set from -// the currently selected mailbox. If ch is not nil, sends sequence IDs of each -// deleted message to this channel. -func (c *Client) Expunge(ch chan uint32) error { - if ch != nil { - defer close(ch) - } - - if c.State() != imap.SelectedState { - return ErrNoMailboxSelected - } - - cmd := new(commands.Expunge) - - var h responses.Handler - if ch != nil { - h = &responses.Expunge{SeqNums: ch} - } - - status, err := c.execute(cmd, h) - if err != nil { - return err - } - return status.Err() -} - -func (c *Client) executeSearch(uid bool, criteria *imap.SearchCriteria, charset string) (ids []uint32, status *imap.StatusResp, err error) { - if c.State() != imap.SelectedState { - err = ErrNoMailboxSelected - return - } - - var cmd imap.Commander = &commands.Search{ - Charset: charset, - Criteria: criteria, - } - if uid { - cmd = &commands.Uid{Cmd: cmd} - } - - res := new(responses.Search) - - status, err = c.execute(cmd, res) - if err != nil { - return - } - - err, ids = status.Err(), res.Ids - return -} - -func (c *Client) search(uid bool, criteria *imap.SearchCriteria) (ids []uint32, err error) { - ids, status, err := c.executeSearch(uid, criteria, "UTF-8") - if status != nil && status.Code == imap.CodeBadCharset { - // Some servers don't support UTF-8 - ids, _, err = c.executeSearch(uid, criteria, "US-ASCII") - } - return -} - -// Search searches the mailbox for messages that match the given searching -// criteria. Searching criteria consist of one or more search keys. The response -// contains a list of message sequence IDs corresponding to those messages that -// match the searching criteria. When multiple keys are specified, the result is -// the intersection (AND function) of all the messages that match those keys. -// Criteria must be UTF-8 encoded. See RFC 3501 section 6.4.4 for a list of -// searching criteria. When no criteria has been set, all messages in the mailbox -// will be searched using ALL criteria. -func (c *Client) Search(criteria *imap.SearchCriteria) (seqNums []uint32, err error) { - return c.search(false, criteria) -} - -// UidSearch is identical to Search, but UIDs are returned instead of message -// sequence numbers. -func (c *Client) UidSearch(criteria *imap.SearchCriteria) (uids []uint32, err error) { - return c.search(true, criteria) -} - -func (c *Client) fetch(uid bool, seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { - defer close(ch) - - if c.State() != imap.SelectedState { - return ErrNoMailboxSelected - } - - var cmd imap.Commander = &commands.Fetch{ - SeqSet: seqset, - Items: items, - } - if uid { - cmd = &commands.Uid{Cmd: cmd} - } - - res := &responses.Fetch{Messages: ch, SeqSet: seqset, Uid: uid} - - status, err := c.execute(cmd, res) - if err != nil { - return err - } - return status.Err() -} - -// Fetch retrieves data associated with a message in the mailbox. See RFC 3501 -// section 6.4.5 for a list of items that can be requested. -func (c *Client) Fetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { - return c.fetch(false, seqset, items, ch) -} - -// UidFetch is identical to Fetch, but seqset is interpreted as containing -// unique identifiers instead of message sequence numbers. -func (c *Client) UidFetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { - return c.fetch(true, seqset, items, ch) -} - -func (c *Client) store(uid bool, seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { - if ch != nil { - defer close(ch) - } - - if c.State() != imap.SelectedState { - return ErrNoMailboxSelected - } - - // TODO: this could break extensions (this only works when item is FLAGS) - if fields, ok := value.([]interface{}); ok { - for i, field := range fields { - if s, ok := field.(string); ok { - fields[i] = imap.RawString(s) - } - } - } - - // If ch is nil, the updated values are data which will be lost, so don't - // retrieve it. - if ch == nil { - op, _, err := imap.ParseFlagsOp(item) - if err == nil { - item = imap.FormatFlagsOp(op, true) - } - } - - var cmd imap.Commander = &commands.Store{ - SeqSet: seqset, - Item: item, - Value: value, - } - if uid { - cmd = &commands.Uid{Cmd: cmd} - } - - var h responses.Handler - if ch != nil { - h = &responses.Fetch{Messages: ch, SeqSet: seqset, Uid: uid} - } - - status, err := c.execute(cmd, h) - if err != nil { - return err - } - return status.Err() -} - -// Store alters data associated with a message in the mailbox. If ch is not nil, -// the updated value of the data will be sent to this channel. See RFC 3501 -// section 6.4.6 for a list of items that can be updated. -func (c *Client) Store(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { - return c.store(false, seqset, item, value, ch) -} - -// UidStore is identical to Store, but seqset is interpreted as containing -// unique identifiers instead of message sequence numbers. -func (c *Client) UidStore(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { - return c.store(true, seqset, item, value, ch) -} - -func (c *Client) copy(uid bool, seqset *imap.SeqSet, dest string) error { - if c.State() != imap.SelectedState { - return ErrNoMailboxSelected - } - - var cmd imap.Commander = &commands.Copy{ - SeqSet: seqset, - Mailbox: dest, - } - if uid { - cmd = &commands.Uid{Cmd: cmd} - } - - status, err := c.execute(cmd, nil) - if err != nil { - return err - } - return status.Err() -} - -// Copy copies the specified message(s) to the end of the specified destination -// mailbox. -func (c *Client) Copy(seqset *imap.SeqSet, dest string) error { - return c.copy(false, seqset, dest) -} - -// UidCopy is identical to Copy, but seqset is interpreted as containing unique -// identifiers instead of message sequence numbers. -func (c *Client) UidCopy(seqset *imap.SeqSet, dest string) error { - return c.copy(true, seqset, dest) -} - -func (c *Client) move(uid bool, seqset *imap.SeqSet, dest string) error { - if c.State() != imap.SelectedState { - return ErrNoMailboxSelected - } - - if ok, err := c.Support("MOVE"); err != nil { - return err - } else if !ok { - return c.moveFallback(uid, seqset, dest) - } - - var cmd imap.Commander = &commands.Move{ - SeqSet: seqset, - Mailbox: dest, - } - if uid { - cmd = &commands.Uid{Cmd: cmd} - } - - if status, err := c.Execute(cmd, nil); err != nil { - return err - } else { - return status.Err() - } -} - -// moveFallback uses COPY, STORE and EXPUNGE for servers which don't support -// MOVE. -func (c *Client) moveFallback(uid bool, seqset *imap.SeqSet, dest string) error { - item := imap.FormatFlagsOp(imap.AddFlags, true) - flags := []interface{}{imap.DeletedFlag} - if uid { - if err := c.UidCopy(seqset, dest); err != nil { - return err - } - - if err := c.UidStore(seqset, item, flags, nil); err != nil { - return err - } - } else { - if err := c.Copy(seqset, dest); err != nil { - return err - } - - if err := c.Store(seqset, item, flags, nil); err != nil { - return err - } - } - - return c.Expunge(nil) -} - -// Move moves the specified message(s) to the end of the specified destination -// mailbox. -// -// If the server doesn't support the MOVE extension defined in RFC 6851, -// go-imap will fallback to copy, store and expunge. -func (c *Client) Move(seqset *imap.SeqSet, dest string) error { - return c.move(false, seqset, dest) -} - -// UidMove is identical to Move, but seqset is interpreted as containing unique -// identifiers instead of message sequence numbers. -func (c *Client) UidMove(seqset *imap.SeqSet, dest string) error { - return c.move(true, seqset, dest) -} - -// Unselect frees server's resources associated with the selected mailbox and -// returns the server to the authenticated state. This command performs the same -// actions as Close, except that no messages are permanently removed from the -// currently selected mailbox. -// -// If client does not support the UNSELECT extension, ErrExtensionUnsupported -// is returned. -func (c *Client) Unselect() error { - if ok, err := c.Support("UNSELECT"); !ok || err != nil { - return ErrExtensionUnsupported - } - - if c.State() != imap.SelectedState { - return ErrNoMailboxSelected - } - - cmd := &commands.Unselect{} - if status, err := c.Execute(cmd, nil); err != nil { - return err - } else if err := status.Err(); err != nil { - return err - } - - c.SetState(imap.AuthenticatedState, nil) - return nil -} diff --git a/vendor/github.com/emersion/go-imap/client/tag.go b/vendor/github.com/emersion/go-imap/client/tag.go deleted file mode 100644 index 01526ab..0000000 --- a/vendor/github.com/emersion/go-imap/client/tag.go +++ /dev/null @@ -1,24 +0,0 @@ -package client - -import ( - "crypto/rand" - "encoding/base64" -) - -func randomString(n int) (string, error) { - b := make([]byte, n) - _, err := rand.Read(b) - if err != nil { - return "", err - } - - return base64.RawURLEncoding.EncodeToString(b), nil -} - -func generateTag() string { - tag, err := randomString(4) - if err != nil { - panic(err) - } - return tag -} diff --git a/vendor/github.com/emersion/go-imap/command.go b/vendor/github.com/emersion/go-imap/command.go deleted file mode 100644 index dac2696..0000000 --- a/vendor/github.com/emersion/go-imap/command.go +++ /dev/null @@ -1,57 +0,0 @@ -package imap - -import ( - "errors" - "strings" -) - -// A value that can be converted to a command. -type Commander interface { - Command() *Command -} - -// A command. -type Command struct { - // The command tag. It acts as a unique identifier for this command. If empty, - // the command is untagged. - Tag string - // The command name. - Name string - // The command arguments. - Arguments []interface{} -} - -// Implements the Commander interface. -func (cmd *Command) Command() *Command { - return cmd -} - -func (cmd *Command) WriteTo(w *Writer) error { - tag := cmd.Tag - if tag == "" { - tag = "*" - } - - fields := []interface{}{RawString(tag), RawString(cmd.Name)} - fields = append(fields, cmd.Arguments...) - return w.writeLine(fields...) -} - -// Parse a command from fields. -func (cmd *Command) Parse(fields []interface{}) error { - if len(fields) < 2 { - return errors.New("imap: cannot parse command: no enough fields") - } - - var ok bool - if cmd.Tag, ok = fields[0].(string); !ok { - return errors.New("imap: cannot parse command: invalid tag") - } - if cmd.Name, ok = fields[1].(string); !ok { - return errors.New("imap: cannot parse command: invalid name") - } - cmd.Name = strings.ToUpper(cmd.Name) // Command names are case-insensitive - - cmd.Arguments = fields[2:] - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/append.go b/vendor/github.com/emersion/go-imap/commands/append.go deleted file mode 100644 index d70b584..0000000 --- a/vendor/github.com/emersion/go-imap/commands/append.go +++ /dev/null @@ -1,93 +0,0 @@ -package commands - -import ( - "errors" - "time" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// Append is an APPEND command, as defined in RFC 3501 section 6.3.11. -type Append struct { - Mailbox string - Flags []string - Date time.Time - Message imap.Literal -} - -func (cmd *Append) Command() *imap.Command { - var args []interface{} - - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - args = append(args, imap.FormatMailboxName(mailbox)) - - if cmd.Flags != nil { - flags := make([]interface{}, len(cmd.Flags)) - for i, flag := range cmd.Flags { - flags[i] = imap.RawString(flag) - } - args = append(args, flags) - } - - if !cmd.Date.IsZero() { - args = append(args, cmd.Date) - } - - args = append(args, cmd.Message) - - return &imap.Command{ - Name: "APPEND", - Arguments: args, - } -} - -func (cmd *Append) Parse(fields []interface{}) (err error) { - if len(fields) < 2 { - return errors.New("No enough arguments") - } - - // Parse mailbox name - if mailbox, err := imap.ParseString(fields[0]); err != nil { - return err - } else if mailbox, err = utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } else { - cmd.Mailbox = imap.CanonicalMailboxName(mailbox) - } - - // Parse message literal - litIndex := len(fields) - 1 - var ok bool - if cmd.Message, ok = fields[litIndex].(imap.Literal); !ok { - return errors.New("Message must be a literal") - } - - // Remaining fields a optional - fields = fields[1:litIndex] - if len(fields) > 0 { - // Parse flags list - if flags, ok := fields[0].([]interface{}); ok { - if cmd.Flags, err = imap.ParseStringList(flags); err != nil { - return err - } - - for i, flag := range cmd.Flags { - cmd.Flags[i] = imap.CanonicalFlag(flag) - } - - fields = fields[1:] - } - - // Parse date - if len(fields) > 0 { - if date, ok := fields[0].(string); !ok { - return errors.New("Date must be a string") - } else if cmd.Date, err = time.Parse(imap.DateTimeLayout, date); err != nil { - return err - } - } - } - - return -} diff --git a/vendor/github.com/emersion/go-imap/commands/authenticate.go b/vendor/github.com/emersion/go-imap/commands/authenticate.go deleted file mode 100644 index b66f21f..0000000 --- a/vendor/github.com/emersion/go-imap/commands/authenticate.go +++ /dev/null @@ -1,124 +0,0 @@ -package commands - -import ( - "bufio" - "encoding/base64" - "errors" - "io" - "strings" - - "github.com/emersion/go-imap" - "github.com/emersion/go-sasl" -) - -// AuthenticateConn is a connection that supports IMAP authentication. -type AuthenticateConn interface { - io.Reader - - // WriteResp writes an IMAP response to this connection. - WriteResp(res imap.WriterTo) error -} - -// Authenticate is an AUTHENTICATE command, as defined in RFC 3501 section -// 6.2.2. -type Authenticate struct { - Mechanism string - InitialResponse []byte -} - -func (cmd *Authenticate) Command() *imap.Command { - args := []interface{}{imap.RawString(cmd.Mechanism)} - if cmd.InitialResponse != nil { - var encodedResponse string - if len(cmd.InitialResponse) == 0 { - // Empty initial response should be encoded as "=", not empty - // string. - encodedResponse = "=" - } else { - encodedResponse = base64.StdEncoding.EncodeToString(cmd.InitialResponse) - } - - args = append(args, imap.RawString(encodedResponse)) - } - return &imap.Command{ - Name: "AUTHENTICATE", - Arguments: args, - } -} - -func (cmd *Authenticate) Parse(fields []interface{}) error { - if len(fields) < 1 { - return errors.New("Not enough arguments") - } - - var ok bool - if cmd.Mechanism, ok = fields[0].(string); !ok { - return errors.New("Mechanism must be a string") - } - cmd.Mechanism = strings.ToUpper(cmd.Mechanism) - - if len(fields) != 2 { - return nil - } - - encodedResponse, ok := fields[1].(string) - if !ok { - return errors.New("Initial response must be a string") - } - if encodedResponse == "=" { - cmd.InitialResponse = []byte{} - return nil - } - - var err error - cmd.InitialResponse, err = base64.StdEncoding.DecodeString(encodedResponse) - if err != nil { - return err - } - - return nil -} - -func (cmd *Authenticate) Handle(mechanisms map[string]sasl.Server, conn AuthenticateConn) error { - sasl, ok := mechanisms[cmd.Mechanism] - if !ok { - return errors.New("Unsupported mechanism") - } - - scanner := bufio.NewScanner(conn) - - response := cmd.InitialResponse - for { - challenge, done, err := sasl.Next(response) - if err != nil || done { - return err - } - - encoded := base64.StdEncoding.EncodeToString(challenge) - cont := &imap.ContinuationReq{Info: encoded} - if err := conn.WriteResp(cont); err != nil { - return err - } - - if !scanner.Scan() { - if err := scanner.Err(); err != nil { - return err - } - return errors.New("unexpected EOF") - } - - encoded = scanner.Text() - if encoded != "" { - if encoded == "*" { - return &imap.ErrStatusResp{Resp: &imap.StatusResp{ - Type: imap.StatusRespBad, - Info: "negotiation cancelled", - }} - } - response, err = base64.StdEncoding.DecodeString(encoded) - if err != nil { - return err - } - } - } -} diff --git a/vendor/github.com/emersion/go-imap/commands/capability.go b/vendor/github.com/emersion/go-imap/commands/capability.go deleted file mode 100644 index 3359c0a..0000000 --- a/vendor/github.com/emersion/go-imap/commands/capability.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// Capability is a CAPABILITY command, as defined in RFC 3501 section 6.1.1. -type Capability struct{} - -func (c *Capability) Command() *imap.Command { - return &imap.Command{ - Name: "CAPABILITY", - } -} - -func (c *Capability) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/check.go b/vendor/github.com/emersion/go-imap/commands/check.go deleted file mode 100644 index b90df7c..0000000 --- a/vendor/github.com/emersion/go-imap/commands/check.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// Check is a CHECK command, as defined in RFC 3501 section 6.4.1. -type Check struct{} - -func (cmd *Check) Command() *imap.Command { - return &imap.Command{ - Name: "CHECK", - } -} - -func (cmd *Check) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/close.go b/vendor/github.com/emersion/go-imap/commands/close.go deleted file mode 100644 index cc60658..0000000 --- a/vendor/github.com/emersion/go-imap/commands/close.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// Close is a CLOSE command, as defined in RFC 3501 section 6.4.2. -type Close struct{} - -func (cmd *Close) Command() *imap.Command { - return &imap.Command{ - Name: "CLOSE", - } -} - -func (cmd *Close) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/commands.go b/vendor/github.com/emersion/go-imap/commands/commands.go deleted file mode 100644 index a62b248..0000000 --- a/vendor/github.com/emersion/go-imap/commands/commands.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package commands implements IMAP commands defined in RFC 3501. -package commands diff --git a/vendor/github.com/emersion/go-imap/commands/copy.go b/vendor/github.com/emersion/go-imap/commands/copy.go deleted file mode 100644 index 5258f35..0000000 --- a/vendor/github.com/emersion/go-imap/commands/copy.go +++ /dev/null @@ -1,47 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// Copy is a COPY command, as defined in RFC 3501 section 6.4.7. -type Copy struct { - SeqSet *imap.SeqSet - Mailbox string -} - -func (cmd *Copy) Command() *imap.Command { - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - - return &imap.Command{ - Name: "COPY", - Arguments: []interface{}{cmd.SeqSet, imap.FormatMailboxName(mailbox)}, - } -} - -func (cmd *Copy) Parse(fields []interface{}) error { - if len(fields) < 2 { - return errors.New("No enough arguments") - } - - if seqSet, ok := fields[0].(string); !ok { - return errors.New("Invalid sequence set") - } else if seqSet, err := imap.ParseSeqSet(seqSet); err != nil { - return err - } else { - cmd.SeqSet = seqSet - } - - if mailbox, err := imap.ParseString(fields[1]); err != nil { - return err - } else if mailbox, err := utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } else { - cmd.Mailbox = imap.CanonicalMailboxName(mailbox) - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/create.go b/vendor/github.com/emersion/go-imap/commands/create.go deleted file mode 100644 index a1e6fe2..0000000 --- a/vendor/github.com/emersion/go-imap/commands/create.go +++ /dev/null @@ -1,38 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// Create is a CREATE command, as defined in RFC 3501 section 6.3.3. -type Create struct { - Mailbox string -} - -func (cmd *Create) Command() *imap.Command { - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - - return &imap.Command{ - Name: "CREATE", - Arguments: []interface{}{mailbox}, - } -} - -func (cmd *Create) Parse(fields []interface{}) error { - if len(fields) < 1 { - return errors.New("No enough arguments") - } - - if mailbox, err := imap.ParseString(fields[0]); err != nil { - return err - } else if mailbox, err := utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } else { - cmd.Mailbox = imap.CanonicalMailboxName(mailbox) - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/delete.go b/vendor/github.com/emersion/go-imap/commands/delete.go deleted file mode 100644 index 60f4da8..0000000 --- a/vendor/github.com/emersion/go-imap/commands/delete.go +++ /dev/null @@ -1,38 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// Delete is a DELETE command, as defined in RFC 3501 section 6.3.3. -type Delete struct { - Mailbox string -} - -func (cmd *Delete) Command() *imap.Command { - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - - return &imap.Command{ - Name: "DELETE", - Arguments: []interface{}{imap.FormatMailboxName(mailbox)}, - } -} - -func (cmd *Delete) Parse(fields []interface{}) error { - if len(fields) < 1 { - return errors.New("No enough arguments") - } - - if mailbox, err := imap.ParseString(fields[0]); err != nil { - return err - } else if mailbox, err := utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } else { - cmd.Mailbox = imap.CanonicalMailboxName(mailbox) - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/enable.go b/vendor/github.com/emersion/go-imap/commands/enable.go deleted file mode 100644 index 980195e..0000000 --- a/vendor/github.com/emersion/go-imap/commands/enable.go +++ /dev/null @@ -1,23 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// An ENABLE command, defined in RFC 5161 section 3.1. -type Enable struct { - Caps []string -} - -func (cmd *Enable) Command() *imap.Command { - return &imap.Command{ - Name: "ENABLE", - Arguments: imap.FormatStringList(cmd.Caps), - } -} - -func (cmd *Enable) Parse(fields []interface{}) error { - var err error - cmd.Caps, err = imap.ParseStringList(fields) - return err -} diff --git a/vendor/github.com/emersion/go-imap/commands/expunge.go b/vendor/github.com/emersion/go-imap/commands/expunge.go deleted file mode 100644 index af550a4..0000000 --- a/vendor/github.com/emersion/go-imap/commands/expunge.go +++ /dev/null @@ -1,16 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// Expunge is an EXPUNGE command, as defined in RFC 3501 section 6.4.3. -type Expunge struct{} - -func (cmd *Expunge) Command() *imap.Command { - return &imap.Command{Name: "EXPUNGE"} -} - -func (cmd *Expunge) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/fetch.go b/vendor/github.com/emersion/go-imap/commands/fetch.go deleted file mode 100644 index cf45f75..0000000 --- a/vendor/github.com/emersion/go-imap/commands/fetch.go +++ /dev/null @@ -1,55 +0,0 @@ -package commands - -import ( - "errors" - "strings" - - "github.com/emersion/go-imap" -) - -// Fetch is a FETCH command, as defined in RFC 3501 section 6.4.5. -type Fetch struct { - SeqSet *imap.SeqSet - Items []imap.FetchItem -} - -func (cmd *Fetch) Command() *imap.Command { - items := make([]interface{}, len(cmd.Items)) - for i, item := range cmd.Items { - items[i] = imap.RawString(item) - } - - return &imap.Command{ - Name: "FETCH", - Arguments: []interface{}{cmd.SeqSet, items}, - } -} - -func (cmd *Fetch) Parse(fields []interface{}) error { - if len(fields) < 2 { - return errors.New("No enough arguments") - } - - var err error - if seqset, ok := fields[0].(string); !ok { - return errors.New("Sequence set must be an atom") - } else if cmd.SeqSet, err = imap.ParseSeqSet(seqset); err != nil { - return err - } - - switch items := fields[1].(type) { - case string: // A macro or a single item - cmd.Items = imap.FetchItem(strings.ToUpper(items)).Expand() - case []interface{}: // A list of items - cmd.Items = make([]imap.FetchItem, 0, len(items)) - for _, v := range items { - itemStr, _ := v.(string) - item := imap.FetchItem(strings.ToUpper(itemStr)) - cmd.Items = append(cmd.Items, item.Expand()...) - } - default: - return errors.New("Items must be either a string or a list") - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/idle.go b/vendor/github.com/emersion/go-imap/commands/idle.go deleted file mode 100644 index 4d9669f..0000000 --- a/vendor/github.com/emersion/go-imap/commands/idle.go +++ /dev/null @@ -1,17 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// An IDLE command. -// Se RFC 2177 section 3. -type Idle struct{} - -func (cmd *Idle) Command() *imap.Command { - return &imap.Command{Name: "IDLE"} -} - -func (cmd *Idle) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/list.go b/vendor/github.com/emersion/go-imap/commands/list.go deleted file mode 100644 index 52686e9..0000000 --- a/vendor/github.com/emersion/go-imap/commands/list.go +++ /dev/null @@ -1,60 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// List is a LIST command, as defined in RFC 3501 section 6.3.8. If Subscribed -// is set to true, LSUB will be used instead. -type List struct { - Reference string - Mailbox string - - Subscribed bool -} - -func (cmd *List) Command() *imap.Command { - name := "LIST" - if cmd.Subscribed { - name = "LSUB" - } - - enc := utf7.Encoding.NewEncoder() - ref, _ := enc.String(cmd.Reference) - mailbox, _ := enc.String(cmd.Mailbox) - - return &imap.Command{ - Name: name, - Arguments: []interface{}{ref, mailbox}, - } -} - -func (cmd *List) Parse(fields []interface{}) error { - if len(fields) < 2 { - return errors.New("No enough arguments") - } - - dec := utf7.Encoding.NewDecoder() - - if mailbox, err := imap.ParseString(fields[0]); err != nil { - return err - } else if mailbox, err := dec.String(mailbox); err != nil { - return err - } else { - // TODO: canonical mailbox path - cmd.Reference = imap.CanonicalMailboxName(mailbox) - } - - if mailbox, err := imap.ParseString(fields[1]); err != nil { - return err - } else if mailbox, err := dec.String(mailbox); err != nil { - return err - } else { - cmd.Mailbox = imap.CanonicalMailboxName(mailbox) - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/login.go b/vendor/github.com/emersion/go-imap/commands/login.go deleted file mode 100644 index d0af0b5..0000000 --- a/vendor/github.com/emersion/go-imap/commands/login.go +++ /dev/null @@ -1,36 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" -) - -// Login is a LOGIN command, as defined in RFC 3501 section 6.2.2. -type Login struct { - Username string - Password string -} - -func (cmd *Login) Command() *imap.Command { - return &imap.Command{ - Name: "LOGIN", - Arguments: []interface{}{cmd.Username, cmd.Password}, - } -} - -func (cmd *Login) Parse(fields []interface{}) error { - if len(fields) < 2 { - return errors.New("Not enough arguments") - } - - var err error - if cmd.Username, err = imap.ParseString(fields[0]); err != nil { - return err - } - if cmd.Password, err = imap.ParseString(fields[1]); err != nil { - return err - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/logout.go b/vendor/github.com/emersion/go-imap/commands/logout.go deleted file mode 100644 index e826719..0000000 --- a/vendor/github.com/emersion/go-imap/commands/logout.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// Logout is a LOGOUT command, as defined in RFC 3501 section 6.1.3. -type Logout struct{} - -func (c *Logout) Command() *imap.Command { - return &imap.Command{ - Name: "LOGOUT", - } -} - -func (c *Logout) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/move.go b/vendor/github.com/emersion/go-imap/commands/move.go deleted file mode 100644 index 613a870..0000000 --- a/vendor/github.com/emersion/go-imap/commands/move.go +++ /dev/null @@ -1,48 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// A MOVE command. -// See RFC 6851 section 3.1. -type Move struct { - SeqSet *imap.SeqSet - Mailbox string -} - -func (cmd *Move) Command() *imap.Command { - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - - return &imap.Command{ - Name: "MOVE", - Arguments: []interface{}{cmd.SeqSet, mailbox}, - } -} - -func (cmd *Move) Parse(fields []interface{}) (err error) { - if len(fields) < 2 { - return errors.New("No enough arguments") - } - - seqset, ok := fields[0].(string) - if !ok { - return errors.New("Invalid sequence set") - } - if cmd.SeqSet, err = imap.ParseSeqSet(seqset); err != nil { - return err - } - - mailbox, ok := fields[1].(string) - if !ok { - return errors.New("Mailbox name must be a string") - } - if cmd.Mailbox, err = utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } - - return -} diff --git a/vendor/github.com/emersion/go-imap/commands/noop.go b/vendor/github.com/emersion/go-imap/commands/noop.go deleted file mode 100644 index da6a1c2..0000000 --- a/vendor/github.com/emersion/go-imap/commands/noop.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// Noop is a NOOP command, as defined in RFC 3501 section 6.1.2. -type Noop struct{} - -func (c *Noop) Command() *imap.Command { - return &imap.Command{ - Name: "NOOP", - } -} - -func (c *Noop) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/rename.go b/vendor/github.com/emersion/go-imap/commands/rename.go deleted file mode 100644 index 37a5fa7..0000000 --- a/vendor/github.com/emersion/go-imap/commands/rename.go +++ /dev/null @@ -1,51 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// Rename is a RENAME command, as defined in RFC 3501 section 6.3.5. -type Rename struct { - Existing string - New string -} - -func (cmd *Rename) Command() *imap.Command { - enc := utf7.Encoding.NewEncoder() - existingName, _ := enc.String(cmd.Existing) - newName, _ := enc.String(cmd.New) - - return &imap.Command{ - Name: "RENAME", - Arguments: []interface{}{imap.FormatMailboxName(existingName), imap.FormatMailboxName(newName)}, - } -} - -func (cmd *Rename) Parse(fields []interface{}) error { - if len(fields) < 2 { - return errors.New("No enough arguments") - } - - dec := utf7.Encoding.NewDecoder() - - if existingName, err := imap.ParseString(fields[0]); err != nil { - return err - } else if existingName, err := dec.String(existingName); err != nil { - return err - } else { - cmd.Existing = imap.CanonicalMailboxName(existingName) - } - - if newName, err := imap.ParseString(fields[1]); err != nil { - return err - } else if newName, err := dec.String(newName); err != nil { - return err - } else { - cmd.New = imap.CanonicalMailboxName(newName) - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/search.go b/vendor/github.com/emersion/go-imap/commands/search.go deleted file mode 100644 index 72f026c..0000000 --- a/vendor/github.com/emersion/go-imap/commands/search.go +++ /dev/null @@ -1,57 +0,0 @@ -package commands - -import ( - "errors" - "io" - "strings" - - "github.com/emersion/go-imap" -) - -// Search is a SEARCH command, as defined in RFC 3501 section 6.4.4. -type Search struct { - Charset string - Criteria *imap.SearchCriteria -} - -func (cmd *Search) Command() *imap.Command { - var args []interface{} - if cmd.Charset != "" { - args = append(args, imap.RawString("CHARSET"), imap.RawString(cmd.Charset)) - } - args = append(args, cmd.Criteria.Format()...) - - return &imap.Command{ - Name: "SEARCH", - Arguments: args, - } -} - -func (cmd *Search) Parse(fields []interface{}) error { - if len(fields) == 0 { - return errors.New("Missing search criteria") - } - - // Parse charset - if f, ok := fields[0].(string); ok && strings.EqualFold(f, "CHARSET") { - if len(fields) < 2 { - return errors.New("Missing CHARSET value") - } - if cmd.Charset, ok = fields[1].(string); !ok { - return errors.New("Charset must be a string") - } - fields = fields[2:] - } - - var charsetReader func(io.Reader) io.Reader - charset := strings.ToLower(cmd.Charset) - if charset != "utf-8" && charset != "us-ascii" && charset != "" { - charsetReader = func(r io.Reader) io.Reader { - r, _ = imap.CharsetReader(charset, r) - return r - } - } - - cmd.Criteria = new(imap.SearchCriteria) - return cmd.Criteria.ParseWithCharset(fields, charsetReader) -} diff --git a/vendor/github.com/emersion/go-imap/commands/select.go b/vendor/github.com/emersion/go-imap/commands/select.go deleted file mode 100644 index e881eff..0000000 --- a/vendor/github.com/emersion/go-imap/commands/select.go +++ /dev/null @@ -1,45 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// Select is a SELECT command, as defined in RFC 3501 section 6.3.1. If ReadOnly -// is set to true, the EXAMINE command will be used instead. -type Select struct { - Mailbox string - ReadOnly bool -} - -func (cmd *Select) Command() *imap.Command { - name := "SELECT" - if cmd.ReadOnly { - name = "EXAMINE" - } - - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - - return &imap.Command{ - Name: name, - Arguments: []interface{}{imap.FormatMailboxName(mailbox)}, - } -} - -func (cmd *Select) Parse(fields []interface{}) error { - if len(fields) < 1 { - return errors.New("No enough arguments") - } - - if mailbox, err := imap.ParseString(fields[0]); err != nil { - return err - } else if mailbox, err := utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } else { - cmd.Mailbox = imap.CanonicalMailboxName(mailbox) - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/starttls.go b/vendor/github.com/emersion/go-imap/commands/starttls.go deleted file mode 100644 index d900e5e..0000000 --- a/vendor/github.com/emersion/go-imap/commands/starttls.go +++ /dev/null @@ -1,18 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// StartTLS is a STARTTLS command, as defined in RFC 3501 section 6.2.1. -type StartTLS struct{} - -func (cmd *StartTLS) Command() *imap.Command { - return &imap.Command{ - Name: "STARTTLS", - } -} - -func (cmd *StartTLS) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/status.go b/vendor/github.com/emersion/go-imap/commands/status.go deleted file mode 100644 index 672dce5..0000000 --- a/vendor/github.com/emersion/go-imap/commands/status.go +++ /dev/null @@ -1,58 +0,0 @@ -package commands - -import ( - "errors" - "strings" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// Status is a STATUS command, as defined in RFC 3501 section 6.3.10. -type Status struct { - Mailbox string - Items []imap.StatusItem -} - -func (cmd *Status) Command() *imap.Command { - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - - items := make([]interface{}, len(cmd.Items)) - for i, item := range cmd.Items { - items[i] = imap.RawString(item) - } - - return &imap.Command{ - Name: "STATUS", - Arguments: []interface{}{imap.FormatMailboxName(mailbox), items}, - } -} - -func (cmd *Status) Parse(fields []interface{}) error { - if len(fields) < 2 { - return errors.New("No enough arguments") - } - - if mailbox, err := imap.ParseString(fields[0]); err != nil { - return err - } else if mailbox, err := utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } else { - cmd.Mailbox = imap.CanonicalMailboxName(mailbox) - } - - items, ok := fields[1].([]interface{}) - if !ok { - return errors.New("STATUS command parameter is not a list") - } - cmd.Items = make([]imap.StatusItem, len(items)) - for i, f := range items { - if s, ok := f.(string); !ok { - return errors.New("Got a non-string field in a STATUS command parameter") - } else { - cmd.Items[i] = imap.StatusItem(strings.ToUpper(s)) - } - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/store.go b/vendor/github.com/emersion/go-imap/commands/store.go deleted file mode 100644 index aeee3e6..0000000 --- a/vendor/github.com/emersion/go-imap/commands/store.go +++ /dev/null @@ -1,50 +0,0 @@ -package commands - -import ( - "errors" - "strings" - - "github.com/emersion/go-imap" -) - -// Store is a STORE command, as defined in RFC 3501 section 6.4.6. -type Store struct { - SeqSet *imap.SeqSet - Item imap.StoreItem - Value interface{} -} - -func (cmd *Store) Command() *imap.Command { - return &imap.Command{ - Name: "STORE", - Arguments: []interface{}{cmd.SeqSet, imap.RawString(cmd.Item), cmd.Value}, - } -} - -func (cmd *Store) Parse(fields []interface{}) error { - if len(fields) < 3 { - return errors.New("No enough arguments") - } - - seqset, ok := fields[0].(string) - if !ok { - return errors.New("Invalid sequence set") - } - var err error - if cmd.SeqSet, err = imap.ParseSeqSet(seqset); err != nil { - return err - } - - if item, ok := fields[1].(string); !ok { - return errors.New("Item name must be a string") - } else { - cmd.Item = imap.StoreItem(strings.ToUpper(item)) - } - - if len(fields[2:]) == 1 { - cmd.Value = fields[2] - } else { - cmd.Value = fields[2:] - } - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/subscribe.go b/vendor/github.com/emersion/go-imap/commands/subscribe.go deleted file mode 100644 index 6540969..0000000 --- a/vendor/github.com/emersion/go-imap/commands/subscribe.go +++ /dev/null @@ -1,63 +0,0 @@ -package commands - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -// Subscribe is a SUBSCRIBE command, as defined in RFC 3501 section 6.3.6. -type Subscribe struct { - Mailbox string -} - -func (cmd *Subscribe) Command() *imap.Command { - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - - return &imap.Command{ - Name: "SUBSCRIBE", - Arguments: []interface{}{imap.FormatMailboxName(mailbox)}, - } -} - -func (cmd *Subscribe) Parse(fields []interface{}) error { - if len(fields) < 0 { - return errors.New("No enough arguments") - } - - if mailbox, err := imap.ParseString(fields[0]); err != nil { - return err - } else if cmd.Mailbox, err = utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } - return nil -} - -// An UNSUBSCRIBE command. -// See RFC 3501 section 6.3.7 -type Unsubscribe struct { - Mailbox string -} - -func (cmd *Unsubscribe) Command() *imap.Command { - mailbox, _ := utf7.Encoding.NewEncoder().String(cmd.Mailbox) - - return &imap.Command{ - Name: "UNSUBSCRIBE", - Arguments: []interface{}{imap.FormatMailboxName(mailbox)}, - } -} - -func (cmd *Unsubscribe) Parse(fields []interface{}) error { - if len(fields) < 0 { - return errors.New("No enogh arguments") - } - - if mailbox, err := imap.ParseString(fields[0]); err != nil { - return err - } else if cmd.Mailbox, err = utf7.Encoding.NewDecoder().String(mailbox); err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/uid.go b/vendor/github.com/emersion/go-imap/commands/uid.go deleted file mode 100644 index 979af14..0000000 --- a/vendor/github.com/emersion/go-imap/commands/uid.go +++ /dev/null @@ -1,44 +0,0 @@ -package commands - -import ( - "errors" - "strings" - - "github.com/emersion/go-imap" -) - -// Uid is a UID command, as defined in RFC 3501 section 6.4.8. It wraps another -// command (e.g. wrapping a Fetch command will result in a UID FETCH). -type Uid struct { - Cmd imap.Commander -} - -func (cmd *Uid) Command() *imap.Command { - inner := cmd.Cmd.Command() - - args := []interface{}{imap.RawString(inner.Name)} - args = append(args, inner.Arguments...) - - return &imap.Command{ - Name: "UID", - Arguments: args, - } -} - -func (cmd *Uid) Parse(fields []interface{}) error { - if len(fields) < 0 { - return errors.New("No command name specified") - } - - name, ok := fields[0].(string) - if !ok { - return errors.New("Command name must be a string") - } - - cmd.Cmd = &imap.Command{ - Name: strings.ToUpper(name), // Command names are case-insensitive - Arguments: fields[1:], - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/commands/unselect.go b/vendor/github.com/emersion/go-imap/commands/unselect.go deleted file mode 100644 index da5c63d..0000000 --- a/vendor/github.com/emersion/go-imap/commands/unselect.go +++ /dev/null @@ -1,17 +0,0 @@ -package commands - -import ( - "github.com/emersion/go-imap" -) - -// An UNSELECT command. -// See RFC 3691 section 2. -type Unselect struct{} - -func (cmd *Unselect) Command() *imap.Command { - return &imap.Command{Name: "UNSELECT"} -} - -func (cmd *Unselect) Parse(fields []interface{}) error { - return nil -} diff --git a/vendor/github.com/emersion/go-imap/conn.go b/vendor/github.com/emersion/go-imap/conn.go deleted file mode 100644 index 09ce633..0000000 --- a/vendor/github.com/emersion/go-imap/conn.go +++ /dev/null @@ -1,284 +0,0 @@ -package imap - -import ( - "bufio" - "crypto/tls" - "io" - "net" - "sync" -) - -// A connection state. -// See RFC 3501 section 3. -type ConnState int - -const ( - // In the connecting state, the server has not yet sent a greeting and no - // command can be issued. - ConnectingState = 0 - - // In the not authenticated state, the client MUST supply - // authentication credentials before most commands will be - // permitted. This state is entered when a connection starts - // unless the connection has been pre-authenticated. - NotAuthenticatedState ConnState = 1 << 0 - - // In the authenticated state, the client is authenticated and MUST - // select a mailbox to access before commands that affect messages - // will be permitted. This state is entered when a - // pre-authenticated connection starts, when acceptable - // authentication credentials have been provided, after an error in - // selecting a mailbox, or after a successful CLOSE command. - AuthenticatedState = 1 << 1 - - // In a selected state, a mailbox has been selected to access. - // This state is entered when a mailbox has been successfully - // selected. - SelectedState = AuthenticatedState + 1<<2 - - // In the logout state, the connection is being terminated. This - // state can be entered as a result of a client request (via the - // LOGOUT command) or by unilateral action on the part of either - // the client or server. - LogoutState = 1 << 3 - - // ConnectedState is either NotAuthenticatedState, AuthenticatedState or - // SelectedState. - ConnectedState = NotAuthenticatedState | AuthenticatedState | SelectedState -) - -// A function that upgrades a connection. -// -// This should only be used by libraries implementing an IMAP extension (e.g. -// COMPRESS). -type ConnUpgrader func(conn net.Conn) (net.Conn, error) - -type Waiter struct { - start sync.WaitGroup - end sync.WaitGroup - finished bool -} - -func NewWaiter() *Waiter { - w := &Waiter{finished: false} - w.start.Add(1) - w.end.Add(1) - return w -} - -func (w *Waiter) Wait() { - if !w.finished { - // Signal that we are ready for upgrade to continue. - w.start.Done() - // Wait for upgrade to finish. - w.end.Wait() - w.finished = true - } -} - -func (w *Waiter) WaitReady() { - if !w.finished { - // Wait for reader/writer goroutine to be ready for upgrade. - w.start.Wait() - } -} - -func (w *Waiter) Close() { - if !w.finished { - // Upgrade is finished, close chanel to release reader/writer - w.end.Done() - } -} - -type LockedWriter struct { - lock sync.Mutex - writer io.Writer -} - -// NewLockedWriter - goroutine safe writer. -func NewLockedWriter(w io.Writer) io.Writer { - return &LockedWriter{writer: w} -} - -func (w *LockedWriter) Write(b []byte) (int, error) { - w.lock.Lock() - defer w.lock.Unlock() - return w.writer.Write(b) -} - -type debugWriter struct { - io.Writer - - local io.Writer - remote io.Writer -} - -// NewDebugWriter creates a new io.Writer that will write local network activity -// to local and remote network activity to remote. -func NewDebugWriter(local, remote io.Writer) io.Writer { - return &debugWriter{Writer: local, local: local, remote: remote} -} - -type multiFlusher struct { - flushers []flusher -} - -func (mf *multiFlusher) Flush() error { - for _, f := range mf.flushers { - if err := f.Flush(); err != nil { - return err - } - } - return nil -} - -func newMultiFlusher(flushers ...flusher) flusher { - return &multiFlusher{flushers} -} - -// Underlying connection state information. -type ConnInfo struct { - RemoteAddr net.Addr - LocalAddr net.Addr - - // nil if connection is not using TLS. - TLS *tls.ConnectionState -} - -// An IMAP connection. -type Conn struct { - net.Conn - *Reader - *Writer - - br *bufio.Reader - bw *bufio.Writer - - waiter *Waiter - - // Print all commands and responses to this io.Writer. - debug io.Writer -} - -// NewConn creates a new IMAP connection. -func NewConn(conn net.Conn, r *Reader, w *Writer) *Conn { - c := &Conn{Conn: conn, Reader: r, Writer: w} - - c.init() - return c -} - -func (c *Conn) createWaiter() *Waiter { - // create new waiter each time. - w := NewWaiter() - c.waiter = w - return w -} - -func (c *Conn) init() { - r := io.Reader(c.Conn) - w := io.Writer(c.Conn) - - if c.debug != nil { - localDebug, remoteDebug := c.debug, c.debug - if debug, ok := c.debug.(*debugWriter); ok { - localDebug, remoteDebug = debug.local, debug.remote - } - // If local and remote are the same, then we need a LockedWriter. - if localDebug == remoteDebug { - localDebug = NewLockedWriter(localDebug) - remoteDebug = localDebug - } - - if localDebug != nil { - w = io.MultiWriter(c.Conn, localDebug) - } - if remoteDebug != nil { - r = io.TeeReader(c.Conn, remoteDebug) - } - } - - if c.br == nil { - c.br = bufio.NewReader(r) - c.Reader.reader = c.br - } else { - c.br.Reset(r) - } - - if c.bw == nil { - c.bw = bufio.NewWriter(w) - c.Writer.Writer = c.bw - } else { - c.bw.Reset(w) - } - - if f, ok := c.Conn.(flusher); ok { - c.Writer.Writer = struct { - io.Writer - flusher - }{ - c.bw, - newMultiFlusher(c.bw, f), - } - } -} - -func (c *Conn) Info() *ConnInfo { - info := &ConnInfo{ - RemoteAddr: c.RemoteAddr(), - LocalAddr: c.LocalAddr(), - } - - tlsConn, ok := c.Conn.(*tls.Conn) - if ok { - state := tlsConn.ConnectionState() - info.TLS = &state - } - - return info -} - -// Write implements io.Writer. -func (c *Conn) Write(b []byte) (n int, err error) { - return c.Writer.Write(b) -} - -// Flush writes any buffered data to the underlying connection. -func (c *Conn) Flush() error { - return c.Writer.Flush() -} - -// Upgrade a connection, e.g. wrap an unencrypted connection with an encrypted -// tunnel. -func (c *Conn) Upgrade(upgrader ConnUpgrader) error { - // Block reads and writes during the upgrading process - w := c.createWaiter() - defer w.Close() - - upgraded, err := upgrader(c.Conn) - if err != nil { - return err - } - - c.Conn = upgraded - c.init() - return nil -} - -// Called by reader/writer goroutines to wait for Upgrade to finish -func (c *Conn) Wait() { - c.waiter.Wait() -} - -// Called by Upgrader to wait for reader/writer goroutines to be ready for -// upgrade. -func (c *Conn) WaitReady() { - c.waiter.WaitReady() -} - -// SetDebug defines an io.Writer to which all network activity will be logged. -// If nil is provided, network activity will not be logged. -func (c *Conn) SetDebug(w io.Writer) { - c.debug = w - c.init() -} diff --git a/vendor/github.com/emersion/go-imap/date.go b/vendor/github.com/emersion/go-imap/date.go deleted file mode 100644 index bf99647..0000000 --- a/vendor/github.com/emersion/go-imap/date.go +++ /dev/null @@ -1,71 +0,0 @@ -package imap - -import ( - "fmt" - "regexp" - "time" -) - -// Date and time layouts. -// Dovecot adds a leading zero to dates: -// https://github.com/dovecot/core/blob/4fbd5c5e113078e72f29465ccc96d44955ceadc2/src/lib-imap/imap-date.c#L166 -// Cyrus adds a leading space to dates: -// https://github.com/cyrusimap/cyrus-imapd/blob/1cb805a3bffbdf829df0964f3b802cdc917e76db/lib/times.c#L543 -// GMail doesn't support leading spaces in dates used in SEARCH commands. -const ( - // Defined in RFC 3501 as date-text on page 83. - DateLayout = "_2-Jan-2006" - // Defined in RFC 3501 as date-time on page 83. - DateTimeLayout = "_2-Jan-2006 15:04:05 -0700" - // Defined in RFC 5322 section 3.3, mentioned as env-date in RFC 3501 page 84. - envelopeDateTimeLayout = "Mon, 02 Jan 2006 15:04:05 -0700" - // Use as an example in RFC 3501 page 54. - searchDateLayout = "2-Jan-2006" -) - -// time.Time with a specific layout. -type ( - Date time.Time - DateTime time.Time - envelopeDateTime time.Time - searchDate time.Time -) - -// Permutations of the layouts defined in RFC 5322, section 3.3. -var envelopeDateTimeLayouts = [...]string{ - envelopeDateTimeLayout, // popular, try it first - "_2 Jan 2006 15:04:05 -0700", - "_2 Jan 2006 15:04:05 MST", - "_2 Jan 2006 15:04 -0700", - "_2 Jan 2006 15:04 MST", - "_2 Jan 06 15:04:05 -0700", - "_2 Jan 06 15:04:05 MST", - "_2 Jan 06 15:04 -0700", - "_2 Jan 06 15:04 MST", - "Mon, _2 Jan 2006 15:04:05 -0700", - "Mon, _2 Jan 2006 15:04:05 MST", - "Mon, _2 Jan 2006 15:04 -0700", - "Mon, _2 Jan 2006 15:04 MST", - "Mon, _2 Jan 06 15:04:05 -0700", - "Mon, _2 Jan 06 15:04:05 MST", - "Mon, _2 Jan 06 15:04 -0700", - "Mon, _2 Jan 06 15:04 MST", -} - -// TODO: this is a blunt way to strip any trailing CFWS (comment). A sharper -// one would strip multiple CFWS, and only if really valid according to -// RFC5322. -var commentRE = regexp.MustCompile(`[ \t]+\(.*\)$`) - -// Try parsing the date based on the layouts defined in RFC 5322, section 3.3. -// Inspired by https://github.com/golang/go/blob/master/src/net/mail/message.go -func parseMessageDateTime(maybeDate string) (time.Time, error) { - maybeDate = commentRE.ReplaceAllString(maybeDate, "") - for _, layout := range envelopeDateTimeLayouts { - parsed, err := time.Parse(layout, maybeDate) - if err == nil { - return parsed, nil - } - } - return time.Time{}, fmt.Errorf("date %s could not be parsed", maybeDate) -} diff --git a/vendor/github.com/emersion/go-imap/imap.go b/vendor/github.com/emersion/go-imap/imap.go deleted file mode 100644 index 837d78d..0000000 --- a/vendor/github.com/emersion/go-imap/imap.go +++ /dev/null @@ -1,108 +0,0 @@ -// Package imap implements IMAP4rev1 (RFC 3501). -package imap - -import ( - "errors" - "io" - "strings" -) - -// A StatusItem is a mailbox status data item that can be retrieved with a -// STATUS command. See RFC 3501 section 6.3.10. -type StatusItem string - -const ( - StatusMessages StatusItem = "MESSAGES" - StatusRecent StatusItem = "RECENT" - StatusUidNext StatusItem = "UIDNEXT" - StatusUidValidity StatusItem = "UIDVALIDITY" - StatusUnseen StatusItem = "UNSEEN" - - StatusAppendLimit StatusItem = "APPENDLIMIT" -) - -// A FetchItem is a message data item that can be fetched. -type FetchItem string - -// List of items that can be fetched. -const ( - // Macros - FetchAll FetchItem = "ALL" - FetchFast FetchItem = "FAST" - FetchFull FetchItem = "FULL" - - // Items - FetchBody FetchItem = "BODY" - FetchBodyStructure FetchItem = "BODYSTRUCTURE" - FetchEnvelope FetchItem = "ENVELOPE" - FetchFlags FetchItem = "FLAGS" - FetchInternalDate FetchItem = "INTERNALDATE" - FetchRFC822 FetchItem = "RFC822" - FetchRFC822Header FetchItem = "RFC822.HEADER" - FetchRFC822Size FetchItem = "RFC822.SIZE" - FetchRFC822Text FetchItem = "RFC822.TEXT" - FetchUid FetchItem = "UID" -) - -// Expand expands the item if it's a macro. -func (item FetchItem) Expand() []FetchItem { - switch item { - case FetchAll: - return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope} - case FetchFast: - return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size} - case FetchFull: - return []FetchItem{FetchFlags, FetchInternalDate, FetchRFC822Size, FetchEnvelope, FetchBody} - default: - return []FetchItem{item} - } -} - -// FlagsOp is an operation that will be applied on message flags. -type FlagsOp string - -const ( - // SetFlags replaces existing flags by new ones. - SetFlags FlagsOp = "FLAGS" - // AddFlags adds new flags. - AddFlags = "+FLAGS" - // RemoveFlags removes existing flags. - RemoveFlags = "-FLAGS" -) - -// silentOp can be appended to a FlagsOp to prevent the operation from -// triggering unilateral message updates. -const silentOp = ".SILENT" - -// A StoreItem is a message data item that can be updated. -type StoreItem string - -// FormatFlagsOp returns the StoreItem that executes the flags operation op. -func FormatFlagsOp(op FlagsOp, silent bool) StoreItem { - s := string(op) - if silent { - s += silentOp - } - return StoreItem(s) -} - -// ParseFlagsOp parses a flags operation from StoreItem. -func ParseFlagsOp(item StoreItem) (op FlagsOp, silent bool, err error) { - itemStr := string(item) - silent = strings.HasSuffix(itemStr, silentOp) - if silent { - itemStr = strings.TrimSuffix(itemStr, silentOp) - } - op = FlagsOp(itemStr) - - if op != SetFlags && op != AddFlags && op != RemoveFlags { - err = errors.New("Unsupported STORE operation") - } - return -} - -// CharsetReader, if non-nil, defines a function to generate charset-conversion -// readers, converting from the provided charset into UTF-8. Charsets are always -// lower-case. utf-8 and us-ascii charsets are handled by default. One of the -// the CharsetReader's result values must be non-nil. -var CharsetReader func(charset string, r io.Reader) (io.Reader, error) diff --git a/vendor/github.com/emersion/go-imap/literal.go b/vendor/github.com/emersion/go-imap/literal.go deleted file mode 100644 index b5b7f55..0000000 --- a/vendor/github.com/emersion/go-imap/literal.go +++ /dev/null @@ -1,13 +0,0 @@ -package imap - -import ( - "io" -) - -// A literal, as defined in RFC 3501 section 4.3. -type Literal interface { - io.Reader - - // Len returns the number of bytes of the literal. - Len() int -} diff --git a/vendor/github.com/emersion/go-imap/logger.go b/vendor/github.com/emersion/go-imap/logger.go deleted file mode 100644 index fa96cdc..0000000 --- a/vendor/github.com/emersion/go-imap/logger.go +++ /dev/null @@ -1,8 +0,0 @@ -package imap - -// Logger is the behaviour used by server/client to -// report errors for accepting connections and unexpected behavior from handlers. -type Logger interface { - Printf(format string, v ...interface{}) - Println(v ...interface{}) -} diff --git a/vendor/github.com/emersion/go-imap/mailbox.go b/vendor/github.com/emersion/go-imap/mailbox.go deleted file mode 100644 index e575569..0000000 --- a/vendor/github.com/emersion/go-imap/mailbox.go +++ /dev/null @@ -1,314 +0,0 @@ -package imap - -import ( - "errors" - "fmt" - "strings" - "sync" - - "github.com/emersion/go-imap/utf7" -) - -// The primary mailbox, as defined in RFC 3501 section 5.1. -const InboxName = "INBOX" - -// CanonicalMailboxName returns the canonical form of a mailbox name. Mailbox names can be -// case-sensitive or case-insensitive depending on the backend implementation. -// The special INBOX mailbox is case-insensitive. -func CanonicalMailboxName(name string) string { - if strings.ToUpper(name) == InboxName { - return InboxName - } - return name -} - -// Mailbox attributes definied in RFC 3501 section 7.2.2. -const ( - // It is not possible for any child levels of hierarchy to exist under this\ - // name; no child levels exist now and none can be created in the future. - NoInferiorsAttr = "\\Noinferiors" - // It is not possible to use this name as a selectable mailbox. - NoSelectAttr = "\\Noselect" - // The mailbox has been marked "interesting" by the server; the mailbox - // probably contains messages that have been added since the last time the - // mailbox was selected. - MarkedAttr = "\\Marked" - // The mailbox does not contain any additional messages since the last time - // the mailbox was selected. - UnmarkedAttr = "\\Unmarked" -) - -// Mailbox attributes defined in RFC 6154 section 2 (SPECIAL-USE extension). -const ( - // This mailbox presents all messages in the user's message store. - AllAttr = "\\All" - // This mailbox is used to archive messages. - ArchiveAttr = "\\Archive" - // This mailbox is used to hold draft messages -- typically, messages that are - // being composed but have not yet been sent. - DraftsAttr = "\\Drafts" - // This mailbox presents all messages marked in some way as "important". - FlaggedAttr = "\\Flagged" - // This mailbox is where messages deemed to be junk mail are held. - JunkAttr = "\\Junk" - // This mailbox is used to hold copies of messages that have been sent. - SentAttr = "\\Sent" - // This mailbox is used to hold messages that have been deleted or marked for - // deletion. - TrashAttr = "\\Trash" -) - -// Mailbox attributes defined in RFC 3348 (CHILDREN extension) -const ( - // The presence of this attribute indicates that the mailbox has child - // mailboxes. - HasChildrenAttr = "\\HasChildren" - // The presence of this attribute indicates that the mailbox has no child - // mailboxes. - HasNoChildrenAttr = "\\HasNoChildren" -) - -// This mailbox attribute is a signal that the mailbox contains messages that -// are likely important to the user. This attribute is defined in RFC 8457 -// section 3. -const ImportantAttr = "\\Important" - -// Basic mailbox info. -type MailboxInfo struct { - // The mailbox attributes. - Attributes []string - // The server's path separator. - Delimiter string - // The mailbox name. - Name string -} - -// Parse mailbox info from fields. -func (info *MailboxInfo) Parse(fields []interface{}) error { - if len(fields) < 3 { - return errors.New("Mailbox info needs at least 3 fields") - } - - var err error - if info.Attributes, err = ParseStringList(fields[0]); err != nil { - return err - } - - var ok bool - if info.Delimiter, ok = fields[1].(string); !ok { - // The delimiter may be specified as NIL, which gets converted to a nil interface. - if fields[1] != nil { - return errors.New("Mailbox delimiter must be a string") - } - info.Delimiter = "" - } - - if name, err := ParseString(fields[2]); err != nil { - return err - } else if name, err := utf7.Encoding.NewDecoder().String(name); err != nil { - return err - } else { - info.Name = CanonicalMailboxName(name) - } - - return nil -} - -// Format mailbox info to fields. -func (info *MailboxInfo) Format() []interface{} { - name, _ := utf7.Encoding.NewEncoder().String(info.Name) - attrs := make([]interface{}, len(info.Attributes)) - for i, attr := range info.Attributes { - attrs[i] = RawString(attr) - } - - // If the delimiter is NIL, we need to treat it specially by inserting - // a nil field (so that it's later converted to an unquoted NIL atom). - var del interface{} - - if info.Delimiter != "" { - del = info.Delimiter - } - - // Thunderbird doesn't understand delimiters if not quoted - return []interface{}{attrs, del, FormatMailboxName(name)} -} - -// TODO: optimize this -func (info *MailboxInfo) match(name, pattern string) bool { - i := strings.IndexAny(pattern, "*%") - if i == -1 { - // No more wildcards - return name == pattern - } - - // Get parts before and after wildcard - chunk, wildcard, rest := pattern[0:i], pattern[i], pattern[i+1:] - - // Check that name begins with chunk - if len(chunk) > 0 && !strings.HasPrefix(name, chunk) { - return false - } - name = strings.TrimPrefix(name, chunk) - - // Expand wildcard - var j int - for j = 0; j < len(name); j++ { - if wildcard == '%' && string(name[j]) == info.Delimiter { - break // Stop on delimiter if wildcard is % - } - // Try to match the rest from here - if info.match(name[j:], rest) { - return true - } - } - - return info.match(name[j:], rest) -} - -// Match checks if a reference and a pattern matches this mailbox name, as -// defined in RFC 3501 section 6.3.8. -func (info *MailboxInfo) Match(reference, pattern string) bool { - name := info.Name - - if info.Delimiter != "" && strings.HasPrefix(pattern, info.Delimiter) { - reference = "" - pattern = strings.TrimPrefix(pattern, info.Delimiter) - } - if reference != "" { - if info.Delimiter != "" && !strings.HasSuffix(reference, info.Delimiter) { - reference += info.Delimiter - } - if !strings.HasPrefix(name, reference) { - return false - } - name = strings.TrimPrefix(name, reference) - } - - return info.match(name, pattern) -} - -// A mailbox status. -type MailboxStatus struct { - // The mailbox name. - Name string - // True if the mailbox is open in read-only mode. - ReadOnly bool - // The mailbox items that are currently filled in. This map's values - // should not be used directly, they must only be used by libraries - // implementing extensions of the IMAP protocol. - Items map[StatusItem]interface{} - - // The Items map may be accessed in different goroutines. Protect - // concurrent writes. - ItemsLocker sync.Mutex - - // The mailbox flags. - Flags []string - // The mailbox permanent flags. - PermanentFlags []string - // The sequence number of the first unseen message in the mailbox. - UnseenSeqNum uint32 - - // The number of messages in this mailbox. - Messages uint32 - // The number of messages not seen since the last time the mailbox was opened. - Recent uint32 - // The number of unread messages. - Unseen uint32 - // The next UID. - UidNext uint32 - // Together with a UID, it is a unique identifier for a message. - // Must be greater than or equal to 1. - UidValidity uint32 - - // Per-mailbox limit of message size. Set only if server supports the - // APPENDLIMIT extension. - AppendLimit uint32 -} - -// Create a new mailbox status that will contain the specified items. -func NewMailboxStatus(name string, items []StatusItem) *MailboxStatus { - status := &MailboxStatus{ - Name: name, - Items: make(map[StatusItem]interface{}), - } - - for _, k := range items { - status.Items[k] = nil - } - - return status -} - -func (status *MailboxStatus) Parse(fields []interface{}) error { - status.Items = make(map[StatusItem]interface{}) - - var k StatusItem - for i, f := range fields { - if i%2 == 0 { - if kstr, ok := f.(string); !ok { - return fmt.Errorf("cannot parse mailbox status: key is not a string, but a %T", f) - } else { - k = StatusItem(strings.ToUpper(kstr)) - } - } else { - status.Items[k] = nil - - var err error - switch k { - case StatusMessages: - status.Messages, err = ParseNumber(f) - case StatusRecent: - status.Recent, err = ParseNumber(f) - case StatusUnseen: - status.Unseen, err = ParseNumber(f) - case StatusUidNext: - status.UidNext, err = ParseNumber(f) - case StatusUidValidity: - status.UidValidity, err = ParseNumber(f) - case StatusAppendLimit: - status.AppendLimit, err = ParseNumber(f) - default: - status.Items[k] = f - } - - if err != nil { - return err - } - } - } - - return nil -} - -func (status *MailboxStatus) Format() []interface{} { - var fields []interface{} - for k, v := range status.Items { - switch k { - case StatusMessages: - v = status.Messages - case StatusRecent: - v = status.Recent - case StatusUnseen: - v = status.Unseen - case StatusUidNext: - v = status.UidNext - case StatusUidValidity: - v = status.UidValidity - case StatusAppendLimit: - v = status.AppendLimit - } - - fields = append(fields, RawString(k), v) - } - return fields -} - -func FormatMailboxName(name string) interface{} { - // Some e-mails servers don't handle quoted INBOX names correctly so we special-case it. - if strings.EqualFold(name, "INBOX") { - return RawString(name) - } - return name -} diff --git a/vendor/github.com/emersion/go-imap/message.go b/vendor/github.com/emersion/go-imap/message.go deleted file mode 100644 index 3751b0c..0000000 --- a/vendor/github.com/emersion/go-imap/message.go +++ /dev/null @@ -1,1187 +0,0 @@ -package imap - -import ( - "bytes" - "errors" - "fmt" - "io" - "mime" - "strconv" - "strings" - "time" -) - -// System message flags, defined in RFC 3501 section 2.3.2. -const ( - SeenFlag = "\\Seen" - AnsweredFlag = "\\Answered" - FlaggedFlag = "\\Flagged" - DeletedFlag = "\\Deleted" - DraftFlag = "\\Draft" - RecentFlag = "\\Recent" -) - -// ImportantFlag is a message flag to signal that a message is likely important -// to the user. This flag is defined in RFC 8457 section 2. -const ImportantFlag = "$Important" - -// TryCreateFlag is a special flag in MailboxStatus.PermanentFlags indicating -// that it is possible to create new keywords by attempting to store those -// flags in the mailbox. -const TryCreateFlag = "\\*" - -var flags = []string{ - SeenFlag, - AnsweredFlag, - FlaggedFlag, - DeletedFlag, - DraftFlag, - RecentFlag, -} - -// A PartSpecifier specifies which parts of the MIME entity should be returned. -type PartSpecifier string - -// Part specifiers described in RFC 3501 page 55. -const ( - // Refers to the entire part, including headers. - EntireSpecifier PartSpecifier = "" - // Refers to the header of the part. Must include the final CRLF delimiting - // the header and the body. - HeaderSpecifier = "HEADER" - // Refers to the text body of the part, omitting the header. - TextSpecifier = "TEXT" - // Refers to the MIME Internet Message Body header. Must include the final - // CRLF delimiting the header and the body. - MIMESpecifier = "MIME" -) - -// CanonicalFlag returns the canonical form of a flag. Flags are case-insensitive. -// -// If the flag is defined in RFC 3501, it returns the flag with the case of the -// RFC. Otherwise, it returns the lowercase version of the flag. -func CanonicalFlag(flag string) string { - flag = strings.ToLower(flag) - for _, f := range flags { - if strings.ToLower(f) == flag { - return f - } - } - return flag -} - -func ParseParamList(fields []interface{}) (map[string]string, error) { - params := make(map[string]string) - - var k string - for i, f := range fields { - p, err := ParseString(f) - if err != nil { - return nil, errors.New("Parameter list contains a non-string: " + err.Error()) - } - - if i%2 == 0 { - k = p - } else { - params[k] = p - k = "" - } - } - - if k != "" { - return nil, errors.New("Parameter list contains a key without a value") - } - return params, nil -} - -func FormatParamList(params map[string]string) []interface{} { - var fields []interface{} - for key, value := range params { - fields = append(fields, key, value) - } - return fields -} - -var wordDecoder = &mime.WordDecoder{ - CharsetReader: func(charset string, input io.Reader) (io.Reader, error) { - if CharsetReader != nil { - return CharsetReader(charset, input) - } - return nil, fmt.Errorf("imap: unhandled charset %q", charset) - }, -} - -func decodeHeader(s string) (string, error) { - dec, err := wordDecoder.DecodeHeader(s) - if err != nil { - return s, err - } - return dec, nil -} - -func encodeHeader(s string) string { - return mime.QEncoding.Encode("utf-8", s) -} - -func stringLowered(i interface{}) (string, bool) { - s, ok := i.(string) - return strings.ToLower(s), ok -} - -func parseHeaderParamList(fields []interface{}) (map[string]string, error) { - params, err := ParseParamList(fields) - if err != nil { - return nil, err - } - - for k, v := range params { - if lower := strings.ToLower(k); lower != k { - delete(params, k) - k = lower - } - - params[k], _ = decodeHeader(v) - } - - return params, nil -} - -func formatHeaderParamList(params map[string]string) []interface{} { - encoded := make(map[string]string) - for k, v := range params { - encoded[k] = encodeHeader(v) - } - return FormatParamList(encoded) -} - -// A message. -type Message struct { - // The message sequence number. It must be greater than or equal to 1. - SeqNum uint32 - // The mailbox items that are currently filled in. This map's values - // should not be used directly, they must only be used by libraries - // implementing extensions of the IMAP protocol. - Items map[FetchItem]interface{} - - // The message envelope. - Envelope *Envelope - // The message body structure (either BODYSTRUCTURE or BODY). - BodyStructure *BodyStructure - // The message flags. - Flags []string - // The date the message was received by the server. - InternalDate time.Time - // The message size. - Size uint32 - // The message unique identifier. It must be greater than or equal to 1. - Uid uint32 - // The message body sections. - Body map[*BodySectionName]Literal - - // The order in which items were requested. This order must be preserved - // because some bad IMAP clients (looking at you, Outlook!) refuse responses - // containing items in a different order. - itemsOrder []FetchItem -} - -// Create a new empty message that will contain the specified items. -func NewMessage(seqNum uint32, items []FetchItem) *Message { - msg := &Message{ - SeqNum: seqNum, - Items: make(map[FetchItem]interface{}), - Body: make(map[*BodySectionName]Literal), - itemsOrder: items, - } - - for _, k := range items { - msg.Items[k] = nil - } - - return msg -} - -// Parse a message from fields. -func (m *Message) Parse(fields []interface{}) error { - m.Items = make(map[FetchItem]interface{}) - m.Body = map[*BodySectionName]Literal{} - m.itemsOrder = nil - - var k FetchItem - for i, f := range fields { - if i%2 == 0 { // It's a key - switch f := f.(type) { - case string: - k = FetchItem(strings.ToUpper(f)) - case RawString: - k = FetchItem(strings.ToUpper(string(f))) - default: - return fmt.Errorf("cannot parse message: key is not a string, but a %T", f) - } - } else { // It's a value - m.Items[k] = nil - m.itemsOrder = append(m.itemsOrder, k) - - switch k { - case FetchBody, FetchBodyStructure: - bs, ok := f.([]interface{}) - if !ok { - return fmt.Errorf("cannot parse message: BODYSTRUCTURE is not a list, but a %T", f) - } - - m.BodyStructure = &BodyStructure{Extended: k == FetchBodyStructure} - if err := m.BodyStructure.Parse(bs); err != nil { - return err - } - case FetchEnvelope: - env, ok := f.([]interface{}) - if !ok { - return fmt.Errorf("cannot parse message: ENVELOPE is not a list, but a %T", f) - } - - m.Envelope = &Envelope{} - if err := m.Envelope.Parse(env); err != nil { - return err - } - case FetchFlags: - flags, ok := f.([]interface{}) - if !ok { - return fmt.Errorf("cannot parse message: FLAGS is not a list, but a %T", f) - } - - m.Flags = make([]string, len(flags)) - for i, flag := range flags { - s, _ := ParseString(flag) - m.Flags[i] = CanonicalFlag(s) - } - case FetchInternalDate: - date, _ := f.(string) - m.InternalDate, _ = time.Parse(DateTimeLayout, date) - case FetchRFC822Size: - m.Size, _ = ParseNumber(f) - case FetchUid: - m.Uid, _ = ParseNumber(f) - default: - // Likely to be a section of the body - // First check that the section name is correct - if section, err := ParseBodySectionName(k); err != nil { - // Not a section name, maybe an attribute defined in an IMAP extension - m.Items[k] = f - } else { - m.Body[section], _ = f.(Literal) - } - } - } - } - - return nil -} - -func (m *Message) formatItem(k FetchItem) []interface{} { - v := m.Items[k] - var kk interface{} = RawString(k) - - switch k { - case FetchBody, FetchBodyStructure: - // Extension data is only returned with the BODYSTRUCTURE fetch - m.BodyStructure.Extended = k == FetchBodyStructure - v = m.BodyStructure.Format() - case FetchEnvelope: - v = m.Envelope.Format() - case FetchFlags: - flags := make([]interface{}, len(m.Flags)) - for i, flag := range m.Flags { - flags[i] = RawString(flag) - } - v = flags - case FetchInternalDate: - v = m.InternalDate - case FetchRFC822Size: - v = m.Size - case FetchUid: - v = m.Uid - default: - for section, literal := range m.Body { - if section.value == k { - // This can contain spaces, so we can't pass it as a string directly - kk = section.resp() - v = literal - break - } - } - } - - return []interface{}{kk, v} -} - -func (m *Message) Format() []interface{} { - var fields []interface{} - - // First send ordered items - processed := make(map[FetchItem]bool) - for _, k := range m.itemsOrder { - if _, ok := m.Items[k]; ok { - fields = append(fields, m.formatItem(k)...) - processed[k] = true - } - } - - // Then send other remaining items - for k := range m.Items { - if !processed[k] { - fields = append(fields, m.formatItem(k)...) - } - } - - return fields -} - -// GetBody gets the body section with the specified name. Returns nil if it's not found. -func (m *Message) GetBody(section *BodySectionName) Literal { - section = section.resp() - - for s, body := range m.Body { - if section.Equal(s) { - if body == nil { - // Server can return nil, we need to treat as empty string per RFC 3501 - body = bytes.NewReader(nil) - } - return body - } - } - return nil -} - -// A body section name. -// See RFC 3501 page 55. -type BodySectionName struct { - BodyPartName - - // If set to true, do not implicitly set the \Seen flag. - Peek bool - // The substring of the section requested. The first value is the position of - // the first desired octet and the second value is the maximum number of - // octets desired. - Partial []int - - value FetchItem -} - -func (section *BodySectionName) parse(s string) error { - section.value = FetchItem(s) - - if s == "RFC822" { - s = "BODY[]" - } - if s == "RFC822.HEADER" { - s = "BODY.PEEK[HEADER]" - } - if s == "RFC822.TEXT" { - s = "BODY[TEXT]" - } - - partStart := strings.Index(s, "[") - if partStart == -1 { - return errors.New("Invalid body section name: must contain an open bracket") - } - - partEnd := strings.LastIndex(s, "]") - if partEnd == -1 { - return errors.New("Invalid body section name: must contain a close bracket") - } - - name := s[:partStart] - part := s[partStart+1 : partEnd] - partial := s[partEnd+1:] - - if name == "BODY.PEEK" { - section.Peek = true - } else if name != "BODY" { - return errors.New("Invalid body section name") - } - - b := bytes.NewBufferString(part + string(cr) + string(lf)) - r := NewReader(b) - fields, err := r.ReadFields() - if err != nil { - return err - } - - if err := section.BodyPartName.parse(fields); err != nil { - return err - } - - if len(partial) > 0 { - if !strings.HasPrefix(partial, "<") || !strings.HasSuffix(partial, ">") { - return errors.New("Invalid body section name: invalid partial") - } - partial = partial[1 : len(partial)-1] - - partialParts := strings.SplitN(partial, ".", 2) - - var from, length int - if from, err = strconv.Atoi(partialParts[0]); err != nil { - return errors.New("Invalid body section name: invalid partial: invalid from: " + err.Error()) - } - section.Partial = []int{from} - - if len(partialParts) == 2 { - if length, err = strconv.Atoi(partialParts[1]); err != nil { - return errors.New("Invalid body section name: invalid partial: invalid length: " + err.Error()) - } - section.Partial = append(section.Partial, length) - } - } - - return nil -} - -func (section *BodySectionName) FetchItem() FetchItem { - if section.value != "" { - return section.value - } - - s := "BODY" - if section.Peek { - s += ".PEEK" - } - - s += "[" + section.BodyPartName.string() + "]" - - if len(section.Partial) > 0 { - s += "<" - s += strconv.Itoa(section.Partial[0]) - - if len(section.Partial) > 1 { - s += "." - s += strconv.Itoa(section.Partial[1]) - } - - s += ">" - } - - return FetchItem(s) -} - -// Equal checks whether two sections are equal. -func (section *BodySectionName) Equal(other *BodySectionName) bool { - if section.Peek != other.Peek { - return false - } - if len(section.Partial) != len(other.Partial) { - return false - } - if len(section.Partial) > 0 && section.Partial[0] != other.Partial[0] { - return false - } - if len(section.Partial) > 1 && section.Partial[1] != other.Partial[1] { - return false - } - return section.BodyPartName.Equal(&other.BodyPartName) -} - -func (section *BodySectionName) resp() *BodySectionName { - resp := *section // Copy section - if resp.Peek { - resp.Peek = false - } - if len(resp.Partial) == 2 { - resp.Partial = []int{resp.Partial[0]} - } - if !strings.HasPrefix(string(resp.value), string(FetchRFC822)) { - resp.value = "" - } - return &resp -} - -// ExtractPartial returns a subset of the specified bytes matching the partial requested in the -// section name. -func (section *BodySectionName) ExtractPartial(b []byte) []byte { - if len(section.Partial) != 2 { - return b - } - - from := section.Partial[0] - length := section.Partial[1] - to := from + length - if from > len(b) { - return nil - } - if to > len(b) { - to = len(b) - } - return b[from:to] -} - -// ParseBodySectionName parses a body section name. -func ParseBodySectionName(s FetchItem) (*BodySectionName, error) { - section := new(BodySectionName) - err := section.parse(string(s)) - return section, err -} - -// A body part name. -type BodyPartName struct { - // The specifier of the requested part. - Specifier PartSpecifier - // The part path. Parts indexes start at 1. - Path []int - // If Specifier is HEADER, contains header fields that will/won't be returned, - // depending of the value of NotFields. - Fields []string - // If set to true, Fields is a blacklist of fields instead of a whitelist. - NotFields bool -} - -func (part *BodyPartName) parse(fields []interface{}) error { - if len(fields) == 0 { - return nil - } - - name, ok := fields[0].(string) - if !ok { - return errors.New("Invalid body section name: part name must be a string") - } - - args := fields[1:] - - path := strings.Split(strings.ToUpper(name), ".") - - end := 0 -loop: - for i, node := range path { - switch PartSpecifier(node) { - case EntireSpecifier, HeaderSpecifier, MIMESpecifier, TextSpecifier: - part.Specifier = PartSpecifier(node) - end = i + 1 - break loop - } - - index, err := strconv.Atoi(node) - if err != nil { - return errors.New("Invalid body part name: " + err.Error()) - } - if index <= 0 { - return errors.New("Invalid body part name: index <= 0") - } - - part.Path = append(part.Path, index) - } - - if part.Specifier == HeaderSpecifier && len(path) > end && path[end] == "FIELDS" && len(args) > 0 { - end++ - if len(path) > end && path[end] == "NOT" { - part.NotFields = true - } - - names, ok := args[0].([]interface{}) - if !ok { - return errors.New("Invalid body part name: HEADER.FIELDS must have a list argument") - } - - for _, namei := range names { - if name, ok := namei.(string); ok { - part.Fields = append(part.Fields, name) - } - } - } - - return nil -} - -func (part *BodyPartName) string() string { - path := make([]string, len(part.Path)) - for i, index := range part.Path { - path[i] = strconv.Itoa(index) - } - - if part.Specifier != EntireSpecifier { - path = append(path, string(part.Specifier)) - } - - if part.Specifier == HeaderSpecifier && len(part.Fields) > 0 { - path = append(path, "FIELDS") - - if part.NotFields { - path = append(path, "NOT") - } - } - - s := strings.Join(path, ".") - - if len(part.Fields) > 0 { - s += " (" + strings.Join(part.Fields, " ") + ")" - } - - return s -} - -// Equal checks whether two body part names are equal. -func (part *BodyPartName) Equal(other *BodyPartName) bool { - if part.Specifier != other.Specifier { - return false - } - if part.NotFields != other.NotFields { - return false - } - if len(part.Path) != len(other.Path) { - return false - } - for i, node := range part.Path { - if node != other.Path[i] { - return false - } - } - if len(part.Fields) != len(other.Fields) { - return false - } - for _, field := range part.Fields { - found := false - for _, f := range other.Fields { - if strings.EqualFold(field, f) { - found = true - break - } - } - if !found { - return false - } - } - return true -} - -// An address. -type Address struct { - // The personal name. - PersonalName string - // The SMTP at-domain-list (source route). - AtDomainList string - // The mailbox name. - MailboxName string - // The host name. - HostName string -} - -// Address returns the mailbox address (e.g. "foo@example.org"). -func (addr *Address) Address() string { - return addr.MailboxName + "@" + addr.HostName -} - -// Parse an address from fields. -func (addr *Address) Parse(fields []interface{}) error { - if len(fields) < 4 { - return errors.New("Address doesn't contain 4 fields") - } - - if s, err := ParseString(fields[0]); err == nil { - addr.PersonalName, _ = decodeHeader(s) - } - if s, err := ParseString(fields[1]); err == nil { - addr.AtDomainList, _ = decodeHeader(s) - } - - s, err := ParseString(fields[2]) - if err != nil { - return errors.New("Mailbox name could not be parsed") - } - addr.MailboxName, _ = decodeHeader(s) - - s, err = ParseString(fields[3]) - if err != nil { - return errors.New("Host name could not be parsed") - } - addr.HostName, _ = decodeHeader(s) - - return nil -} - -// Format an address to fields. -func (addr *Address) Format() []interface{} { - fields := make([]interface{}, 4) - - if addr.PersonalName != "" { - fields[0] = encodeHeader(addr.PersonalName) - } - if addr.AtDomainList != "" { - fields[1] = addr.AtDomainList - } - if addr.MailboxName != "" { - fields[2] = addr.MailboxName - } - if addr.HostName != "" { - fields[3] = addr.HostName - } - - return fields -} - -// Parse an address list from fields. -func ParseAddressList(fields []interface{}) (addrs []*Address) { - for _, f := range fields { - if addrFields, ok := f.([]interface{}); ok { - addr := &Address{} - if err := addr.Parse(addrFields); err == nil { - addrs = append(addrs, addr) - } - } - } - - return -} - -// Format an address list to fields. -func FormatAddressList(addrs []*Address) interface{} { - if len(addrs) == 0 { - return nil - } - - fields := make([]interface{}, len(addrs)) - - for i, addr := range addrs { - fields[i] = addr.Format() - } - - return fields -} - -// A message envelope, ie. message metadata from its headers. -// See RFC 3501 page 77. -type Envelope struct { - // The message date. - Date time.Time - // The message subject. - Subject string - // The From header addresses. - From []*Address - // The message senders. - Sender []*Address - // The Reply-To header addresses. - ReplyTo []*Address - // The To header addresses. - To []*Address - // The Cc header addresses. - Cc []*Address - // The Bcc header addresses. - Bcc []*Address - // The In-Reply-To header. Contains the parent Message-Id. - InReplyTo string - // The Message-Id header. - MessageId string -} - -// Parse an envelope from fields. -func (e *Envelope) Parse(fields []interface{}) error { - if len(fields) < 10 { - return errors.New("ENVELOPE doesn't contain 10 fields") - } - - if date, ok := fields[0].(string); ok { - e.Date, _ = parseMessageDateTime(date) - } - if subject, err := ParseString(fields[1]); err == nil { - e.Subject, _ = decodeHeader(subject) - } - if from, ok := fields[2].([]interface{}); ok { - e.From = ParseAddressList(from) - } - if sender, ok := fields[3].([]interface{}); ok { - e.Sender = ParseAddressList(sender) - } - if replyTo, ok := fields[4].([]interface{}); ok { - e.ReplyTo = ParseAddressList(replyTo) - } - if to, ok := fields[5].([]interface{}); ok { - e.To = ParseAddressList(to) - } - if cc, ok := fields[6].([]interface{}); ok { - e.Cc = ParseAddressList(cc) - } - if bcc, ok := fields[7].([]interface{}); ok { - e.Bcc = ParseAddressList(bcc) - } - if inReplyTo, ok := fields[8].(string); ok { - e.InReplyTo = inReplyTo - } - if msgId, ok := fields[9].(string); ok { - e.MessageId = msgId - } - - return nil -} - -// Format an envelope to fields. -func (e *Envelope) Format() (fields []interface{}) { - fields = make([]interface{}, 0, 10) - fields = append(fields, envelopeDateTime(e.Date)) - if e.Subject != "" { - fields = append(fields, encodeHeader(e.Subject)) - } else { - fields = append(fields, nil) - } - fields = append(fields, - FormatAddressList(e.From), - FormatAddressList(e.Sender), - FormatAddressList(e.ReplyTo), - FormatAddressList(e.To), - FormatAddressList(e.Cc), - FormatAddressList(e.Bcc), - ) - if e.InReplyTo != "" { - fields = append(fields, e.InReplyTo) - } else { - fields = append(fields, nil) - } - if e.MessageId != "" { - fields = append(fields, e.MessageId) - } else { - fields = append(fields, nil) - } - return fields -} - -// A body structure. -// See RFC 3501 page 74. -type BodyStructure struct { - // Basic fields - - // The MIME type (e.g. "text", "image") - MIMEType string - // The MIME subtype (e.g. "plain", "png") - MIMESubType string - // The MIME parameters. - Params map[string]string - - // The Content-Id header. - Id string - // The Content-Description header. - Description string - // The Content-Encoding header. - Encoding string - // The Content-Length header. - Size uint32 - - // Type-specific fields - - // The children parts, if multipart. - Parts []*BodyStructure - // The envelope, if message/rfc822. - Envelope *Envelope - // The body structure, if message/rfc822. - BodyStructure *BodyStructure - // The number of lines, if text or message/rfc822. - Lines uint32 - - // Extension data - - // True if the body structure contains extension data. - Extended bool - - // The Content-Disposition header field value. - Disposition string - // The Content-Disposition header field parameters. - DispositionParams map[string]string - // The Content-Language header field, if multipart. - Language []string - // The content URI, if multipart. - Location []string - - // The MD5 checksum. - MD5 string -} - -func (bs *BodyStructure) Parse(fields []interface{}) error { - if len(fields) == 0 { - return nil - } - - // Initialize params map - bs.Params = make(map[string]string) - - switch fields[0].(type) { - case []interface{}: // A multipart body part - bs.MIMEType = "multipart" - - end := 0 - for i, fi := range fields { - switch f := fi.(type) { - case []interface{}: // A part - part := new(BodyStructure) - if err := part.Parse(f); err != nil { - return err - } - bs.Parts = append(bs.Parts, part) - case string: - end = i - } - - if end > 0 { - break - } - } - - bs.MIMESubType, _ = fields[end].(string) - end++ - - // GMail seems to return only 3 extension data fields. Parse as many fields - // as we can. - if len(fields) > end { - bs.Extended = true // Contains extension data - - params, _ := fields[end].([]interface{}) - bs.Params, _ = parseHeaderParamList(params) - end++ - } - if len(fields) > end { - if disp, ok := fields[end].([]interface{}); ok && len(disp) >= 2 { - if s, ok := disp[0].(string); ok { - bs.Disposition, _ = decodeHeader(s) - bs.Disposition = strings.ToLower(bs.Disposition) - } - if params, ok := disp[1].([]interface{}); ok { - bs.DispositionParams, _ = parseHeaderParamList(params) - } - } - end++ - } - if len(fields) > end { - switch langs := fields[end].(type) { - case string: - bs.Language = []string{langs} - case []interface{}: - bs.Language, _ = ParseStringList(langs) - default: - bs.Language = nil - } - end++ - } - if len(fields) > end { - location, _ := fields[end].([]interface{}) - bs.Location, _ = ParseStringList(location) - end++ - } - case string: // A non-multipart body part - if len(fields) < 7 { - return errors.New("Non-multipart body part doesn't have 7 fields") - } - - bs.MIMEType, _ = stringLowered(fields[0]) - bs.MIMESubType, _ = stringLowered(fields[1]) - - params, _ := fields[2].([]interface{}) - bs.Params, _ = parseHeaderParamList(params) - - bs.Id, _ = fields[3].(string) - if desc, err := ParseString(fields[4]); err == nil { - bs.Description, _ = decodeHeader(desc) - } - bs.Encoding, _ = stringLowered(fields[5]) - bs.Size, _ = ParseNumber(fields[6]) - - end := 7 - - // Type-specific fields - if strings.EqualFold(bs.MIMEType, "message") && strings.EqualFold(bs.MIMESubType, "rfc822") { - if len(fields)-end < 3 { - return errors.New("Missing type-specific fields for message/rfc822") - } - - envelope, _ := fields[end].([]interface{}) - bs.Envelope = new(Envelope) - bs.Envelope.Parse(envelope) - - structure, _ := fields[end+1].([]interface{}) - bs.BodyStructure = new(BodyStructure) - bs.BodyStructure.Parse(structure) - - bs.Lines, _ = ParseNumber(fields[end+2]) - - end += 3 - } - if strings.EqualFold(bs.MIMEType, "text") { - if len(fields)-end < 1 { - return errors.New("Missing type-specific fields for text/*") - } - - bs.Lines, _ = ParseNumber(fields[end]) - end++ - } - - // GMail seems to return only 3 extension data fields. Parse as many fields - // as we can. - if len(fields) > end { - bs.Extended = true // Contains extension data - - bs.MD5, _ = fields[end].(string) - end++ - } - if len(fields) > end { - if disp, ok := fields[end].([]interface{}); ok && len(disp) >= 2 { - if s, ok := disp[0].(string); ok { - bs.Disposition, _ = decodeHeader(s) - bs.Disposition = strings.ToLower(bs.Disposition) - } - if params, ok := disp[1].([]interface{}); ok { - bs.DispositionParams, _ = parseHeaderParamList(params) - } - } - end++ - } - if len(fields) > end { - switch langs := fields[end].(type) { - case string: - bs.Language = []string{langs} - case []interface{}: - bs.Language, _ = ParseStringList(langs) - default: - bs.Language = nil - } - end++ - } - if len(fields) > end { - location, _ := fields[end].([]interface{}) - bs.Location, _ = ParseStringList(location) - end++ - } - } - - return nil -} - -func (bs *BodyStructure) Format() (fields []interface{}) { - if strings.EqualFold(bs.MIMEType, "multipart") { - for _, part := range bs.Parts { - fields = append(fields, part.Format()) - } - - fields = append(fields, bs.MIMESubType) - - if bs.Extended { - extended := make([]interface{}, 4) - - if bs.Params != nil { - extended[0] = formatHeaderParamList(bs.Params) - } - if bs.Disposition != "" { - extended[1] = []interface{}{ - encodeHeader(bs.Disposition), - formatHeaderParamList(bs.DispositionParams), - } - } - if bs.Language != nil { - extended[2] = FormatStringList(bs.Language) - } - if bs.Location != nil { - extended[3] = FormatStringList(bs.Location) - } - - fields = append(fields, extended...) - } - } else { - fields = make([]interface{}, 7) - fields[0] = bs.MIMEType - fields[1] = bs.MIMESubType - fields[2] = formatHeaderParamList(bs.Params) - - if bs.Id != "" { - fields[3] = bs.Id - } - if bs.Description != "" { - fields[4] = encodeHeader(bs.Description) - } - if bs.Encoding != "" { - fields[5] = bs.Encoding - } - - fields[6] = bs.Size - - // Type-specific fields - if strings.EqualFold(bs.MIMEType, "message") && strings.EqualFold(bs.MIMESubType, "rfc822") { - var env interface{} - if bs.Envelope != nil { - env = bs.Envelope.Format() - } - - var bsbs interface{} - if bs.BodyStructure != nil { - bsbs = bs.BodyStructure.Format() - } - - fields = append(fields, env, bsbs, bs.Lines) - } - if strings.EqualFold(bs.MIMEType, "text") { - fields = append(fields, bs.Lines) - } - - // Extension data - if bs.Extended { - extended := make([]interface{}, 4) - - if bs.MD5 != "" { - extended[0] = bs.MD5 - } - if bs.Disposition != "" { - extended[1] = []interface{}{ - encodeHeader(bs.Disposition), - formatHeaderParamList(bs.DispositionParams), - } - } - if bs.Language != nil { - extended[2] = FormatStringList(bs.Language) - } - if bs.Location != nil { - extended[3] = FormatStringList(bs.Location) - } - - fields = append(fields, extended...) - } - } - - return -} - -// Filename parses the body structure's filename, if it's an attachment. An -// empty string is returned if the filename isn't specified. An error is -// returned if and only if a charset error occurs, in which case the undecoded -// filename is returned too. -func (bs *BodyStructure) Filename() (string, error) { - raw, ok := bs.DispositionParams["filename"] - if !ok { - // Using "name" in Content-Type is discouraged - raw = bs.Params["name"] - } - return decodeHeader(raw) -} - -// BodyStructureWalkFunc is the type of the function called for each body -// structure visited by BodyStructure.Walk. The path argument contains the IMAP -// part path (see BodyPartName). -// -// The function should return true to visit all of the part's children or false -// to skip them. -type BodyStructureWalkFunc func(path []int, part *BodyStructure) (walkChildren bool) - -// Walk walks the body structure tree, calling f for each part in the tree, -// including bs itself. The parts are visited in DFS pre-order. -func (bs *BodyStructure) Walk(f BodyStructureWalkFunc) { - // Non-multipart messages only have part 1 - if len(bs.Parts) == 0 { - f([]int{1}, bs) - return - } - - bs.walk(f, nil) -} - -func (bs *BodyStructure) walk(f BodyStructureWalkFunc, path []int) { - if !f(path, bs) { - return - } - - for i, part := range bs.Parts { - num := i + 1 - - partPath := append([]int(nil), path...) - partPath = append(partPath, num) - - part.walk(f, partPath) - } -} diff --git a/vendor/github.com/emersion/go-imap/read.go b/vendor/github.com/emersion/go-imap/read.go deleted file mode 100644 index 112ee28..0000000 --- a/vendor/github.com/emersion/go-imap/read.go +++ /dev/null @@ -1,467 +0,0 @@ -package imap - -import ( - "bytes" - "errors" - "io" - "strconv" - "strings" -) - -const ( - sp = ' ' - cr = '\r' - lf = '\n' - dquote = '"' - literalStart = '{' - literalEnd = '}' - listStart = '(' - listEnd = ')' - respCodeStart = '[' - respCodeEnd = ']' -) - -const ( - crlf = "\r\n" - nilAtom = "NIL" -) - -// TODO: add CTL to atomSpecials -var ( - quotedSpecials = string([]rune{dquote, '\\'}) - respSpecials = string([]rune{respCodeEnd}) - atomSpecials = string([]rune{listStart, listEnd, literalStart, sp, '%', '*'}) + quotedSpecials + respSpecials -) - -type parseError struct { - error -} - -func newParseError(text string) error { - return &parseError{errors.New(text)} -} - -// IsParseError returns true if the provided error is a parse error produced by -// Reader. -func IsParseError(err error) bool { - _, ok := err.(*parseError) - return ok -} - -// A string reader. -type StringReader interface { - // ReadString reads until the first occurrence of delim in the input, - // returning a string containing the data up to and including the delimiter. - // See https://golang.org/pkg/bufio/#Reader.ReadString - ReadString(delim byte) (line string, err error) -} - -type reader interface { - io.Reader - io.RuneScanner - StringReader -} - -// ParseNumber parses a number. -func ParseNumber(f interface{}) (uint32, error) { - // Useful for tests - if n, ok := f.(uint32); ok { - return n, nil - } - - var s string - switch f := f.(type) { - case RawString: - s = string(f) - case string: - s = f - default: - return 0, newParseError("expected a number, got a non-atom") - } - - nbr, err := strconv.ParseUint(string(s), 10, 32) - if err != nil { - return 0, &parseError{err} - } - - return uint32(nbr), nil -} - -// ParseString parses a string, which is either a literal, a quoted string or an -// atom. -func ParseString(f interface{}) (string, error) { - if s, ok := f.(string); ok { - return s, nil - } - - // Useful for tests - if a, ok := f.(RawString); ok { - return string(a), nil - } - - if l, ok := f.(Literal); ok { - b := make([]byte, l.Len()) - if _, err := io.ReadFull(l, b); err != nil { - return "", err - } - return string(b), nil - } - - return "", newParseError("expected a string") -} - -// Convert a field list to a string list. -func ParseStringList(f interface{}) ([]string, error) { - fields, ok := f.([]interface{}) - if !ok { - return nil, newParseError("expected a string list, got a non-list") - } - - list := make([]string, len(fields)) - for i, f := range fields { - var err error - if list[i], err = ParseString(f); err != nil { - return nil, newParseError("cannot parse string in string list: " + err.Error()) - } - } - return list, nil -} - -func trimSuffix(str string, suffix rune) string { - return str[:len(str)-1] -} - -// An IMAP reader. -type Reader struct { - MaxLiteralSize uint32 // The maximum literal size. - - reader - - continues chan<- bool - - brackets int - inRespCode bool -} - -func (r *Reader) ReadSp() error { - char, _, err := r.ReadRune() - if err != nil { - return err - } - if char != sp { - return newParseError("expected a space") - } - return nil -} - -func (r *Reader) ReadCrlf() (err error) { - var char rune - - if char, _, err = r.ReadRune(); err != nil { - return - } - if char == lf { - return - } - if char != cr { - err = newParseError("line doesn't end with a CR") - return - } - - if char, _, err = r.ReadRune(); err != nil { - return - } - if char != lf { - err = newParseError("line doesn't end with a LF") - } - - return -} - -func (r *Reader) ReadAtom() (interface{}, error) { - r.brackets = 0 - - var atom string - for { - char, _, err := r.ReadRune() - if err != nil { - return nil, err - } - - // TODO: list-wildcards and \ - if r.brackets == 0 && (char == listStart || char == literalStart || char == dquote) { - return nil, newParseError("atom contains forbidden char: " + string(char)) - } - if char == cr || char == lf { - break - } - if r.brackets == 0 && (char == sp || char == listEnd) { - break - } - if char == respCodeEnd { - if r.brackets == 0 { - if r.inRespCode { - break - } else { - return nil, newParseError("atom contains bad brackets nesting") - } - } - r.brackets-- - } - if char == respCodeStart { - r.brackets++ - } - - atom += string(char) - } - - r.UnreadRune() - - if atom == nilAtom { - return nil, nil - } - - return atom, nil -} - -func (r *Reader) ReadLiteral() (Literal, error) { - char, _, err := r.ReadRune() - if err != nil { - return nil, err - } else if char != literalStart { - return nil, newParseError("literal string doesn't start with an open brace") - } - - lstr, err := r.ReadString(byte(literalEnd)) - if err != nil { - return nil, err - } - lstr = trimSuffix(lstr, literalEnd) - - nonSync := strings.HasSuffix(lstr, "+") - if nonSync { - lstr = trimSuffix(lstr, '+') - } - - n, err := strconv.ParseUint(lstr, 10, 32) - if err != nil { - return nil, newParseError("cannot parse literal length: " + err.Error()) - } - if r.MaxLiteralSize > 0 && uint32(n) > r.MaxLiteralSize { - return nil, newParseError("literal exceeding maximum size") - } - - if err := r.ReadCrlf(); err != nil { - return nil, err - } - - // Send continuation request if necessary - if r.continues != nil && !nonSync { - r.continues <- true - } - - // Read literal - b := make([]byte, n) - if _, err := io.ReadFull(r, b); err != nil { - return nil, err - } - return bytes.NewBuffer(b), nil -} - -func (r *Reader) ReadQuotedString() (string, error) { - if char, _, err := r.ReadRune(); err != nil { - return "", err - } else if char != dquote { - return "", newParseError("quoted string doesn't start with a double quote") - } - - var buf bytes.Buffer - var escaped bool - for { - char, _, err := r.ReadRune() - if err != nil { - return "", err - } - - if char == '\\' && !escaped { - escaped = true - } else { - if char == cr || char == lf { - r.UnreadRune() - return "", newParseError("CR or LF not allowed in quoted string") - } - if char == dquote && !escaped { - break - } - - if !strings.ContainsRune(quotedSpecials, char) && escaped { - return "", newParseError("quoted string cannot contain backslash followed by a non-quoted-specials char") - } - - buf.WriteRune(char) - escaped = false - } - } - - return buf.String(), nil -} - -func (r *Reader) ReadFields() (fields []interface{}, err error) { - var char rune - for { - if char, _, err = r.ReadRune(); err != nil { - return - } - if err = r.UnreadRune(); err != nil { - return - } - - var field interface{} - ok := true - switch char { - case literalStart: - field, err = r.ReadLiteral() - case dquote: - field, err = r.ReadQuotedString() - case listStart: - field, err = r.ReadList() - case listEnd: - ok = false - case cr: - return - default: - field, err = r.ReadAtom() - } - - if err != nil { - return - } - if ok { - fields = append(fields, field) - } - - if char, _, err = r.ReadRune(); err != nil { - return - } - if char == cr || char == lf || char == listEnd || char == respCodeEnd { - if char == cr || char == lf { - r.UnreadRune() - } - return - } - if char == listStart { - r.UnreadRune() - continue - } - if char != sp { - err = newParseError("fields are not separated by a space") - return - } - } -} - -func (r *Reader) ReadList() (fields []interface{}, err error) { - char, _, err := r.ReadRune() - if err != nil { - return - } - if char != listStart { - err = newParseError("list doesn't start with an open parenthesis") - return - } - - fields, err = r.ReadFields() - if err != nil { - return - } - - r.UnreadRune() - if char, _, err = r.ReadRune(); err != nil { - return - } - if char != listEnd { - err = newParseError("list doesn't end with a close parenthesis") - } - return -} - -func (r *Reader) ReadLine() (fields []interface{}, err error) { - fields, err = r.ReadFields() - if err != nil { - return - } - - r.UnreadRune() - err = r.ReadCrlf() - return -} - -func (r *Reader) ReadRespCode() (code StatusRespCode, fields []interface{}, err error) { - char, _, err := r.ReadRune() - if err != nil { - return - } - if char != respCodeStart { - err = newParseError("response code doesn't start with an open bracket") - return - } - - r.inRespCode = true - fields, err = r.ReadFields() - r.inRespCode = false - if err != nil { - return - } - - if len(fields) == 0 { - err = newParseError("response code doesn't contain any field") - return - } - - codeStr, ok := fields[0].(string) - if !ok { - err = newParseError("response code doesn't start with a string atom") - return - } - if codeStr == "" { - err = newParseError("response code is empty") - return - } - code = StatusRespCode(strings.ToUpper(codeStr)) - - fields = fields[1:] - - r.UnreadRune() - char, _, err = r.ReadRune() - if err != nil { - return - } - if char != respCodeEnd { - err = newParseError("response code doesn't end with a close bracket") - } - return -} - -func (r *Reader) ReadInfo() (info string, err error) { - info, err = r.ReadString(byte(lf)) - if err != nil { - return - } - info = strings.TrimSuffix(info, string(lf)) - info = strings.TrimSuffix(info, string(cr)) - info = strings.TrimLeft(info, " ") - - return -} - -func NewReader(r reader) *Reader { - return &Reader{reader: r} -} - -func NewServerReader(r reader, continues chan<- bool) *Reader { - return &Reader{reader: r, continues: continues} -} - -type Parser interface { - Parse(fields []interface{}) error -} diff --git a/vendor/github.com/emersion/go-imap/response.go b/vendor/github.com/emersion/go-imap/response.go deleted file mode 100644 index 611d03e..0000000 --- a/vendor/github.com/emersion/go-imap/response.go +++ /dev/null @@ -1,181 +0,0 @@ -package imap - -import ( - "strings" -) - -// Resp is an IMAP response. It is either a *DataResp, a -// *ContinuationReq or a *StatusResp. -type Resp interface { - resp() -} - -// ReadResp reads a single response from a Reader. -func ReadResp(r *Reader) (Resp, error) { - atom, err := r.ReadAtom() - if err != nil { - return nil, err - } - tag, ok := atom.(string) - if !ok { - return nil, newParseError("response tag is not an atom") - } - - if tag == "+" { - if err := r.ReadSp(); err != nil { - r.UnreadRune() - } - - resp := &ContinuationReq{} - resp.Info, err = r.ReadInfo() - if err != nil { - return nil, err - } - - return resp, nil - } - - if err := r.ReadSp(); err != nil { - return nil, err - } - - // Can be either data or status - // Try to parse a status - var fields []interface{} - if atom, err := r.ReadAtom(); err == nil { - fields = append(fields, atom) - - if err := r.ReadSp(); err == nil { - if name, ok := atom.(string); ok { - status := StatusRespType(name) - switch status { - case StatusRespOk, StatusRespNo, StatusRespBad, StatusRespPreauth, StatusRespBye: - resp := &StatusResp{ - Tag: tag, - Type: status, - } - - char, _, err := r.ReadRune() - if err != nil { - return nil, err - } - r.UnreadRune() - - if char == '[' { - // Contains code & arguments - resp.Code, resp.Arguments, err = r.ReadRespCode() - if err != nil { - return nil, err - } - } - - resp.Info, err = r.ReadInfo() - if err != nil { - return nil, err - } - - return resp, nil - } - } - } else { - r.UnreadRune() - } - } else { - r.UnreadRune() - } - - // Not a status so it's data - resp := &DataResp{Tag: tag} - - var remaining []interface{} - remaining, err = r.ReadLine() - if err != nil { - return nil, err - } - - resp.Fields = append(fields, remaining...) - return resp, nil -} - -// DataResp is an IMAP response containing data. -type DataResp struct { - // The response tag. Can be either "" for untagged responses, "+" for continuation - // requests or a previous command's tag. - Tag string - // The parsed response fields. - Fields []interface{} -} - -// NewUntaggedResp creates a new untagged response. -func NewUntaggedResp(fields []interface{}) *DataResp { - return &DataResp{ - Tag: "*", - Fields: fields, - } -} - -func (r *DataResp) resp() {} - -func (r *DataResp) WriteTo(w *Writer) error { - tag := RawString(r.Tag) - if tag == "" { - tag = RawString("*") - } - - fields := []interface{}{RawString(tag)} - fields = append(fields, r.Fields...) - return w.writeLine(fields...) -} - -// ContinuationReq is a continuation request response. -type ContinuationReq struct { - // The info message sent with the continuation request. - Info string -} - -func (r *ContinuationReq) resp() {} - -func (r *ContinuationReq) WriteTo(w *Writer) error { - if err := w.writeString("+"); err != nil { - return err - } - - if r.Info != "" { - if err := w.writeString(string(sp) + r.Info); err != nil { - return err - } - } - - return w.writeCrlf() -} - -// ParseNamedResp attempts to parse a named data response. -func ParseNamedResp(resp Resp) (name string, fields []interface{}, ok bool) { - data, ok := resp.(*DataResp) - if !ok || len(data.Fields) == 0 { - return - } - - // Some responses (namely EXISTS and RECENT) are formatted like so: - // [num] [name] [...] - // Which is fucking stupid. But we handle that here by checking if the - // response name is a number and then rearranging it. - if len(data.Fields) > 1 { - name, ok := data.Fields[1].(string) - if ok { - if _, err := ParseNumber(data.Fields[0]); err == nil { - fields := []interface{}{data.Fields[0]} - fields = append(fields, data.Fields[2:]...) - return strings.ToUpper(name), fields, true - } - } - } - - // IMAP commands are formatted like this: - // [name] [...] - name, ok = data.Fields[0].(string) - if !ok { - return - } - return strings.ToUpper(name), data.Fields[1:], true -} diff --git a/vendor/github.com/emersion/go-imap/responses/authenticate.go b/vendor/github.com/emersion/go-imap/responses/authenticate.go deleted file mode 100644 index 8e134cb..0000000 --- a/vendor/github.com/emersion/go-imap/responses/authenticate.go +++ /dev/null @@ -1,61 +0,0 @@ -package responses - -import ( - "encoding/base64" - - "github.com/emersion/go-imap" - "github.com/emersion/go-sasl" -) - -// An AUTHENTICATE response. -type Authenticate struct { - Mechanism sasl.Client - InitialResponse []byte - RepliesCh chan []byte -} - -// Implements -func (r *Authenticate) Replies() <-chan []byte { - return r.RepliesCh -} - -func (r *Authenticate) writeLine(l string) error { - r.RepliesCh <- []byte(l + "\r\n") - return nil -} - -func (r *Authenticate) cancel() error { - return r.writeLine("*") -} - -func (r *Authenticate) Handle(resp imap.Resp) error { - cont, ok := resp.(*imap.ContinuationReq) - if !ok { - return ErrUnhandled - } - - // Empty challenge, send initial response as stated in RFC 2222 section 5.1 - if cont.Info == "" && r.InitialResponse != nil { - encoded := base64.StdEncoding.EncodeToString(r.InitialResponse) - if err := r.writeLine(encoded); err != nil { - return err - } - r.InitialResponse = nil - return nil - } - - challenge, err := base64.StdEncoding.DecodeString(cont.Info) - if err != nil { - r.cancel() - return err - } - - reply, err := r.Mechanism.Next(challenge) - if err != nil { - r.cancel() - return err - } - - encoded := base64.StdEncoding.EncodeToString(reply) - return r.writeLine(encoded) -} diff --git a/vendor/github.com/emersion/go-imap/responses/capability.go b/vendor/github.com/emersion/go-imap/responses/capability.go deleted file mode 100644 index 483cb2e..0000000 --- a/vendor/github.com/emersion/go-imap/responses/capability.go +++ /dev/null @@ -1,20 +0,0 @@ -package responses - -import ( - "github.com/emersion/go-imap" -) - -// A CAPABILITY response. -// See RFC 3501 section 7.2.1 -type Capability struct { - Caps []string -} - -func (r *Capability) WriteTo(w *imap.Writer) error { - fields := []interface{}{imap.RawString("CAPABILITY")} - for _, cap := range r.Caps { - fields = append(fields, imap.RawString(cap)) - } - - return imap.NewUntaggedResp(fields).WriteTo(w) -} diff --git a/vendor/github.com/emersion/go-imap/responses/enabled.go b/vendor/github.com/emersion/go-imap/responses/enabled.go deleted file mode 100644 index fc4e27b..0000000 --- a/vendor/github.com/emersion/go-imap/responses/enabled.go +++ /dev/null @@ -1,33 +0,0 @@ -package responses - -import ( - "github.com/emersion/go-imap" -) - -// An ENABLED response, defined in RFC 5161 section 3.2. -type Enabled struct { - Caps []string -} - -func (r *Enabled) Handle(resp imap.Resp) error { - name, fields, ok := imap.ParseNamedResp(resp) - if !ok || name != "ENABLED" { - return ErrUnhandled - } - - if caps, err := imap.ParseStringList(fields); err != nil { - return err - } else { - r.Caps = append(r.Caps, caps...) - } - - return nil -} - -func (r *Enabled) WriteTo(w *imap.Writer) error { - fields := []interface{}{imap.RawString("ENABLED")} - for _, cap := range r.Caps { - fields = append(fields, imap.RawString(cap)) - } - return imap.NewUntaggedResp(fields).WriteTo(w) -} diff --git a/vendor/github.com/emersion/go-imap/responses/expunge.go b/vendor/github.com/emersion/go-imap/responses/expunge.go deleted file mode 100644 index bce3bf1..0000000 --- a/vendor/github.com/emersion/go-imap/responses/expunge.go +++ /dev/null @@ -1,43 +0,0 @@ -package responses - -import ( - "github.com/emersion/go-imap" -) - -const expungeName = "EXPUNGE" - -// An EXPUNGE response. -// See RFC 3501 section 7.4.1 -type Expunge struct { - SeqNums chan uint32 -} - -func (r *Expunge) Handle(resp imap.Resp) error { - name, fields, ok := imap.ParseNamedResp(resp) - if !ok || name != expungeName { - return ErrUnhandled - } - - if len(fields) == 0 { - return errNotEnoughFields - } - - seqNum, err := imap.ParseNumber(fields[0]) - if err != nil { - return err - } - - r.SeqNums <- seqNum - return nil -} - -func (r *Expunge) WriteTo(w *imap.Writer) error { - for seqNum := range r.SeqNums { - resp := imap.NewUntaggedResp([]interface{}{seqNum, imap.RawString(expungeName)}) - if err := resp.WriteTo(w); err != nil { - return err - } - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/responses/fetch.go b/vendor/github.com/emersion/go-imap/responses/fetch.go deleted file mode 100644 index 691ebcb..0000000 --- a/vendor/github.com/emersion/go-imap/responses/fetch.go +++ /dev/null @@ -1,70 +0,0 @@ -package responses - -import ( - "github.com/emersion/go-imap" -) - -const fetchName = "FETCH" - -// A FETCH response. -// See RFC 3501 section 7.4.2 -type Fetch struct { - Messages chan *imap.Message - SeqSet *imap.SeqSet - Uid bool -} - -func (r *Fetch) Handle(resp imap.Resp) error { - name, fields, ok := imap.ParseNamedResp(resp) - if !ok || name != fetchName { - return ErrUnhandled - } else if len(fields) < 1 { - return errNotEnoughFields - } - - seqNum, err := imap.ParseNumber(fields[0]) - if err != nil { - return err - } - - msgFields, _ := fields[1].([]interface{}) - msg := &imap.Message{SeqNum: seqNum} - if err := msg.Parse(msgFields); err != nil { - return err - } - - if r.Uid && msg.Uid == 0 { - // we requested UIDs and got a message without one --> unilateral update --> ignore - return ErrUnhandled - } - - var num uint32 - if r.Uid { - num = msg.Uid - } else { - num = seqNum - } - - // Check whether we obtained a result we requested with our SeqSet - // If the result is not contained in our SeqSet we have to handle an additional special case: - // In case we requested UIDs with a dynamic sequence (i.e. * or n:*) and the maximum UID of the mailbox - // is less then our n, the server will supply us with the max UID (cf. RFC 3501 §6.4.8 and §9 `seq-range`). - // Thus, such a result is correct and has to be returned by us. - if !r.SeqSet.Contains(num) && (!r.Uid || !r.SeqSet.Dynamic()) { - return ErrUnhandled - } - - r.Messages <- msg - return nil -} - -func (r *Fetch) WriteTo(w *imap.Writer) error { - var err error - for msg := range r.Messages { - resp := imap.NewUntaggedResp([]interface{}{msg.SeqNum, imap.RawString(fetchName), msg.Format()}) - if err == nil { - err = resp.WriteTo(w) - } - } - return err -} diff --git a/vendor/github.com/emersion/go-imap/responses/idle.go b/vendor/github.com/emersion/go-imap/responses/idle.go deleted file mode 100644 index b5efcac..0000000 --- a/vendor/github.com/emersion/go-imap/responses/idle.go +++ /dev/null @@ -1,38 +0,0 @@ -package responses - -import ( - "github.com/emersion/go-imap" -) - -// An IDLE response. -type Idle struct { - RepliesCh chan []byte - Stop <-chan struct{} - - gotContinuationReq bool -} - -func (r *Idle) Replies() <-chan []byte { - return r.RepliesCh -} - -func (r *Idle) stop() { - r.RepliesCh <- []byte("DONE\r\n") -} - -func (r *Idle) Handle(resp imap.Resp) error { - // Wait for a continuation request - if _, ok := resp.(*imap.ContinuationReq); ok && !r.gotContinuationReq { - r.gotContinuationReq = true - - // We got a continuation request, wait for r.Stop to be closed - go func() { - <-r.Stop - r.stop() - }() - - return nil - } - - return ErrUnhandled -} diff --git a/vendor/github.com/emersion/go-imap/responses/list.go b/vendor/github.com/emersion/go-imap/responses/list.go deleted file mode 100644 index e080fc1..0000000 --- a/vendor/github.com/emersion/go-imap/responses/list.go +++ /dev/null @@ -1,57 +0,0 @@ -package responses - -import ( - "github.com/emersion/go-imap" -) - -const ( - listName = "LIST" - lsubName = "LSUB" -) - -// A LIST response. -// If Subscribed is set to true, LSUB will be used instead. -// See RFC 3501 section 7.2.2 -type List struct { - Mailboxes chan *imap.MailboxInfo - Subscribed bool -} - -func (r *List) Name() string { - if r.Subscribed { - return lsubName - } else { - return listName - } -} - -func (r *List) Handle(resp imap.Resp) error { - name, fields, ok := imap.ParseNamedResp(resp) - if !ok || name != r.Name() { - return ErrUnhandled - } - - mbox := &imap.MailboxInfo{} - if err := mbox.Parse(fields); err != nil { - return err - } - - r.Mailboxes <- mbox - return nil -} - -func (r *List) WriteTo(w *imap.Writer) error { - respName := r.Name() - - for mbox := range r.Mailboxes { - fields := []interface{}{imap.RawString(respName)} - fields = append(fields, mbox.Format()...) - - resp := imap.NewUntaggedResp(fields) - if err := resp.WriteTo(w); err != nil { - return err - } - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/responses/responses.go b/vendor/github.com/emersion/go-imap/responses/responses.go deleted file mode 100644 index 4d035ee..0000000 --- a/vendor/github.com/emersion/go-imap/responses/responses.go +++ /dev/null @@ -1,35 +0,0 @@ -// IMAP responses defined in RFC 3501. -package responses - -import ( - "errors" - - "github.com/emersion/go-imap" -) - -// ErrUnhandled is used when a response hasn't been handled. -var ErrUnhandled = errors.New("imap: unhandled response") - -var errNotEnoughFields = errors.New("imap: not enough fields in response") - -// Handler handles responses. -type Handler interface { - // Handle processes a response. If the response cannot be processed, - // ErrUnhandledResp must be returned. - Handle(resp imap.Resp) error -} - -// HandlerFunc is a function that handles responses. -type HandlerFunc func(resp imap.Resp) error - -// Handle implements Handler. -func (f HandlerFunc) Handle(resp imap.Resp) error { - return f(resp) -} - -// Replier is a Handler that needs to send raw data (for instance -// AUTHENTICATE). -type Replier interface { - Handler - Replies() <-chan []byte -} diff --git a/vendor/github.com/emersion/go-imap/responses/search.go b/vendor/github.com/emersion/go-imap/responses/search.go deleted file mode 100644 index 028dbc7..0000000 --- a/vendor/github.com/emersion/go-imap/responses/search.go +++ /dev/null @@ -1,41 +0,0 @@ -package responses - -import ( - "github.com/emersion/go-imap" -) - -const searchName = "SEARCH" - -// A SEARCH response. -// See RFC 3501 section 7.2.5 -type Search struct { - Ids []uint32 -} - -func (r *Search) Handle(resp imap.Resp) error { - name, fields, ok := imap.ParseNamedResp(resp) - if !ok || name != searchName { - return ErrUnhandled - } - - r.Ids = make([]uint32, len(fields)) - for i, f := range fields { - if id, err := imap.ParseNumber(f); err != nil { - return err - } else { - r.Ids[i] = id - } - } - - return nil -} - -func (r *Search) WriteTo(w *imap.Writer) (err error) { - fields := []interface{}{imap.RawString(searchName)} - for _, id := range r.Ids { - fields = append(fields, id) - } - - resp := imap.NewUntaggedResp(fields) - return resp.WriteTo(w) -} diff --git a/vendor/github.com/emersion/go-imap/responses/select.go b/vendor/github.com/emersion/go-imap/responses/select.go deleted file mode 100644 index e450963..0000000 --- a/vendor/github.com/emersion/go-imap/responses/select.go +++ /dev/null @@ -1,142 +0,0 @@ -package responses - -import ( - "fmt" - - "github.com/emersion/go-imap" -) - -// A SELECT response. -type Select struct { - Mailbox *imap.MailboxStatus -} - -func (r *Select) Handle(resp imap.Resp) error { - if r.Mailbox == nil { - r.Mailbox = &imap.MailboxStatus{Items: make(map[imap.StatusItem]interface{})} - } - mbox := r.Mailbox - - switch resp := resp.(type) { - case *imap.DataResp: - name, fields, ok := imap.ParseNamedResp(resp) - if !ok || name != "FLAGS" { - return ErrUnhandled - } else if len(fields) < 1 { - return errNotEnoughFields - } - - flags, _ := fields[0].([]interface{}) - mbox.Flags, _ = imap.ParseStringList(flags) - case *imap.StatusResp: - if len(resp.Arguments) < 1 { - return ErrUnhandled - } - - var item imap.StatusItem - switch resp.Code { - case "UNSEEN": - mbox.UnseenSeqNum, _ = imap.ParseNumber(resp.Arguments[0]) - case "PERMANENTFLAGS": - flags, _ := resp.Arguments[0].([]interface{}) - mbox.PermanentFlags, _ = imap.ParseStringList(flags) - case "UIDNEXT": - mbox.UidNext, _ = imap.ParseNumber(resp.Arguments[0]) - item = imap.StatusUidNext - case "UIDVALIDITY": - mbox.UidValidity, _ = imap.ParseNumber(resp.Arguments[0]) - item = imap.StatusUidValidity - default: - return ErrUnhandled - } - - if item != "" { - mbox.ItemsLocker.Lock() - mbox.Items[item] = nil - mbox.ItemsLocker.Unlock() - } - default: - return ErrUnhandled - } - return nil -} - -func (r *Select) WriteTo(w *imap.Writer) error { - mbox := r.Mailbox - - if mbox.Flags != nil { - flags := make([]interface{}, len(mbox.Flags)) - for i, f := range mbox.Flags { - flags[i] = imap.RawString(f) - } - res := imap.NewUntaggedResp([]interface{}{imap.RawString("FLAGS"), flags}) - if err := res.WriteTo(w); err != nil { - return err - } - } - - if mbox.PermanentFlags != nil { - flags := make([]interface{}, len(mbox.PermanentFlags)) - for i, f := range mbox.PermanentFlags { - flags[i] = imap.RawString(f) - } - statusRes := &imap.StatusResp{ - Type: imap.StatusRespOk, - Code: imap.CodePermanentFlags, - Arguments: []interface{}{flags}, - Info: "Flags permitted.", - } - if err := statusRes.WriteTo(w); err != nil { - return err - } - } - - if mbox.UnseenSeqNum > 0 { - statusRes := &imap.StatusResp{ - Type: imap.StatusRespOk, - Code: imap.CodeUnseen, - Arguments: []interface{}{mbox.UnseenSeqNum}, - Info: fmt.Sprintf("Message %d is first unseen", mbox.UnseenSeqNum), - } - if err := statusRes.WriteTo(w); err != nil { - return err - } - } - - for k := range r.Mailbox.Items { - switch k { - case imap.StatusMessages: - res := imap.NewUntaggedResp([]interface{}{mbox.Messages, imap.RawString("EXISTS")}) - if err := res.WriteTo(w); err != nil { - return err - } - case imap.StatusRecent: - res := imap.NewUntaggedResp([]interface{}{mbox.Recent, imap.RawString("RECENT")}) - if err := res.WriteTo(w); err != nil { - return err - } - case imap.StatusUidNext: - statusRes := &imap.StatusResp{ - Type: imap.StatusRespOk, - Code: imap.CodeUidNext, - Arguments: []interface{}{mbox.UidNext}, - Info: "Predicted next UID", - } - if err := statusRes.WriteTo(w); err != nil { - return err - } - case imap.StatusUidValidity: - statusRes := &imap.StatusResp{ - Type: imap.StatusRespOk, - Code: imap.CodeUidValidity, - Arguments: []interface{}{mbox.UidValidity}, - Info: "UIDs valid", - } - if err := statusRes.WriteTo(w); err != nil { - return err - } - } - } - - return nil -} diff --git a/vendor/github.com/emersion/go-imap/responses/status.go b/vendor/github.com/emersion/go-imap/responses/status.go deleted file mode 100644 index 6a8570c..0000000 --- a/vendor/github.com/emersion/go-imap/responses/status.go +++ /dev/null @@ -1,53 +0,0 @@ -package responses - -import ( - "errors" - - "github.com/emersion/go-imap" - "github.com/emersion/go-imap/utf7" -) - -const statusName = "STATUS" - -// A STATUS response. -// See RFC 3501 section 7.2.4 -type Status struct { - Mailbox *imap.MailboxStatus -} - -func (r *Status) Handle(resp imap.Resp) error { - if r.Mailbox == nil { - r.Mailbox = &imap.MailboxStatus{} - } - mbox := r.Mailbox - - name, fields, ok := imap.ParseNamedResp(resp) - if !ok || name != statusName { - return ErrUnhandled - } else if len(fields) < 2 { - return errNotEnoughFields - } - - if name, err := imap.ParseString(fields[0]); err != nil { - return err - } else if name, err := utf7.Encoding.NewDecoder().String(name); err != nil { - return err - } else { - mbox.Name = imap.CanonicalMailboxName(name) - } - - var items []interface{} - if items, ok = fields[1].([]interface{}); !ok { - return errors.New("STATUS response expects a list as second argument") - } - - mbox.Items = nil - return mbox.Parse(items) -} - -func (r *Status) WriteTo(w *imap.Writer) error { - mbox := r.Mailbox - name, _ := utf7.Encoding.NewEncoder().String(mbox.Name) - fields := []interface{}{imap.RawString(statusName), imap.FormatMailboxName(name), mbox.Format()} - return imap.NewUntaggedResp(fields).WriteTo(w) -} diff --git a/vendor/github.com/emersion/go-imap/search.go b/vendor/github.com/emersion/go-imap/search.go deleted file mode 100644 index 0ecb24d..0000000 --- a/vendor/github.com/emersion/go-imap/search.go +++ /dev/null @@ -1,371 +0,0 @@ -package imap - -import ( - "errors" - "fmt" - "io" - "net/textproto" - "strings" - "time" -) - -func maybeString(mystery interface{}) string { - if s, ok := mystery.(string); ok { - return s - } - return "" -} - -func convertField(f interface{}, charsetReader func(io.Reader) io.Reader) string { - // An IMAP string contains only 7-bit data, no need to decode it - if s, ok := f.(string); ok { - return s - } - - // If no charset is provided, getting directly the string is faster - if charsetReader == nil { - if stringer, ok := f.(fmt.Stringer); ok { - return stringer.String() - } - } - - // Not a string, it must be a literal - l, ok := f.(Literal) - if !ok { - return "" - } - - var r io.Reader = l - if charsetReader != nil { - if dec := charsetReader(r); dec != nil { - r = dec - } - } - - b := make([]byte, l.Len()) - if _, err := io.ReadFull(r, b); err != nil { - return "" - } - return string(b) -} - -func popSearchField(fields []interface{}) (interface{}, []interface{}, error) { - if len(fields) == 0 { - return nil, nil, errors.New("imap: no enough fields for search key") - } - return fields[0], fields[1:], nil -} - -// SearchCriteria is a search criteria. A message matches the criteria if and -// only if it matches each one of its fields. -type SearchCriteria struct { - SeqNum *SeqSet // Sequence number is in sequence set - Uid *SeqSet // UID is in sequence set - - // Time and timezone are ignored - Since time.Time // Internal date is since this date - Before time.Time // Internal date is before this date - SentSince time.Time // Date header field is since this date - SentBefore time.Time // Date header field is before this date - - Header textproto.MIMEHeader // Each header field value is present - Body []string // Each string is in the body - Text []string // Each string is in the text (header + body) - - WithFlags []string // Each flag is present - WithoutFlags []string // Each flag is not present - - Larger uint32 // Size is larger than this number - Smaller uint32 // Size is smaller than this number - - Not []*SearchCriteria // Each criteria doesn't match - Or [][2]*SearchCriteria // Each criteria pair has at least one match of two -} - -// NewSearchCriteria creates a new search criteria. -func NewSearchCriteria() *SearchCriteria { - return &SearchCriteria{Header: make(textproto.MIMEHeader)} -} - -func (c *SearchCriteria) parseField(fields []interface{}, charsetReader func(io.Reader) io.Reader) ([]interface{}, error) { - if len(fields) == 0 { - return nil, nil - } - - f := fields[0] - fields = fields[1:] - - if subfields, ok := f.([]interface{}); ok { - return fields, c.ParseWithCharset(subfields, charsetReader) - } - - key, ok := f.(string) - if !ok { - return nil, fmt.Errorf("imap: invalid search criteria field type: %T", f) - } - key = strings.ToUpper(key) - - var err error - switch key { - case "ALL": - // Nothing to do - case "ANSWERED", "DELETED", "DRAFT", "FLAGGED", "RECENT", "SEEN": - c.WithFlags = append(c.WithFlags, CanonicalFlag("\\"+key)) - case "BCC", "CC", "FROM", "SUBJECT", "TO": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } - if c.Header == nil { - c.Header = make(textproto.MIMEHeader) - } - c.Header.Add(key, convertField(f, charsetReader)) - case "BEFORE": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if t, err := time.Parse(DateLayout, maybeString(f)); err != nil { - return nil, err - } else if c.Before.IsZero() || t.Before(c.Before) { - c.Before = t - } - case "BODY": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else { - c.Body = append(c.Body, convertField(f, charsetReader)) - } - case "HEADER": - var f1, f2 interface{} - if f1, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if f2, fields, err = popSearchField(fields); err != nil { - return nil, err - } else { - if c.Header == nil { - c.Header = make(textproto.MIMEHeader) - } - c.Header.Add(maybeString(f1), convertField(f2, charsetReader)) - } - case "KEYWORD": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else { - c.WithFlags = append(c.WithFlags, CanonicalFlag(maybeString(f))) - } - case "LARGER": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if n, err := ParseNumber(f); err != nil { - return nil, err - } else if c.Larger == 0 || n > c.Larger { - c.Larger = n - } - case "NEW": - c.WithFlags = append(c.WithFlags, RecentFlag) - c.WithoutFlags = append(c.WithoutFlags, SeenFlag) - case "NOT": - not := new(SearchCriteria) - if fields, err = not.parseField(fields, charsetReader); err != nil { - return nil, err - } - c.Not = append(c.Not, not) - case "OLD": - c.WithoutFlags = append(c.WithoutFlags, RecentFlag) - case "ON": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if t, err := time.Parse(DateLayout, maybeString(f)); err != nil { - return nil, err - } else { - c.Since = t - c.Before = t.Add(24 * time.Hour) - } - case "OR": - c1, c2 := new(SearchCriteria), new(SearchCriteria) - if fields, err = c1.parseField(fields, charsetReader); err != nil { - return nil, err - } else if fields, err = c2.parseField(fields, charsetReader); err != nil { - return nil, err - } - c.Or = append(c.Or, [2]*SearchCriteria{c1, c2}) - case "SENTBEFORE": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if t, err := time.Parse(DateLayout, maybeString(f)); err != nil { - return nil, err - } else if c.SentBefore.IsZero() || t.Before(c.SentBefore) { - c.SentBefore = t - } - case "SENTON": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if t, err := time.Parse(DateLayout, maybeString(f)); err != nil { - return nil, err - } else { - c.SentSince = t - c.SentBefore = t.Add(24 * time.Hour) - } - case "SENTSINCE": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if t, err := time.Parse(DateLayout, maybeString(f)); err != nil { - return nil, err - } else if c.SentSince.IsZero() || t.After(c.SentSince) { - c.SentSince = t - } - case "SINCE": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if t, err := time.Parse(DateLayout, maybeString(f)); err != nil { - return nil, err - } else if c.Since.IsZero() || t.After(c.Since) { - c.Since = t - } - case "SMALLER": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if n, err := ParseNumber(f); err != nil { - return nil, err - } else if c.Smaller == 0 || n < c.Smaller { - c.Smaller = n - } - case "TEXT": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else { - c.Text = append(c.Text, convertField(f, charsetReader)) - } - case "UID": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else if c.Uid, err = ParseSeqSet(maybeString(f)); err != nil { - return nil, err - } - case "UNANSWERED", "UNDELETED", "UNDRAFT", "UNFLAGGED", "UNSEEN": - unflag := strings.TrimPrefix(key, "UN") - c.WithoutFlags = append(c.WithoutFlags, CanonicalFlag("\\"+unflag)) - case "UNKEYWORD": - if f, fields, err = popSearchField(fields); err != nil { - return nil, err - } else { - c.WithoutFlags = append(c.WithoutFlags, CanonicalFlag(maybeString(f))) - } - default: // Try to parse a sequence set - if c.SeqNum, err = ParseSeqSet(key); err != nil { - return nil, err - } - } - - return fields, nil -} - -// ParseWithCharset parses a search criteria from the provided fields. -// charsetReader is an optional function that converts from the fields charset -// to UTF-8. -func (c *SearchCriteria) ParseWithCharset(fields []interface{}, charsetReader func(io.Reader) io.Reader) error { - for len(fields) > 0 { - var err error - if fields, err = c.parseField(fields, charsetReader); err != nil { - return err - } - } - return nil -} - -// Format formats search criteria to fields. UTF-8 is used. -func (c *SearchCriteria) Format() []interface{} { - var fields []interface{} - - if c.SeqNum != nil { - fields = append(fields, c.SeqNum) - } - if c.Uid != nil { - fields = append(fields, RawString("UID"), c.Uid) - } - - if !c.Since.IsZero() && !c.Before.IsZero() && c.Before.Sub(c.Since) == 24*time.Hour { - fields = append(fields, RawString("ON"), searchDate(c.Since)) - } else { - if !c.Since.IsZero() { - fields = append(fields, RawString("SINCE"), searchDate(c.Since)) - } - if !c.Before.IsZero() { - fields = append(fields, RawString("BEFORE"), searchDate(c.Before)) - } - } - if !c.SentSince.IsZero() && !c.SentBefore.IsZero() && c.SentBefore.Sub(c.SentSince) == 24*time.Hour { - fields = append(fields, RawString("SENTON"), searchDate(c.SentSince)) - } else { - if !c.SentSince.IsZero() { - fields = append(fields, RawString("SENTSINCE"), searchDate(c.SentSince)) - } - if !c.SentBefore.IsZero() { - fields = append(fields, RawString("SENTBEFORE"), searchDate(c.SentBefore)) - } - } - - for key, values := range c.Header { - var prefields []interface{} - switch key { - case "Bcc", "Cc", "From", "Subject", "To": - prefields = []interface{}{RawString(strings.ToUpper(key))} - default: - prefields = []interface{}{RawString("HEADER"), key} - } - for _, value := range values { - fields = append(fields, prefields...) - fields = append(fields, value) - } - } - - for _, value := range c.Body { - fields = append(fields, RawString("BODY"), value) - } - for _, value := range c.Text { - fields = append(fields, RawString("TEXT"), value) - } - - for _, flag := range c.WithFlags { - var subfields []interface{} - switch flag { - case AnsweredFlag, DeletedFlag, DraftFlag, FlaggedFlag, RecentFlag, SeenFlag: - subfields = []interface{}{RawString(strings.ToUpper(strings.TrimPrefix(flag, "\\")))} - default: - subfields = []interface{}{RawString("KEYWORD"), RawString(flag)} - } - fields = append(fields, subfields...) - } - for _, flag := range c.WithoutFlags { - var subfields []interface{} - switch flag { - case AnsweredFlag, DeletedFlag, DraftFlag, FlaggedFlag, SeenFlag: - subfields = []interface{}{RawString("UN" + strings.ToUpper(strings.TrimPrefix(flag, "\\")))} - case RecentFlag: - subfields = []interface{}{RawString("OLD")} - default: - subfields = []interface{}{RawString("UNKEYWORD"), RawString(flag)} - } - fields = append(fields, subfields...) - } - - if c.Larger > 0 { - fields = append(fields, RawString("LARGER"), c.Larger) - } - if c.Smaller > 0 { - fields = append(fields, RawString("SMALLER"), c.Smaller) - } - - for _, not := range c.Not { - fields = append(fields, RawString("NOT"), not.Format()) - } - - for _, or := range c.Or { - fields = append(fields, RawString("OR"), or[0].Format(), or[1].Format()) - } - - // Not a single criteria given, add ALL criteria as fallback - if len(fields) == 0 { - fields = append(fields, RawString("ALL")) - } - - return fields -} diff --git a/vendor/github.com/emersion/go-imap/seqset.go b/vendor/github.com/emersion/go-imap/seqset.go deleted file mode 100644 index abe6afc..0000000 --- a/vendor/github.com/emersion/go-imap/seqset.go +++ /dev/null @@ -1,289 +0,0 @@ -package imap - -import ( - "fmt" - "strconv" - "strings" -) - -// ErrBadSeqSet is used to report problems with the format of a sequence set -// value. -type ErrBadSeqSet string - -func (err ErrBadSeqSet) Error() string { - return fmt.Sprintf("imap: bad sequence set value %q", string(err)) -} - -// Seq represents a single seq-number or seq-range value (RFC 3501 ABNF). Values -// may be static (e.g. "1", "2:4") or dynamic (e.g. "*", "1:*"). A seq-number is -// represented by setting Start = Stop. Zero is used to represent "*", which is -// safe because seq-number uses nz-number rule. The order of values is always -// Start <= Stop, except when representing "n:*", where Start = n and Stop = 0. -type Seq struct { - Start, Stop uint32 -} - -// parseSeqNumber parses a single seq-number value (non-zero uint32 or "*"). -func parseSeqNumber(v string) (uint32, error) { - if n, err := strconv.ParseUint(v, 10, 32); err == nil && v[0] != '0' { - return uint32(n), nil - } else if v == "*" { - return 0, nil - } - return 0, ErrBadSeqSet(v) -} - -// parseSeq creates a new seq instance by parsing strings in the format "n" or -// "n:m", where n and/or m may be "*". An error is returned for invalid values. -func parseSeq(v string) (s Seq, err error) { - if sep := strings.IndexRune(v, ':'); sep < 0 { - s.Start, err = parseSeqNumber(v) - s.Stop = s.Start - return - } else if s.Start, err = parseSeqNumber(v[:sep]); err == nil { - if s.Stop, err = parseSeqNumber(v[sep+1:]); err == nil { - if (s.Stop < s.Start && s.Stop != 0) || s.Start == 0 { - s.Start, s.Stop = s.Stop, s.Start - } - return - } - } - return s, ErrBadSeqSet(v) -} - -// Contains returns true if the seq-number q is contained in sequence value s. -// The dynamic value "*" contains only other "*" values, the dynamic range "n:*" -// contains "*" and all numbers >= n. -func (s Seq) Contains(q uint32) bool { - if q == 0 { - return s.Stop == 0 // "*" is contained only in "*" and "n:*" - } - return s.Start != 0 && s.Start <= q && (q <= s.Stop || s.Stop == 0) -} - -// Less returns true if s precedes and does not contain seq-number q. -func (s Seq) Less(q uint32) bool { - return (s.Stop < q || q == 0) && s.Stop != 0 -} - -// Merge combines sequence values s and t into a single union if the two -// intersect or one is a superset of the other. The order of s and t does not -// matter. If the values cannot be merged, s is returned unmodified and ok is -// set to false. -func (s Seq) Merge(t Seq) (union Seq, ok bool) { - if union = s; s == t { - ok = true - return - } - if s.Start != 0 && t.Start != 0 { - // s and t are any combination of "n", "n:m", or "n:*" - if s.Start > t.Start { - s, t = t, s - } - // s starts at or before t, check where it ends - if (s.Stop >= t.Stop && t.Stop != 0) || s.Stop == 0 { - return s, true // s is a superset of t - } - // s is "n" or "n:m", if m == ^uint32(0) then t is "n:*" - if s.Stop+1 >= t.Start || s.Stop == ^uint32(0) { - return Seq{s.Start, t.Stop}, true // s intersects or touches t - } - return - } - // exactly one of s and t is "*" - if s.Start == 0 { - if t.Stop == 0 { - return t, true // s is "*", t is "n:*" - } - } else if s.Stop == 0 { - return s, true // s is "n:*", t is "*" - } - return -} - -// String returns sequence value s as a seq-number or seq-range string. -func (s Seq) String() string { - if s.Start == s.Stop { - if s.Start == 0 { - return "*" - } - return strconv.FormatUint(uint64(s.Start), 10) - } - b := strconv.AppendUint(make([]byte, 0, 24), uint64(s.Start), 10) - if s.Stop == 0 { - return string(append(b, ':', '*')) - } - return string(strconv.AppendUint(append(b, ':'), uint64(s.Stop), 10)) -} - -// SeqSet is used to represent a set of message sequence numbers or UIDs (see -// sequence-set ABNF rule). The zero value is an empty set. -type SeqSet struct { - Set []Seq -} - -// ParseSeqSet returns a new SeqSet instance after parsing the set string. -func ParseSeqSet(set string) (s *SeqSet, err error) { - s = new(SeqSet) - return s, s.Add(set) -} - -// Add inserts new sequence values into the set. The string format is described -// by RFC 3501 sequence-set ABNF rule. If an error is encountered, all values -// inserted successfully prior to the error remain in the set. -func (s *SeqSet) Add(set string) error { - for _, sv := range strings.Split(set, ",") { - v, err := parseSeq(sv) - if err != nil { - return err - } - s.insert(v) - } - return nil -} - -// AddNum inserts new sequence numbers into the set. The value 0 represents "*". -func (s *SeqSet) AddNum(q ...uint32) { - for _, v := range q { - s.insert(Seq{v, v}) - } -} - -// AddRange inserts a new sequence range into the set. -func (s *SeqSet) AddRange(Start, Stop uint32) { - if (Stop < Start && Stop != 0) || Start == 0 { - s.insert(Seq{Stop, Start}) - } else { - s.insert(Seq{Start, Stop}) - } -} - -// AddSet inserts all values from t into s. -func (s *SeqSet) AddSet(t *SeqSet) { - for _, v := range t.Set { - s.insert(v) - } -} - -// Clear removes all values from the set. -func (s *SeqSet) Clear() { - s.Set = s.Set[:0] -} - -// Empty returns true if the sequence set does not contain any values. -func (s SeqSet) Empty() bool { - return len(s.Set) == 0 -} - -// Dynamic returns true if the set contains "*" or "n:*" values. -func (s SeqSet) Dynamic() bool { - return len(s.Set) > 0 && s.Set[len(s.Set)-1].Stop == 0 -} - -// Contains returns true if the non-zero sequence number or UID q is contained -// in the set. The dynamic range "n:*" contains all q >= n. It is the caller's -// responsibility to handle the special case where q is the maximum UID in the -// mailbox and q < n (i.e. the set cannot match UIDs against "*:n" or "*" since -// it doesn't know what the maximum value is). -func (s SeqSet) Contains(q uint32) bool { - if _, ok := s.search(q); ok { - return q != 0 - } - return false -} - -// String returns a sorted representation of all contained sequence values. -func (s SeqSet) String() string { - if len(s.Set) == 0 { - return "" - } - b := make([]byte, 0, 64) - for _, v := range s.Set { - b = append(b, ',') - if v.Start == 0 { - b = append(b, '*') - continue - } - b = strconv.AppendUint(b, uint64(v.Start), 10) - if v.Start != v.Stop { - if v.Stop == 0 { - b = append(b, ':', '*') - continue - } - b = strconv.AppendUint(append(b, ':'), uint64(v.Stop), 10) - } - } - return string(b[1:]) -} - -// insert adds sequence value v to the set. -func (s *SeqSet) insert(v Seq) { - i, _ := s.search(v.Start) - merged := false - if i > 0 { - // try merging with the preceding entry (e.g. "1,4".insert(2), i == 1) - s.Set[i-1], merged = s.Set[i-1].Merge(v) - } - if i == len(s.Set) { - // v was either merged with the last entry or needs to be appended - if !merged { - s.insertAt(i, v) - } - return - } else if merged { - i-- - } else if s.Set[i], merged = s.Set[i].Merge(v); !merged { - s.insertAt(i, v) // insert in the middle (e.g. "1,5".insert(3), i == 1) - return - } - // v was merged with s.Set[i], continue trying to merge until the end - for j := i + 1; j < len(s.Set); j++ { - if s.Set[i], merged = s.Set[i].Merge(s.Set[j]); !merged { - if j > i+1 { - // cut out all entries between i and j that were merged - s.Set = append(s.Set[:i+1], s.Set[j:]...) - } - return - } - } - // everything after s.Set[i] was merged - s.Set = s.Set[:i+1] -} - -// insertAt inserts a new sequence value v at index i, resizing s.Set as needed. -func (s *SeqSet) insertAt(i int, v Seq) { - if n := len(s.Set); i == n { - // insert at the end - s.Set = append(s.Set, v) - return - } else if n < cap(s.Set) { - // enough space, shift everything at and after i to the right - s.Set = s.Set[:n+1] - copy(s.Set[i+1:], s.Set[i:]) - } else { - // allocate new slice and copy everything, n is at least 1 - set := make([]Seq, n+1, n*2) - copy(set, s.Set[:i]) - copy(set[i+1:], s.Set[i:]) - s.Set = set - } - s.Set[i] = v -} - -// search attempts to find the index of the sequence set value that contains q. -// If no values contain q, the returned index is the position where q should be -// inserted and ok is set to false. -func (s SeqSet) search(q uint32) (i int, ok bool) { - min, max := 0, len(s.Set)-1 - for min < max { - if mid := (min + max) >> 1; s.Set[mid].Less(q) { - min = mid + 1 - } else { - max = mid - } - } - if max < 0 || s.Set[min].Less(q) { - return len(s.Set), false // q is the new largest value - } - return min, s.Set[min].Contains(q) -} diff --git a/vendor/github.com/emersion/go-imap/status.go b/vendor/github.com/emersion/go-imap/status.go deleted file mode 100644 index 81ffd1b..0000000 --- a/vendor/github.com/emersion/go-imap/status.go +++ /dev/null @@ -1,136 +0,0 @@ -package imap - -import ( - "errors" -) - -// A status response type. -type StatusRespType string - -// Status response types defined in RFC 3501 section 7.1. -const ( - // The OK response indicates an information message from the server. When - // tagged, it indicates successful completion of the associated command. - // The untagged form indicates an information-only message. - StatusRespOk StatusRespType = "OK" - - // The NO response indicates an operational error message from the - // server. When tagged, it indicates unsuccessful completion of the - // associated command. The untagged form indicates a warning; the - // command can still complete successfully. - StatusRespNo StatusRespType = "NO" - - // The BAD response indicates an error message from the server. When - // tagged, it reports a protocol-level error in the client's command; - // the tag indicates the command that caused the error. The untagged - // form indicates a protocol-level error for which the associated - // command can not be determined; it can also indicate an internal - // server failure. - StatusRespBad StatusRespType = "BAD" - - // The PREAUTH response is always untagged, and is one of three - // possible greetings at connection startup. It indicates that the - // connection has already been authenticated by external means; thus - // no LOGIN command is needed. - StatusRespPreauth StatusRespType = "PREAUTH" - - // The BYE response is always untagged, and indicates that the server - // is about to close the connection. - StatusRespBye StatusRespType = "BYE" -) - -type StatusRespCode string - -// Status response codes defined in RFC 3501 section 7.1. -const ( - CodeAlert StatusRespCode = "ALERT" - CodeBadCharset StatusRespCode = "BADCHARSET" - CodeCapability StatusRespCode = "CAPABILITY" - CodeParse StatusRespCode = "PARSE" - CodePermanentFlags StatusRespCode = "PERMANENTFLAGS" - CodeReadOnly StatusRespCode = "READ-ONLY" - CodeReadWrite StatusRespCode = "READ-WRITE" - CodeTryCreate StatusRespCode = "TRYCREATE" - CodeUidNext StatusRespCode = "UIDNEXT" - CodeUidValidity StatusRespCode = "UIDVALIDITY" - CodeUnseen StatusRespCode = "UNSEEN" -) - -// A status response. -// See RFC 3501 section 7.1 -type StatusResp struct { - // The response tag. If empty, it defaults to *. - Tag string - // The status type. - Type StatusRespType - // The status code. - // See https://www.iana.org/assignments/imap-response-codes/imap-response-codes.xhtml - Code StatusRespCode - // Arguments provided with the status code. - Arguments []interface{} - // The status info. - Info string -} - -func (r *StatusResp) resp() {} - -// If this status is NO or BAD, returns an error with the status info. -// Otherwise, returns nil. -func (r *StatusResp) Err() error { - if r == nil { - // No status response, connection closed before we get one - return errors.New("imap: connection closed during command execution") - } - - if r.Type == StatusRespNo || r.Type == StatusRespBad { - return errors.New(r.Info) - } - return nil -} - -func (r *StatusResp) WriteTo(w *Writer) error { - tag := RawString(r.Tag) - if tag == "" { - tag = "*" - } - - if err := w.writeFields([]interface{}{RawString(tag), RawString(r.Type)}); err != nil { - return err - } - - if err := w.writeString(string(sp)); err != nil { - return err - } - - if r.Code != "" { - if err := w.writeRespCode(r.Code, r.Arguments); err != nil { - return err - } - - if err := w.writeString(string(sp)); err != nil { - return err - } - } - - if err := w.writeString(r.Info); err != nil { - return err - } - - return w.writeCrlf() -} - -// ErrStatusResp can be returned by a server.Handler to replace the default status -// response. The response tag must be empty. -// -// To suppress default response, Resp should be set to nil. -type ErrStatusResp struct { - // Response to send instead of default. - Resp *StatusResp -} - -func (err *ErrStatusResp) Error() string { - if err.Resp == nil { - return "imap: suppressed response" - } - return err.Resp.Info -} diff --git a/vendor/github.com/emersion/go-imap/utf7/decoder.go b/vendor/github.com/emersion/go-imap/utf7/decoder.go deleted file mode 100644 index cfcba8c..0000000 --- a/vendor/github.com/emersion/go-imap/utf7/decoder.go +++ /dev/null @@ -1,149 +0,0 @@ -package utf7 - -import ( - "errors" - "unicode/utf16" - "unicode/utf8" - - "golang.org/x/text/transform" -) - -// ErrInvalidUTF7 means that a transformer encountered invalid UTF-7. -var ErrInvalidUTF7 = errors.New("utf7: invalid UTF-7") - -type decoder struct { - ascii bool -} - -func (d *decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - for i := 0; i < len(src); i++ { - ch := src[i] - - if ch < min || ch > max { // Illegal code point in ASCII mode - err = ErrInvalidUTF7 - return - } - - if ch != '&' { - if nDst+1 > len(dst) { - err = transform.ErrShortDst - return - } - - nSrc++ - - dst[nDst] = ch - nDst++ - - d.ascii = true - continue - } - - // Find the end of the Base64 or "&-" segment - start := i + 1 - for i++; i < len(src) && src[i] != '-'; i++ { - if src[i] == '\r' || src[i] == '\n' { // base64 package ignores CR and LF - err = ErrInvalidUTF7 - return - } - } - - if i == len(src) { // Implicit shift ("&...") - if atEOF { - err = ErrInvalidUTF7 - } else { - err = transform.ErrShortSrc - } - return - } - - var b []byte - if i == start { // Escape sequence "&-" - b = []byte{'&'} - d.ascii = true - } else { // Control or non-ASCII code points in base64 - if !d.ascii { // Null shift ("&...-&...-") - err = ErrInvalidUTF7 - return - } - - b = decode(src[start:i]) - d.ascii = false - } - - if len(b) == 0 { // Bad encoding - err = ErrInvalidUTF7 - return - } - - if nDst+len(b) > len(dst) { - d.ascii = true - err = transform.ErrShortDst - return - } - - nSrc = i + 1 - - for _, ch := range b { - dst[nDst] = ch - nDst++ - } - } - - if atEOF { - d.ascii = true - } - - return -} - -func (d *decoder) Reset() { - d.ascii = true -} - -// Extracts UTF-16-BE bytes from base64 data and converts them to UTF-8. -// A nil slice is returned if the encoding is invalid. -func decode(b64 []byte) []byte { - var b []byte - - // Allocate a single block of memory large enough to store the Base64 data - // (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes. - // Since a 2-byte UTF-16 sequence may expand into a 3-byte UTF-8 sequence, - // double the space allocation for UTF-8. - if n := len(b64); b64[n-1] == '=' { - return nil - } else if n&3 == 0 { - b = make([]byte, b64Enc.DecodedLen(n)*3) - } else { - n += 4 - n&3 - b = make([]byte, n+b64Enc.DecodedLen(n)*3) - copy(b[copy(b, b64):n], []byte("==")) - b64, b = b[:n], b[n:] - } - - // Decode Base64 into the first 1/3rd of b - n, err := b64Enc.Decode(b, b64) - if err != nil || n&1 == 1 { - return nil - } - - // Decode UTF-16-BE into the remaining 2/3rds of b - b, s := b[:n], b[n:] - j := 0 - for i := 0; i < n; i += 2 { - r := rune(b[i])<<8 | rune(b[i+1]) - if utf16.IsSurrogate(r) { - if i += 2; i == n { - return nil - } - r2 := rune(b[i])<<8 | rune(b[i+1]) - if r = utf16.DecodeRune(r, r2); r == repl { - return nil - } - } else if min <= r && r <= max { - return nil - } - j += utf8.EncodeRune(s[j:], r) - } - return s[:j] -} diff --git a/vendor/github.com/emersion/go-imap/utf7/encoder.go b/vendor/github.com/emersion/go-imap/utf7/encoder.go deleted file mode 100644 index 8414d10..0000000 --- a/vendor/github.com/emersion/go-imap/utf7/encoder.go +++ /dev/null @@ -1,91 +0,0 @@ -package utf7 - -import ( - "unicode/utf16" - "unicode/utf8" - - "golang.org/x/text/transform" -) - -type encoder struct{} - -func (e *encoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - for i := 0; i < len(src); { - ch := src[i] - - var b []byte - if min <= ch && ch <= max { - b = []byte{ch} - if ch == '&' { - b = append(b, '-') - } - - i++ - } else { - start := i - - // Find the next printable ASCII code point - i++ - for i < len(src) && (src[i] < min || src[i] > max) { - i++ - } - - if !atEOF && i == len(src) { - err = transform.ErrShortSrc - return - } - - b = encode(src[start:i]) - } - - if nDst+len(b) > len(dst) { - err = transform.ErrShortDst - return - } - - nSrc = i - - for _, ch := range b { - dst[nDst] = ch - nDst++ - } - } - - return -} - -func (e *encoder) Reset() {} - -// Converts string s from UTF-8 to UTF-16-BE, encodes the result as base64, -// removes the padding, and adds UTF-7 shifts. -func encode(s []byte) []byte { - // len(s) is sufficient for UTF-8 to UTF-16 conversion if there are no - // control code points (see table below). - b := make([]byte, 0, len(s)+4) - for len(s) > 0 { - r, size := utf8.DecodeRune(s) - if r > utf8.MaxRune { - r, size = utf8.RuneError, 1 // Bug fix (issue 3785) - } - s = s[size:] - if r1, r2 := utf16.EncodeRune(r); r1 != repl { - b = append(b, byte(r1>>8), byte(r1)) - r = r2 - } - b = append(b, byte(r>>8), byte(r)) - } - - // Encode as base64 - n := b64Enc.EncodedLen(len(b)) + 2 - b64 := make([]byte, n) - b64Enc.Encode(b64[1:], b) - - // Strip padding - n -= 2 - (len(b)+2)%3 - b64 = b64[:n] - - // Add UTF-7 shifts - b64[0] = '&' - b64[n-1] = '-' - return b64 -} diff --git a/vendor/github.com/emersion/go-imap/utf7/utf7.go b/vendor/github.com/emersion/go-imap/utf7/utf7.go deleted file mode 100644 index b9dd962..0000000 --- a/vendor/github.com/emersion/go-imap/utf7/utf7.go +++ /dev/null @@ -1,34 +0,0 @@ -// Package utf7 implements modified UTF-7 encoding defined in RFC 3501 section 5.1.3 -package utf7 - -import ( - "encoding/base64" - - "golang.org/x/text/encoding" -) - -const ( - min = 0x20 // Minimum self-representing UTF-7 value - max = 0x7E // Maximum self-representing UTF-7 value - - repl = '\uFFFD' // Unicode replacement code point -) - -var b64Enc = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,") - -type enc struct{} - -func (e enc) NewDecoder() *encoding.Decoder { - return &encoding.Decoder{ - Transformer: &decoder{true}, - } -} - -func (e enc) NewEncoder() *encoding.Encoder { - return &encoding.Encoder{ - Transformer: &encoder{}, - } -} - -// Encoding is the modified UTF-7 encoding. -var Encoding encoding.Encoding = enc{} diff --git a/vendor/github.com/emersion/go-imap/write.go b/vendor/github.com/emersion/go-imap/write.go deleted file mode 100644 index c295e4e..0000000 --- a/vendor/github.com/emersion/go-imap/write.go +++ /dev/null @@ -1,255 +0,0 @@ -package imap - -import ( - "bytes" - "fmt" - "io" - "io/ioutil" - "strconv" - "time" - "unicode" -) - -type flusher interface { - Flush() error -} - -type ( - // A raw string. - RawString string -) - -type WriterTo interface { - WriteTo(w *Writer) error -} - -func formatNumber(num uint32) string { - return strconv.FormatUint(uint64(num), 10) -} - -// Convert a string list to a field list. -func FormatStringList(list []string) (fields []interface{}) { - fields = make([]interface{}, len(list)) - for i, v := range list { - fields[i] = v - } - return -} - -// Check if a string is 8-bit clean. -func isAscii(s string) bool { - for _, c := range s { - if c > unicode.MaxASCII || unicode.IsControl(c) { - return false - } - } - return true -} - -// An IMAP writer. -type Writer struct { - io.Writer - - AllowAsyncLiterals bool - - continues <-chan bool -} - -// Helper function to write a string to w. -func (w *Writer) writeString(s string) error { - _, err := io.WriteString(w.Writer, s) - return err -} - -func (w *Writer) writeCrlf() error { - if err := w.writeString(crlf); err != nil { - return err - } - - return w.Flush() -} - -func (w *Writer) writeNumber(num uint32) error { - return w.writeString(formatNumber(num)) -} - -func (w *Writer) writeQuoted(s string) error { - return w.writeString(strconv.Quote(s)) -} - -func (w *Writer) writeQuotedOrLiteral(s string) error { - if !isAscii(s) { - // IMAP doesn't allow 8-bit data outside literals - return w.writeLiteral(bytes.NewBufferString(s)) - } - - return w.writeQuoted(s) -} - -func (w *Writer) writeDateTime(t time.Time, layout string) error { - if t.IsZero() { - return w.writeString(nilAtom) - } - return w.writeQuoted(t.Format(layout)) -} - -func (w *Writer) writeFields(fields []interface{}) error { - for i, field := range fields { - if i > 0 { // Write separator - if err := w.writeString(string(sp)); err != nil { - return err - } - } - - if err := w.writeField(field); err != nil { - return err - } - } - - return nil -} - -func (w *Writer) writeList(fields []interface{}) error { - if err := w.writeString(string(listStart)); err != nil { - return err - } - - if err := w.writeFields(fields); err != nil { - return err - } - - return w.writeString(string(listEnd)) -} - -// LiteralLengthErr is returned when the Len() of the Literal object does not -// match the actual length of the byte stream. -type LiteralLengthErr struct { - Actual int - Expected int -} - -func (e LiteralLengthErr) Error() string { - return fmt.Sprintf("imap: size of Literal is not equal to Len() (%d != %d)", e.Expected, e.Actual) -} - -func (w *Writer) writeLiteral(l Literal) error { - if l == nil { - return w.writeString(nilAtom) - } - - unsyncLiteral := w.AllowAsyncLiterals && l.Len() <= 4096 - - header := string(literalStart) + strconv.Itoa(l.Len()) - if unsyncLiteral { - header += string('+') - } - header += string(literalEnd) + crlf - if err := w.writeString(header); err != nil { - return err - } - - // If a channel is available, wait for a continuation request before sending data - if !unsyncLiteral && w.continues != nil { - // Make sure to flush the writer, otherwise we may never receive a continuation request - if err := w.Flush(); err != nil { - return err - } - - if !<-w.continues { - return fmt.Errorf("imap: cannot send literal: no continuation request received") - } - } - - // In case of bufio.Buffer, it will be 0 after io.Copy. - literalLen := int64(l.Len()) - - n, err := io.CopyN(w, l, literalLen) - if err != nil { - if err == io.EOF && n != literalLen { - return LiteralLengthErr{int(n), l.Len()} - } - return err - } - extra, _ := io.Copy(ioutil.Discard, l) - if extra != 0 { - return LiteralLengthErr{int(n + extra), l.Len()} - } - - return nil -} - -func (w *Writer) writeField(field interface{}) error { - if field == nil { - return w.writeString(nilAtom) - } - - switch field := field.(type) { - case RawString: - return w.writeString(string(field)) - case string: - return w.writeQuotedOrLiteral(field) - case int: - return w.writeNumber(uint32(field)) - case uint32: - return w.writeNumber(field) - case Literal: - return w.writeLiteral(field) - case []interface{}: - return w.writeList(field) - case envelopeDateTime: - return w.writeDateTime(time.Time(field), envelopeDateTimeLayout) - case searchDate: - return w.writeDateTime(time.Time(field), searchDateLayout) - case Date: - return w.writeDateTime(time.Time(field), DateLayout) - case DateTime: - return w.writeDateTime(time.Time(field), DateTimeLayout) - case time.Time: - return w.writeDateTime(field, DateTimeLayout) - case *SeqSet: - return w.writeString(field.String()) - case *BodySectionName: - // Can contain spaces - that's why we don't just pass it as a string - return w.writeString(string(field.FetchItem())) - } - - return fmt.Errorf("imap: cannot format field: %v", field) -} - -func (w *Writer) writeRespCode(code StatusRespCode, args []interface{}) error { - if err := w.writeString(string(respCodeStart)); err != nil { - return err - } - - fields := []interface{}{RawString(code)} - fields = append(fields, args...) - - if err := w.writeFields(fields); err != nil { - return err - } - - return w.writeString(string(respCodeEnd)) -} - -func (w *Writer) writeLine(fields ...interface{}) error { - if err := w.writeFields(fields); err != nil { - return err - } - - return w.writeCrlf() -} - -func (w *Writer) Flush() error { - if f, ok := w.Writer.(flusher); ok { - return f.Flush() - } - return nil -} - -func NewWriter(w io.Writer) *Writer { - return &Writer{Writer: w} -} - -func NewClientWriter(w io.Writer, continues <-chan bool) *Writer { - return &Writer{Writer: w, continues: continues} -} diff --git a/vendor/github.com/emersion/go-sasl/.build.yml b/vendor/github.com/emersion/go-sasl/.build.yml deleted file mode 100644 index daa6006..0000000 --- a/vendor/github.com/emersion/go-sasl/.build.yml +++ /dev/null @@ -1,19 +0,0 @@ -image: alpine/latest -packages: - - go - # Required by codecov - - bash - - findutils -sources: - - https://github.com/emersion/go-sasl -tasks: - - build: | - cd go-sasl - go build -v ./... - - test: | - cd go-sasl - go test -coverprofile=coverage.txt -covermode=atomic ./... - - upload-coverage: | - cd go-sasl - export CODECOV_TOKEN=3f257f71-a128-4834-8f68-2b534e9f4cb1 - curl -s https://codecov.io/bash | bash diff --git a/vendor/github.com/emersion/go-sasl/.gitignore b/vendor/github.com/emersion/go-sasl/.gitignore deleted file mode 100644 index daf913b..0000000 --- a/vendor/github.com/emersion/go-sasl/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof diff --git a/vendor/github.com/emersion/go-sasl/LICENSE b/vendor/github.com/emersion/go-sasl/LICENSE deleted file mode 100644 index dc1922e..0000000 --- a/vendor/github.com/emersion/go-sasl/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 emersion - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/emersion/go-sasl/README.md b/vendor/github.com/emersion/go-sasl/README.md deleted file mode 100644 index 1f8a682..0000000 --- a/vendor/github.com/emersion/go-sasl/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# go-sasl - -[![GoDoc](https://godoc.org/github.com/emersion/go-sasl?status.svg)](https://godoc.org/github.com/emersion/go-sasl) -[![Build Status](https://travis-ci.org/emersion/go-sasl.svg?branch=master)](https://travis-ci.org/emersion/go-sasl) - -A [SASL](https://tools.ietf.org/html/rfc4422) library written in Go. - -Implemented mechanisms: -* [ANONYMOUS](https://tools.ietf.org/html/rfc4505) -* [EXTERNAL](https://tools.ietf.org/html/rfc4422#appendix-A) -* [LOGIN](https://tools.ietf.org/html/draft-murchison-sasl-login-00) (obsolete, use PLAIN instead) -* [PLAIN](https://tools.ietf.org/html/rfc4616) -* [OAUTHBEARER](https://tools.ietf.org/html/rfc7628) - -## License - -MIT diff --git a/vendor/github.com/emersion/go-sasl/anonymous.go b/vendor/github.com/emersion/go-sasl/anonymous.go deleted file mode 100644 index 8ccb817..0000000 --- a/vendor/github.com/emersion/go-sasl/anonymous.go +++ /dev/null @@ -1,56 +0,0 @@ -package sasl - -// The ANONYMOUS mechanism name. -const Anonymous = "ANONYMOUS" - -type anonymousClient struct { - Trace string -} - -func (c *anonymousClient) Start() (mech string, ir []byte, err error) { - mech = Anonymous - ir = []byte(c.Trace) - return -} - -func (c *anonymousClient) Next(challenge []byte) (response []byte, err error) { - return nil, ErrUnexpectedServerChallenge -} - -// A client implementation of the ANONYMOUS authentication mechanism, as -// described in RFC 4505. -func NewAnonymousClient(trace string) Client { - return &anonymousClient{trace} -} - -// Get trace information from clients logging in anonymously. -type AnonymousAuthenticator func(trace string) error - -type anonymousServer struct { - done bool - authenticate AnonymousAuthenticator -} - -func (s *anonymousServer) Next(response []byte) (challenge []byte, done bool, err error) { - if s.done { - err = ErrUnexpectedClientResponse - return - } - - // No initial response, send an empty challenge - if response == nil { - return []byte{}, false, nil - } - - s.done = true - - err = s.authenticate(string(response)) - done = true - return -} - -// A server implementation of the ANONYMOUS authentication mechanism, as -// described in RFC 4505. -func NewAnonymousServer(authenticator AnonymousAuthenticator) Server { - return &anonymousServer{authenticate: authenticator} -} diff --git a/vendor/github.com/emersion/go-sasl/external.go b/vendor/github.com/emersion/go-sasl/external.go deleted file mode 100644 index da070c8..0000000 --- a/vendor/github.com/emersion/go-sasl/external.go +++ /dev/null @@ -1,26 +0,0 @@ -package sasl - -// The EXTERNAL mechanism name. -const External = "EXTERNAL" - -type externalClient struct { - Identity string -} - -func (a *externalClient) Start() (mech string, ir []byte, err error) { - mech = External - ir = []byte(a.Identity) - return -} - -func (a *externalClient) Next(challenge []byte) (response []byte, err error) { - return nil, ErrUnexpectedServerChallenge -} - -// An implementation of the EXTERNAL authentication mechanism, as described in -// RFC 4422. Authorization identity may be left blank to indicate that the -// client is requesting to act as the identity associated with the -// authentication credentials. -func NewExternalClient(identity string) Client { - return &externalClient{identity} -} diff --git a/vendor/github.com/emersion/go-sasl/login.go b/vendor/github.com/emersion/go-sasl/login.go deleted file mode 100644 index 3847ee1..0000000 --- a/vendor/github.com/emersion/go-sasl/login.go +++ /dev/null @@ -1,89 +0,0 @@ -package sasl - -import ( - "bytes" -) - -// The LOGIN mechanism name. -const Login = "LOGIN" - -var expectedChallenge = []byte("Password:") - -type loginClient struct { - Username string - Password string -} - -func (a *loginClient) Start() (mech string, ir []byte, err error) { - mech = "LOGIN" - ir = []byte(a.Username) - return -} - -func (a *loginClient) Next(challenge []byte) (response []byte, err error) { - if bytes.Compare(challenge, expectedChallenge) != 0 { - return nil, ErrUnexpectedServerChallenge - } else { - return []byte(a.Password), nil - } -} - -// A client implementation of the LOGIN authentication mechanism for SMTP, -// as described in http://www.iana.org/go/draft-murchison-sasl-login -// -// It is considered obsolete, and should not be used when other mechanisms are -// available. For plaintext password authentication use PLAIN mechanism. -func NewLoginClient(username, password string) Client { - return &loginClient{username, password} -} - -// Authenticates users with an username and a password. -type LoginAuthenticator func(username, password string) error - -type loginState int - -const ( - loginNotStarted loginState = iota - loginWaitingUsername - loginWaitingPassword -) - -type loginServer struct { - state loginState - username, password string - authenticate LoginAuthenticator -} - -// A server implementation of the LOGIN authentication mechanism, as described -// in https://tools.ietf.org/html/draft-murchison-sasl-login-00. -// -// LOGIN is obsolete and should only be enabled for legacy clients that cannot -// be updated to use PLAIN. -func NewLoginServer(authenticator LoginAuthenticator) Server { - return &loginServer{authenticate: authenticator} -} - -func (a *loginServer) Next(response []byte) (challenge []byte, done bool, err error) { - switch a.state { - case loginNotStarted: - // Check for initial response field, as per RFC4422 section 3 - if response == nil { - challenge = []byte("Username:") - break - } - a.state++ - fallthrough - case loginWaitingUsername: - a.username = string(response) - challenge = []byte("Password:") - case loginWaitingPassword: - a.password = string(response) - err = a.authenticate(a.username, a.password) - done = true - default: - err = ErrUnexpectedClientResponse - } - - a.state++ - return -} diff --git a/vendor/github.com/emersion/go-sasl/oauthbearer.go b/vendor/github.com/emersion/go-sasl/oauthbearer.go deleted file mode 100644 index a0639b1..0000000 --- a/vendor/github.com/emersion/go-sasl/oauthbearer.go +++ /dev/null @@ -1,191 +0,0 @@ -package sasl - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "strconv" - "strings" -) - -// The OAUTHBEARER mechanism name. -const OAuthBearer = "OAUTHBEARER" - -type OAuthBearerError struct { - Status string `json:"status"` - Schemes string `json:"schemes"` - Scope string `json:"scope"` -} - -type OAuthBearerOptions struct { - Username string - Token string - Host string - Port int -} - -// Implements error -func (err *OAuthBearerError) Error() string { - return fmt.Sprintf("OAUTHBEARER authentication error (%v)", err.Status) -} - -type oauthBearerClient struct { - OAuthBearerOptions -} - -func (a *oauthBearerClient) Start() (mech string, ir []byte, err error) { - mech = OAuthBearer - var str = "n,a=" + a.Username + "," - - if a.Host != "" { - str += "\x01host=" + a.Host - } - - if a.Port != 0 { - str += "\x01port=" + strconv.Itoa(a.Port) - } - str += "\x01auth=Bearer " + a.Token + "\x01\x01" - ir = []byte(str) - return -} - -func (a *oauthBearerClient) Next(challenge []byte) ([]byte, error) { - authBearerErr := &OAuthBearerError{} - if err := json.Unmarshal(challenge, authBearerErr); err != nil { - return nil, err - } else { - return nil, authBearerErr - } -} - -// An implementation of the OAUTHBEARER authentication mechanism, as -// described in RFC 7628. -func NewOAuthBearerClient(opt *OAuthBearerOptions) Client { - return &oauthBearerClient{*opt} -} - -type OAuthBearerAuthenticator func(opts OAuthBearerOptions) *OAuthBearerError - -type oauthBearerServer struct { - done bool - failErr error - authenticate OAuthBearerAuthenticator -} - -func (a *oauthBearerServer) fail(descr string) ([]byte, bool, error) { - blob, err := json.Marshal(OAuthBearerError{ - Status: "invalid_request", - Schemes: "bearer", - }) - if err != nil { - panic(err) // wtf - } - a.failErr = errors.New(descr) - return blob, false, nil -} - -func (a *oauthBearerServer) Next(response []byte) (challenge []byte, done bool, err error) { - // Per RFC, we cannot just send an error, we need to return JSON-structured - // value as a challenge and then after getting dummy response from the - // client stop the exchange. - if a.failErr != nil { - // Server libraries (go-smtp, go-imap) will not call Next on - // protocol-specific SASL cancel response ('*'). However, GS2 (and - // indirectly OAUTHBEARER) defines a protocol-independent way to do so - // using 0x01. - if len(response) != 1 && response[0] != 0x01 { - return nil, true, errors.New("unexpected response") - } - return nil, true, a.failErr - } - - if a.done { - err = ErrUnexpectedClientResponse - return - } - - // Generate empty challenge. - if response == nil { - return []byte{}, false, nil - } - - a.done = true - - // Cut n,a=username,\x01host=...\x01auth=... - // into - // n - // a=username - // \x01host=...\x01auth=...\x01\x01 - parts := bytes.SplitN(response, []byte{','}, 3) - if len(parts) != 3 { - return a.fail("Invalid response") - } - if !bytes.Equal(parts[0], []byte{'n'}) { - return a.fail("Invalid response, missing 'n'") - } - opts := OAuthBearerOptions{} - if !bytes.HasPrefix(parts[1], []byte("a=")) { - return a.fail("Invalid response, missing 'a'") - } - opts.Username = string(bytes.TrimPrefix(parts[1], []byte("a="))) - - // Cut \x01host=...\x01auth=...\x01\x01 - // into - // *empty* - // host=... - // auth=... - // *empty* - // - // Note that this code does not do a lot of checks to make sure the input - // follows the exact format specified by RFC. - params := bytes.Split(parts[2], []byte{0x01}) - for _, p := range params { - // Skip empty fields (one at start and end). - if len(p) == 0 { - continue - } - - pParts := bytes.SplitN(p, []byte{'='}, 2) - if len(pParts) != 2 { - return a.fail("Invalid response, missing '='") - } - - switch string(pParts[0]) { - case "host": - opts.Host = string(pParts[1]) - case "port": - port, err := strconv.ParseUint(string(pParts[1]), 10, 16) - if err != nil { - return a.fail("Invalid response, malformed 'port' value") - } - opts.Port = int(port) - case "auth": - const prefix = "bearer " - strValue := string(pParts[1]) - // Token type is case-insensitive. - if !strings.HasPrefix(strings.ToLower(strValue), prefix) { - return a.fail("Unsupported token type") - } - opts.Token = strValue[len(prefix):] - default: - return a.fail("Invalid response, unknown parameter: " + string(pParts[0])) - } - } - - authzErr := a.authenticate(opts) - if authzErr != nil { - blob, err := json.Marshal(authzErr) - if err != nil { - panic(err) // wtf - } - a.failErr = authzErr - return blob, false, nil - } - - return nil, true, nil -} - -func NewOAuthBearerServer(auth OAuthBearerAuthenticator) Server { - return &oauthBearerServer{authenticate: auth} -} diff --git a/vendor/github.com/emersion/go-sasl/plain.go b/vendor/github.com/emersion/go-sasl/plain.go deleted file mode 100644 index 344ed17..0000000 --- a/vendor/github.com/emersion/go-sasl/plain.go +++ /dev/null @@ -1,77 +0,0 @@ -package sasl - -import ( - "bytes" - "errors" -) - -// The PLAIN mechanism name. -const Plain = "PLAIN" - -type plainClient struct { - Identity string - Username string - Password string -} - -func (a *plainClient) Start() (mech string, ir []byte, err error) { - mech = "PLAIN" - ir = []byte(a.Identity + "\x00" + a.Username + "\x00" + a.Password) - return -} - -func (a *plainClient) Next(challenge []byte) (response []byte, err error) { - return nil, ErrUnexpectedServerChallenge -} - -// A client implementation of the PLAIN authentication mechanism, as described -// in RFC 4616. Authorization identity may be left blank to indicate that it is -// the same as the username. -func NewPlainClient(identity, username, password string) Client { - return &plainClient{identity, username, password} -} - -// Authenticates users with an identity, a username and a password. If the -// identity is left blank, it indicates that it is the same as the username. -// If identity is not empty and the server doesn't support it, an error must be -// returned. -type PlainAuthenticator func(identity, username, password string) error - -type plainServer struct { - done bool - authenticate PlainAuthenticator -} - -func (a *plainServer) Next(response []byte) (challenge []byte, done bool, err error) { - if a.done { - err = ErrUnexpectedClientResponse - return - } - - // No initial response, send an empty challenge - if response == nil { - return []byte{}, false, nil - } - - a.done = true - - parts := bytes.Split(response, []byte("\x00")) - if len(parts) != 3 { - err = errors.New("Invalid response") - return - } - - identity := string(parts[0]) - username := string(parts[1]) - password := string(parts[2]) - - err = a.authenticate(identity, username, password) - done = true - return -} - -// A server implementation of the PLAIN authentication mechanism, as described -// in RFC 4616. -func NewPlainServer(authenticator PlainAuthenticator) Server { - return &plainServer{authenticate: authenticator} -} diff --git a/vendor/github.com/emersion/go-sasl/sasl.go b/vendor/github.com/emersion/go-sasl/sasl.go deleted file mode 100644 index c209144..0000000 --- a/vendor/github.com/emersion/go-sasl/sasl.go +++ /dev/null @@ -1,45 +0,0 @@ -// Library for Simple Authentication and Security Layer (SASL) defined in RFC 4422. -package sasl - -// Note: -// Most of this code was copied, with some modifications, from net/smtp. It -// would be better if Go provided a standard package (e.g. crypto/sasl) that -// could be shared by SMTP, IMAP, and other packages. - -import ( - "errors" -) - -// Common SASL errors. -var ( - ErrUnexpectedClientResponse = errors.New("sasl: unexpected client response") - ErrUnexpectedServerChallenge = errors.New("sasl: unexpected server challenge") -) - -// Client interface to perform challenge-response authentication. -type Client interface { - // Begins SASL authentication with the server. It returns the - // authentication mechanism name and "initial response" data (if required by - // the selected mechanism). A non-nil error causes the client to abort the - // authentication attempt. - // - // A nil ir value is different from a zero-length value. The nil value - // indicates that the selected mechanism does not use an initial response, - // while a zero-length value indicates an empty initial response, which must - // be sent to the server. - Start() (mech string, ir []byte, err error) - - // Continues challenge-response authentication. A non-nil error causes - // the client to abort the authentication attempt. - Next(challenge []byte) (response []byte, err error) -} - -// Server interface to perform challenge-response authentication. -type Server interface { - // Begins or continues challenge-response authentication. If the client - // supplies an initial response, response is non-nil. - // - // If the authentication is finished, done is set to true. If the - // authentication has failed, an error is returned. - Next(response []byte) (challenge []byte, done bool, err error) -} diff --git a/vendor/golang.org/x/text/AUTHORS b/vendor/golang.org/x/text/AUTHORS deleted file mode 100644 index 15167cd..0000000 --- a/vendor/golang.org/x/text/AUTHORS +++ /dev/null @@ -1,3 +0,0 @@ -# This source code refers to The Go Authors for copyright purposes. -# The master list of authors is in the main Go distribution, -# visible at http://tip.golang.org/AUTHORS. diff --git a/vendor/golang.org/x/text/CONTRIBUTORS b/vendor/golang.org/x/text/CONTRIBUTORS deleted file mode 100644 index 1c4577e..0000000 --- a/vendor/golang.org/x/text/CONTRIBUTORS +++ /dev/null @@ -1,3 +0,0 @@ -# This source code was written by the Go contributors. -# The master list of contributors is in the main Go distribution, -# visible at http://tip.golang.org/CONTRIBUTORS. diff --git a/vendor/golang.org/x/text/LICENSE b/vendor/golang.org/x/text/LICENSE deleted file mode 100644 index 6a66aea..0000000 --- a/vendor/golang.org/x/text/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2009 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/golang.org/x/text/PATENTS b/vendor/golang.org/x/text/PATENTS deleted file mode 100644 index 7330990..0000000 --- a/vendor/golang.org/x/text/PATENTS +++ /dev/null @@ -1,22 +0,0 @@ -Additional IP Rights Grant (Patents) - -"This implementation" means the copyrightable works distributed by -Google as part of the Go project. - -Google hereby grants to You a perpetual, worldwide, non-exclusive, -no-charge, royalty-free, irrevocable (except as stated in this section) -patent license to make, have made, use, offer to sell, sell, import, -transfer and otherwise run, modify and propagate the contents of this -implementation of Go, where such license applies only to those patent -claims, both currently owned or controlled by Google and acquired in -the future, licensable by Google that are necessarily infringed by this -implementation of Go. This grant does not include claims that would be -infringed only as a consequence of further modification of this -implementation. If you or your agent or exclusive licensee institute or -order or agree to the institution of patent litigation against any -entity (including a cross-claim or counterclaim in a lawsuit) alleging -that this implementation of Go or any code incorporated within this -implementation of Go constitutes direct or contributory patent -infringement, or inducement of patent infringement, then any patent -rights granted to you under this License for this implementation of Go -shall terminate as of the date such litigation is filed. diff --git a/vendor/golang.org/x/text/encoding/encoding.go b/vendor/golang.org/x/text/encoding/encoding.go deleted file mode 100644 index a0bd7cd..0000000 --- a/vendor/golang.org/x/text/encoding/encoding.go +++ /dev/null @@ -1,335 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package encoding defines an interface for character encodings, such as Shift -// JIS and Windows 1252, that can convert to and from UTF-8. -// -// Encoding implementations are provided in other packages, such as -// golang.org/x/text/encoding/charmap and -// golang.org/x/text/encoding/japanese. -package encoding // import "golang.org/x/text/encoding" - -import ( - "errors" - "io" - "strconv" - "unicode/utf8" - - "golang.org/x/text/encoding/internal/identifier" - "golang.org/x/text/transform" -) - -// TODO: -// - There seems to be some inconsistency in when decoders return errors -// and when not. Also documentation seems to suggest they shouldn't return -// errors at all (except for UTF-16). -// - Encoders seem to rely on or at least benefit from the input being in NFC -// normal form. Perhaps add an example how users could prepare their output. - -// Encoding is a character set encoding that can be transformed to and from -// UTF-8. -type Encoding interface { - // NewDecoder returns a Decoder. - NewDecoder() *Decoder - - // NewEncoder returns an Encoder. - NewEncoder() *Encoder -} - -// A Decoder converts bytes to UTF-8. It implements transform.Transformer. -// -// Transforming source bytes that are not of that encoding will not result in an -// error per se. Each byte that cannot be transcoded will be represented in the -// output by the UTF-8 encoding of '\uFFFD', the replacement rune. -type Decoder struct { - transform.Transformer - - // This forces external creators of Decoders to use names in struct - // initializers, allowing for future extendibility without having to break - // code. - _ struct{} -} - -// Bytes converts the given encoded bytes to UTF-8. It returns the converted -// bytes or nil, err if any error occurred. -func (d *Decoder) Bytes(b []byte) ([]byte, error) { - b, _, err := transform.Bytes(d, b) - if err != nil { - return nil, err - } - return b, nil -} - -// String converts the given encoded string to UTF-8. It returns the converted -// string or "", err if any error occurred. -func (d *Decoder) String(s string) (string, error) { - s, _, err := transform.String(d, s) - if err != nil { - return "", err - } - return s, nil -} - -// Reader wraps another Reader to decode its bytes. -// -// The Decoder may not be used for any other operation as long as the returned -// Reader is in use. -func (d *Decoder) Reader(r io.Reader) io.Reader { - return transform.NewReader(r, d) -} - -// An Encoder converts bytes from UTF-8. It implements transform.Transformer. -// -// Each rune that cannot be transcoded will result in an error. In this case, -// the transform will consume all source byte up to, not including the offending -// rune. Transforming source bytes that are not valid UTF-8 will be replaced by -// `\uFFFD`. To return early with an error instead, use transform.Chain to -// preprocess the data with a UTF8Validator. -type Encoder struct { - transform.Transformer - - // This forces external creators of Encoders to use names in struct - // initializers, allowing for future extendibility without having to break - // code. - _ struct{} -} - -// Bytes converts bytes from UTF-8. It returns the converted bytes or nil, err if -// any error occurred. -func (e *Encoder) Bytes(b []byte) ([]byte, error) { - b, _, err := transform.Bytes(e, b) - if err != nil { - return nil, err - } - return b, nil -} - -// String converts a string from UTF-8. It returns the converted string or -// "", err if any error occurred. -func (e *Encoder) String(s string) (string, error) { - s, _, err := transform.String(e, s) - if err != nil { - return "", err - } - return s, nil -} - -// Writer wraps another Writer to encode its UTF-8 output. -// -// The Encoder may not be used for any other operation as long as the returned -// Writer is in use. -func (e *Encoder) Writer(w io.Writer) io.Writer { - return transform.NewWriter(w, e) -} - -// ASCIISub is the ASCII substitute character, as recommended by -// https://unicode.org/reports/tr36/#Text_Comparison -const ASCIISub = '\x1a' - -// Nop is the nop encoding. Its transformed bytes are the same as the source -// bytes; it does not replace invalid UTF-8 sequences. -var Nop Encoding = nop{} - -type nop struct{} - -func (nop) NewDecoder() *Decoder { - return &Decoder{Transformer: transform.Nop} -} -func (nop) NewEncoder() *Encoder { - return &Encoder{Transformer: transform.Nop} -} - -// Replacement is the replacement encoding. Decoding from the replacement -// encoding yields a single '\uFFFD' replacement rune. Encoding from UTF-8 to -// the replacement encoding yields the same as the source bytes except that -// invalid UTF-8 is converted to '\uFFFD'. -// -// It is defined at http://encoding.spec.whatwg.org/#replacement -var Replacement Encoding = replacement{} - -type replacement struct{} - -func (replacement) NewDecoder() *Decoder { - return &Decoder{Transformer: replacementDecoder{}} -} - -func (replacement) NewEncoder() *Encoder { - return &Encoder{Transformer: replacementEncoder{}} -} - -func (replacement) ID() (mib identifier.MIB, other string) { - return identifier.Replacement, "" -} - -type replacementDecoder struct{ transform.NopResetter } - -func (replacementDecoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - if len(dst) < 3 { - return 0, 0, transform.ErrShortDst - } - if atEOF { - const fffd = "\ufffd" - dst[0] = fffd[0] - dst[1] = fffd[1] - dst[2] = fffd[2] - nDst = 3 - } - return nDst, len(src), nil -} - -type replacementEncoder struct{ transform.NopResetter } - -func (replacementEncoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - r, size := rune(0), 0 - - for ; nSrc < len(src); nSrc += size { - r = rune(src[nSrc]) - - // Decode a 1-byte rune. - if r < utf8.RuneSelf { - size = 1 - - } else { - // Decode a multi-byte rune. - r, size = utf8.DecodeRune(src[nSrc:]) - if size == 1 { - // All valid runes of size 1 (those below utf8.RuneSelf) were - // handled above. We have invalid UTF-8 or we haven't seen the - // full character yet. - if !atEOF && !utf8.FullRune(src[nSrc:]) { - err = transform.ErrShortSrc - break - } - r = '\ufffd' - } - } - - if nDst+utf8.RuneLen(r) > len(dst) { - err = transform.ErrShortDst - break - } - nDst += utf8.EncodeRune(dst[nDst:], r) - } - return nDst, nSrc, err -} - -// HTMLEscapeUnsupported wraps encoders to replace source runes outside the -// repertoire of the destination encoding with HTML escape sequences. -// -// This wrapper exists to comply to URL and HTML forms requiring a -// non-terminating legacy encoder. The produced sequences may lead to data -// loss as they are indistinguishable from legitimate input. To avoid this -// issue, use UTF-8 encodings whenever possible. -func HTMLEscapeUnsupported(e *Encoder) *Encoder { - return &Encoder{Transformer: &errorHandler{e, errorToHTML}} -} - -// ReplaceUnsupported wraps encoders to replace source runes outside the -// repertoire of the destination encoding with an encoding-specific -// replacement. -// -// This wrapper is only provided for backwards compatibility and legacy -// handling. Its use is strongly discouraged. Use UTF-8 whenever possible. -func ReplaceUnsupported(e *Encoder) *Encoder { - return &Encoder{Transformer: &errorHandler{e, errorToReplacement}} -} - -type errorHandler struct { - *Encoder - handler func(dst []byte, r rune, err repertoireError) (n int, ok bool) -} - -// TODO: consider making this error public in some form. -type repertoireError interface { - Replacement() byte -} - -func (h errorHandler) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - nDst, nSrc, err = h.Transformer.Transform(dst, src, atEOF) - for err != nil { - rerr, ok := err.(repertoireError) - if !ok { - return nDst, nSrc, err - } - r, sz := utf8.DecodeRune(src[nSrc:]) - n, ok := h.handler(dst[nDst:], r, rerr) - if !ok { - return nDst, nSrc, transform.ErrShortDst - } - err = nil - nDst += n - if nSrc += sz; nSrc < len(src) { - var dn, sn int - dn, sn, err = h.Transformer.Transform(dst[nDst:], src[nSrc:], atEOF) - nDst += dn - nSrc += sn - } - } - return nDst, nSrc, err -} - -func errorToHTML(dst []byte, r rune, err repertoireError) (n int, ok bool) { - buf := [8]byte{} - b := strconv.AppendUint(buf[:0], uint64(r), 10) - if n = len(b) + len("&#;"); n >= len(dst) { - return 0, false - } - dst[0] = '&' - dst[1] = '#' - dst[copy(dst[2:], b)+2] = ';' - return n, true -} - -func errorToReplacement(dst []byte, r rune, err repertoireError) (n int, ok bool) { - if len(dst) == 0 { - return 0, false - } - dst[0] = err.Replacement() - return 1, true -} - -// ErrInvalidUTF8 means that a transformer encountered invalid UTF-8. -var ErrInvalidUTF8 = errors.New("encoding: invalid UTF-8") - -// UTF8Validator is a transformer that returns ErrInvalidUTF8 on the first -// input byte that is not valid UTF-8. -var UTF8Validator transform.Transformer = utf8Validator{} - -type utf8Validator struct{ transform.NopResetter } - -func (utf8Validator) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - n := len(src) - if n > len(dst) { - n = len(dst) - } - for i := 0; i < n; { - if c := src[i]; c < utf8.RuneSelf { - dst[i] = c - i++ - continue - } - _, size := utf8.DecodeRune(src[i:]) - if size == 1 { - // All valid runes of size 1 (those below utf8.RuneSelf) were - // handled above. We have invalid UTF-8 or we haven't seen the - // full character yet. - err = ErrInvalidUTF8 - if !atEOF && !utf8.FullRune(src[i:]) { - err = transform.ErrShortSrc - } - return i, i, err - } - if i+size > len(dst) { - return i, i, transform.ErrShortDst - } - for ; size > 0; size-- { - dst[i] = src[i] - i++ - } - } - if len(src) > len(dst) { - err = transform.ErrShortDst - } - return n, n, err -} diff --git a/vendor/golang.org/x/text/encoding/internal/identifier/identifier.go b/vendor/golang.org/x/text/encoding/internal/identifier/identifier.go deleted file mode 100644 index 5c9b85c..0000000 --- a/vendor/golang.org/x/text/encoding/internal/identifier/identifier.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2015 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:generate go run gen.go - -// Package identifier defines the contract between implementations of Encoding -// and Index by defining identifiers that uniquely identify standardized coded -// character sets (CCS) and character encoding schemes (CES), which we will -// together refer to as encodings, for which Encoding implementations provide -// converters to and from UTF-8. This package is typically only of concern to -// implementers of Indexes and Encodings. -// -// One part of the identifier is the MIB code, which is defined by IANA and -// uniquely identifies a CCS or CES. Each code is associated with data that -// references authorities, official documentation as well as aliases and MIME -// names. -// -// Not all CESs are covered by the IANA registry. The "other" string that is -// returned by ID can be used to identify other character sets or versions of -// existing ones. -// -// It is recommended that each package that provides a set of Encodings provide -// the All and Common variables to reference all supported encodings and -// commonly used subset. This allows Index implementations to include all -// available encodings without explicitly referencing or knowing about them. -package identifier - -// Note: this package is internal, but could be made public if there is a need -// for writing third-party Indexes and Encodings. - -// References: -// - http://source.icu-project.org/repos/icu/icu/trunk/source/data/mappings/convrtrs.txt -// - http://www.iana.org/assignments/character-sets/character-sets.xhtml -// - http://www.iana.org/assignments/ianacharset-mib/ianacharset-mib -// - http://www.ietf.org/rfc/rfc2978.txt -// - https://www.unicode.org/reports/tr22/ -// - http://www.w3.org/TR/encoding/ -// - https://encoding.spec.whatwg.org/ -// - https://encoding.spec.whatwg.org/encodings.json -// - https://tools.ietf.org/html/rfc6657#section-5 - -// Interface can be implemented by Encodings to define the CCS or CES for which -// it implements conversions. -type Interface interface { - // ID returns an encoding identifier. Exactly one of the mib and other - // values should be non-zero. - // - // In the usual case it is only necessary to indicate the MIB code. The - // other string can be used to specify encodings for which there is no MIB, - // such as "x-mac-dingbat". - // - // The other string may only contain the characters a-z, A-Z, 0-9, - and _. - ID() (mib MIB, other string) - - // NOTE: the restrictions on the encoding are to allow extending the syntax - // with additional information such as versions, vendors and other variants. -} - -// A MIB identifies an encoding. It is derived from the IANA MIB codes and adds -// some identifiers for some encodings that are not covered by the IANA -// standard. -// -// See http://www.iana.org/assignments/ianacharset-mib. -type MIB uint16 - -// These additional MIB types are not defined in IANA. They are added because -// they are common and defined within the text repo. -const ( - // Unofficial marks the start of encodings not registered by IANA. - Unofficial MIB = 10000 + iota - - // Replacement is the WhatWG replacement encoding. - Replacement - - // XUserDefined is the code for x-user-defined. - XUserDefined - - // MacintoshCyrillic is the code for x-mac-cyrillic. - MacintoshCyrillic -) diff --git a/vendor/golang.org/x/text/encoding/internal/identifier/mib.go b/vendor/golang.org/x/text/encoding/internal/identifier/mib.go deleted file mode 100644 index fc7df1b..0000000 --- a/vendor/golang.org/x/text/encoding/internal/identifier/mib.go +++ /dev/null @@ -1,1619 +0,0 @@ -// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. - -package identifier - -const ( - // ASCII is the MIB identifier with IANA name US-ASCII (MIME: US-ASCII). - // - // ANSI X3.4-1986 - // Reference: RFC2046 - ASCII MIB = 3 - - // ISOLatin1 is the MIB identifier with IANA name ISO_8859-1:1987 (MIME: ISO-8859-1). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatin1 MIB = 4 - - // ISOLatin2 is the MIB identifier with IANA name ISO_8859-2:1987 (MIME: ISO-8859-2). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatin2 MIB = 5 - - // ISOLatin3 is the MIB identifier with IANA name ISO_8859-3:1988 (MIME: ISO-8859-3). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatin3 MIB = 6 - - // ISOLatin4 is the MIB identifier with IANA name ISO_8859-4:1988 (MIME: ISO-8859-4). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatin4 MIB = 7 - - // ISOLatinCyrillic is the MIB identifier with IANA name ISO_8859-5:1988 (MIME: ISO-8859-5). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatinCyrillic MIB = 8 - - // ISOLatinArabic is the MIB identifier with IANA name ISO_8859-6:1987 (MIME: ISO-8859-6). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatinArabic MIB = 9 - - // ISOLatinGreek is the MIB identifier with IANA name ISO_8859-7:1987 (MIME: ISO-8859-7). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1947 - // Reference: RFC1345 - ISOLatinGreek MIB = 10 - - // ISOLatinHebrew is the MIB identifier with IANA name ISO_8859-8:1988 (MIME: ISO-8859-8). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatinHebrew MIB = 11 - - // ISOLatin5 is the MIB identifier with IANA name ISO_8859-9:1989 (MIME: ISO-8859-9). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatin5 MIB = 12 - - // ISOLatin6 is the MIB identifier with IANA name ISO-8859-10 (MIME: ISO-8859-10). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOLatin6 MIB = 13 - - // ISOTextComm is the MIB identifier with IANA name ISO_6937-2-add. - // - // ISO-IR: International Register of Escape Sequences and ISO 6937-2:1983 - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISOTextComm MIB = 14 - - // HalfWidthKatakana is the MIB identifier with IANA name JIS_X0201. - // - // JIS X 0201-1976. One byte only, this is equivalent to - // JIS/Roman (similar to ASCII) plus eight-bit half-width - // Katakana - // Reference: RFC1345 - HalfWidthKatakana MIB = 15 - - // JISEncoding is the MIB identifier with IANA name JIS_Encoding. - // - // JIS X 0202-1991. Uses ISO 2022 escape sequences to - // shift code sets as documented in JIS X 0202-1991. - JISEncoding MIB = 16 - - // ShiftJIS is the MIB identifier with IANA name Shift_JIS (MIME: Shift_JIS). - // - // This charset is an extension of csHalfWidthKatakana by - // adding graphic characters in JIS X 0208. The CCS's are - // JIS X0201:1997 and JIS X0208:1997. The - // complete definition is shown in Appendix 1 of JIS - // X0208:1997. - // This charset can be used for the top-level media type "text". - ShiftJIS MIB = 17 - - // EUCPkdFmtJapanese is the MIB identifier with IANA name Extended_UNIX_Code_Packed_Format_for_Japanese (MIME: EUC-JP). - // - // Standardized by OSF, UNIX International, and UNIX Systems - // Laboratories Pacific. Uses ISO 2022 rules to select - // code set 0: US-ASCII (a single 7-bit byte set) - // code set 1: JIS X0208-1990 (a double 8-bit byte set) - // restricted to A0-FF in both bytes - // code set 2: Half Width Katakana (a single 7-bit byte set) - // requiring SS2 as the character prefix - // code set 3: JIS X0212-1990 (a double 7-bit byte set) - // restricted to A0-FF in both bytes - // requiring SS3 as the character prefix - EUCPkdFmtJapanese MIB = 18 - - // EUCFixWidJapanese is the MIB identifier with IANA name Extended_UNIX_Code_Fixed_Width_for_Japanese. - // - // Used in Japan. Each character is 2 octets. - // code set 0: US-ASCII (a single 7-bit byte set) - // 1st byte = 00 - // 2nd byte = 20-7E - // code set 1: JIS X0208-1990 (a double 7-bit byte set) - // restricted to A0-FF in both bytes - // code set 2: Half Width Katakana (a single 7-bit byte set) - // 1st byte = 00 - // 2nd byte = A0-FF - // code set 3: JIS X0212-1990 (a double 7-bit byte set) - // restricted to A0-FF in - // the first byte - // and 21-7E in the second byte - EUCFixWidJapanese MIB = 19 - - // ISO4UnitedKingdom is the MIB identifier with IANA name BS_4730. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO4UnitedKingdom MIB = 20 - - // ISO11SwedishForNames is the MIB identifier with IANA name SEN_850200_C. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO11SwedishForNames MIB = 21 - - // ISO15Italian is the MIB identifier with IANA name IT. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO15Italian MIB = 22 - - // ISO17Spanish is the MIB identifier with IANA name ES. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO17Spanish MIB = 23 - - // ISO21German is the MIB identifier with IANA name DIN_66003. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO21German MIB = 24 - - // ISO60Norwegian1 is the MIB identifier with IANA name NS_4551-1. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO60Norwegian1 MIB = 25 - - // ISO69French is the MIB identifier with IANA name NF_Z_62-010. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO69French MIB = 26 - - // ISO10646UTF1 is the MIB identifier with IANA name ISO-10646-UTF-1. - // - // Universal Transfer Format (1), this is the multibyte - // encoding, that subsets ASCII-7. It does not have byte - // ordering issues. - ISO10646UTF1 MIB = 27 - - // ISO646basic1983 is the MIB identifier with IANA name ISO_646.basic:1983. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO646basic1983 MIB = 28 - - // INVARIANT is the MIB identifier with IANA name INVARIANT. - // - // Reference: RFC1345 - INVARIANT MIB = 29 - - // ISO2IntlRefVersion is the MIB identifier with IANA name ISO_646.irv:1983. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO2IntlRefVersion MIB = 30 - - // NATSSEFI is the MIB identifier with IANA name NATS-SEFI. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - NATSSEFI MIB = 31 - - // NATSSEFIADD is the MIB identifier with IANA name NATS-SEFI-ADD. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - NATSSEFIADD MIB = 32 - - // NATSDANO is the MIB identifier with IANA name NATS-DANO. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - NATSDANO MIB = 33 - - // NATSDANOADD is the MIB identifier with IANA name NATS-DANO-ADD. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - NATSDANOADD MIB = 34 - - // ISO10Swedish is the MIB identifier with IANA name SEN_850200_B. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO10Swedish MIB = 35 - - // KSC56011987 is the MIB identifier with IANA name KS_C_5601-1987. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - KSC56011987 MIB = 36 - - // ISO2022KR is the MIB identifier with IANA name ISO-2022-KR (MIME: ISO-2022-KR). - // - // rfc1557 (see also KS_C_5601-1987) - // Reference: RFC1557 - ISO2022KR MIB = 37 - - // EUCKR is the MIB identifier with IANA name EUC-KR (MIME: EUC-KR). - // - // rfc1557 (see also KS_C_5861-1992) - // Reference: RFC1557 - EUCKR MIB = 38 - - // ISO2022JP is the MIB identifier with IANA name ISO-2022-JP (MIME: ISO-2022-JP). - // - // rfc1468 (see also rfc2237 ) - // Reference: RFC1468 - ISO2022JP MIB = 39 - - // ISO2022JP2 is the MIB identifier with IANA name ISO-2022-JP-2 (MIME: ISO-2022-JP-2). - // - // rfc1554 - // Reference: RFC1554 - ISO2022JP2 MIB = 40 - - // ISO13JISC6220jp is the MIB identifier with IANA name JIS_C6220-1969-jp. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO13JISC6220jp MIB = 41 - - // ISO14JISC6220ro is the MIB identifier with IANA name JIS_C6220-1969-ro. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO14JISC6220ro MIB = 42 - - // ISO16Portuguese is the MIB identifier with IANA name PT. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO16Portuguese MIB = 43 - - // ISO18Greek7Old is the MIB identifier with IANA name greek7-old. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO18Greek7Old MIB = 44 - - // ISO19LatinGreek is the MIB identifier with IANA name latin-greek. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO19LatinGreek MIB = 45 - - // ISO25French is the MIB identifier with IANA name NF_Z_62-010_(1973). - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO25French MIB = 46 - - // ISO27LatinGreek1 is the MIB identifier with IANA name Latin-greek-1. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO27LatinGreek1 MIB = 47 - - // ISO5427Cyrillic is the MIB identifier with IANA name ISO_5427. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO5427Cyrillic MIB = 48 - - // ISO42JISC62261978 is the MIB identifier with IANA name JIS_C6226-1978. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO42JISC62261978 MIB = 49 - - // ISO47BSViewdata is the MIB identifier with IANA name BS_viewdata. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO47BSViewdata MIB = 50 - - // ISO49INIS is the MIB identifier with IANA name INIS. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO49INIS MIB = 51 - - // ISO50INIS8 is the MIB identifier with IANA name INIS-8. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO50INIS8 MIB = 52 - - // ISO51INISCyrillic is the MIB identifier with IANA name INIS-cyrillic. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO51INISCyrillic MIB = 53 - - // ISO54271981 is the MIB identifier with IANA name ISO_5427:1981. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO54271981 MIB = 54 - - // ISO5428Greek is the MIB identifier with IANA name ISO_5428:1980. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO5428Greek MIB = 55 - - // ISO57GB1988 is the MIB identifier with IANA name GB_1988-80. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO57GB1988 MIB = 56 - - // ISO58GB231280 is the MIB identifier with IANA name GB_2312-80. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO58GB231280 MIB = 57 - - // ISO61Norwegian2 is the MIB identifier with IANA name NS_4551-2. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO61Norwegian2 MIB = 58 - - // ISO70VideotexSupp1 is the MIB identifier with IANA name videotex-suppl. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO70VideotexSupp1 MIB = 59 - - // ISO84Portuguese2 is the MIB identifier with IANA name PT2. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO84Portuguese2 MIB = 60 - - // ISO85Spanish2 is the MIB identifier with IANA name ES2. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO85Spanish2 MIB = 61 - - // ISO86Hungarian is the MIB identifier with IANA name MSZ_7795.3. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO86Hungarian MIB = 62 - - // ISO87JISX0208 is the MIB identifier with IANA name JIS_C6226-1983. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO87JISX0208 MIB = 63 - - // ISO88Greek7 is the MIB identifier with IANA name greek7. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO88Greek7 MIB = 64 - - // ISO89ASMO449 is the MIB identifier with IANA name ASMO_449. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO89ASMO449 MIB = 65 - - // ISO90 is the MIB identifier with IANA name iso-ir-90. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO90 MIB = 66 - - // ISO91JISC62291984a is the MIB identifier with IANA name JIS_C6229-1984-a. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO91JISC62291984a MIB = 67 - - // ISO92JISC62991984b is the MIB identifier with IANA name JIS_C6229-1984-b. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO92JISC62991984b MIB = 68 - - // ISO93JIS62291984badd is the MIB identifier with IANA name JIS_C6229-1984-b-add. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO93JIS62291984badd MIB = 69 - - // ISO94JIS62291984hand is the MIB identifier with IANA name JIS_C6229-1984-hand. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO94JIS62291984hand MIB = 70 - - // ISO95JIS62291984handadd is the MIB identifier with IANA name JIS_C6229-1984-hand-add. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO95JIS62291984handadd MIB = 71 - - // ISO96JISC62291984kana is the MIB identifier with IANA name JIS_C6229-1984-kana. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO96JISC62291984kana MIB = 72 - - // ISO2033 is the MIB identifier with IANA name ISO_2033-1983. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO2033 MIB = 73 - - // ISO99NAPLPS is the MIB identifier with IANA name ANSI_X3.110-1983. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO99NAPLPS MIB = 74 - - // ISO102T617bit is the MIB identifier with IANA name T.61-7bit. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO102T617bit MIB = 75 - - // ISO103T618bit is the MIB identifier with IANA name T.61-8bit. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO103T618bit MIB = 76 - - // ISO111ECMACyrillic is the MIB identifier with IANA name ECMA-cyrillic. - // - // ISO registry - ISO111ECMACyrillic MIB = 77 - - // ISO121Canadian1 is the MIB identifier with IANA name CSA_Z243.4-1985-1. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO121Canadian1 MIB = 78 - - // ISO122Canadian2 is the MIB identifier with IANA name CSA_Z243.4-1985-2. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO122Canadian2 MIB = 79 - - // ISO123CSAZ24341985gr is the MIB identifier with IANA name CSA_Z243.4-1985-gr. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO123CSAZ24341985gr MIB = 80 - - // ISO88596E is the MIB identifier with IANA name ISO_8859-6-E (MIME: ISO-8859-6-E). - // - // rfc1556 - // Reference: RFC1556 - ISO88596E MIB = 81 - - // ISO88596I is the MIB identifier with IANA name ISO_8859-6-I (MIME: ISO-8859-6-I). - // - // rfc1556 - // Reference: RFC1556 - ISO88596I MIB = 82 - - // ISO128T101G2 is the MIB identifier with IANA name T.101-G2. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO128T101G2 MIB = 83 - - // ISO88598E is the MIB identifier with IANA name ISO_8859-8-E (MIME: ISO-8859-8-E). - // - // rfc1556 - // Reference: RFC1556 - ISO88598E MIB = 84 - - // ISO88598I is the MIB identifier with IANA name ISO_8859-8-I (MIME: ISO-8859-8-I). - // - // rfc1556 - // Reference: RFC1556 - ISO88598I MIB = 85 - - // ISO139CSN369103 is the MIB identifier with IANA name CSN_369103. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO139CSN369103 MIB = 86 - - // ISO141JUSIB1002 is the MIB identifier with IANA name JUS_I.B1.002. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO141JUSIB1002 MIB = 87 - - // ISO143IECP271 is the MIB identifier with IANA name IEC_P27-1. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO143IECP271 MIB = 88 - - // ISO146Serbian is the MIB identifier with IANA name JUS_I.B1.003-serb. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO146Serbian MIB = 89 - - // ISO147Macedonian is the MIB identifier with IANA name JUS_I.B1.003-mac. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO147Macedonian MIB = 90 - - // ISO150GreekCCITT is the MIB identifier with IANA name greek-ccitt. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO150GreekCCITT MIB = 91 - - // ISO151Cuba is the MIB identifier with IANA name NC_NC00-10:81. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO151Cuba MIB = 92 - - // ISO6937Add is the MIB identifier with IANA name ISO_6937-2-25. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO6937Add MIB = 93 - - // ISO153GOST1976874 is the MIB identifier with IANA name GOST_19768-74. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO153GOST1976874 MIB = 94 - - // ISO8859Supp is the MIB identifier with IANA name ISO_8859-supp. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO8859Supp MIB = 95 - - // ISO10367Box is the MIB identifier with IANA name ISO_10367-box. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO10367Box MIB = 96 - - // ISO158Lap is the MIB identifier with IANA name latin-lap. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO158Lap MIB = 97 - - // ISO159JISX02121990 is the MIB identifier with IANA name JIS_X0212-1990. - // - // ISO-IR: International Register of Escape Sequences - // Note: The current registration authority is IPSJ/ITSCJ, Japan. - // Reference: RFC1345 - ISO159JISX02121990 MIB = 98 - - // ISO646Danish is the MIB identifier with IANA name DS_2089. - // - // Danish Standard, DS 2089, February 1974 - // Reference: RFC1345 - ISO646Danish MIB = 99 - - // USDK is the MIB identifier with IANA name us-dk. - // - // Reference: RFC1345 - USDK MIB = 100 - - // DKUS is the MIB identifier with IANA name dk-us. - // - // Reference: RFC1345 - DKUS MIB = 101 - - // KSC5636 is the MIB identifier with IANA name KSC5636. - // - // Reference: RFC1345 - KSC5636 MIB = 102 - - // Unicode11UTF7 is the MIB identifier with IANA name UNICODE-1-1-UTF-7. - // - // rfc1642 - // Reference: RFC1642 - Unicode11UTF7 MIB = 103 - - // ISO2022CN is the MIB identifier with IANA name ISO-2022-CN. - // - // rfc1922 - // Reference: RFC1922 - ISO2022CN MIB = 104 - - // ISO2022CNEXT is the MIB identifier with IANA name ISO-2022-CN-EXT. - // - // rfc1922 - // Reference: RFC1922 - ISO2022CNEXT MIB = 105 - - // UTF8 is the MIB identifier with IANA name UTF-8. - // - // rfc3629 - // Reference: RFC3629 - UTF8 MIB = 106 - - // ISO885913 is the MIB identifier with IANA name ISO-8859-13. - // - // ISO See https://www.iana.org/assignments/charset-reg/ISO-8859-13 https://www.iana.org/assignments/charset-reg/ISO-8859-13 - ISO885913 MIB = 109 - - // ISO885914 is the MIB identifier with IANA name ISO-8859-14. - // - // ISO See https://www.iana.org/assignments/charset-reg/ISO-8859-14 - ISO885914 MIB = 110 - - // ISO885915 is the MIB identifier with IANA name ISO-8859-15. - // - // ISO - // Please see: https://www.iana.org/assignments/charset-reg/ISO-8859-15 - ISO885915 MIB = 111 - - // ISO885916 is the MIB identifier with IANA name ISO-8859-16. - // - // ISO - ISO885916 MIB = 112 - - // GBK is the MIB identifier with IANA name GBK. - // - // Chinese IT Standardization Technical Committee - // Please see: https://www.iana.org/assignments/charset-reg/GBK - GBK MIB = 113 - - // GB18030 is the MIB identifier with IANA name GB18030. - // - // Chinese IT Standardization Technical Committee - // Please see: https://www.iana.org/assignments/charset-reg/GB18030 - GB18030 MIB = 114 - - // OSDEBCDICDF0415 is the MIB identifier with IANA name OSD_EBCDIC_DF04_15. - // - // Fujitsu-Siemens standard mainframe EBCDIC encoding - // Please see: https://www.iana.org/assignments/charset-reg/OSD-EBCDIC-DF04-15 - OSDEBCDICDF0415 MIB = 115 - - // OSDEBCDICDF03IRV is the MIB identifier with IANA name OSD_EBCDIC_DF03_IRV. - // - // Fujitsu-Siemens standard mainframe EBCDIC encoding - // Please see: https://www.iana.org/assignments/charset-reg/OSD-EBCDIC-DF03-IRV - OSDEBCDICDF03IRV MIB = 116 - - // OSDEBCDICDF041 is the MIB identifier with IANA name OSD_EBCDIC_DF04_1. - // - // Fujitsu-Siemens standard mainframe EBCDIC encoding - // Please see: https://www.iana.org/assignments/charset-reg/OSD-EBCDIC-DF04-1 - OSDEBCDICDF041 MIB = 117 - - // ISO115481 is the MIB identifier with IANA name ISO-11548-1. - // - // See https://www.iana.org/assignments/charset-reg/ISO-11548-1 - ISO115481 MIB = 118 - - // KZ1048 is the MIB identifier with IANA name KZ-1048. - // - // See https://www.iana.org/assignments/charset-reg/KZ-1048 - KZ1048 MIB = 119 - - // Unicode is the MIB identifier with IANA name ISO-10646-UCS-2. - // - // the 2-octet Basic Multilingual Plane, aka Unicode - // this needs to specify network byte order: the standard - // does not specify (it is a 16-bit integer space) - Unicode MIB = 1000 - - // UCS4 is the MIB identifier with IANA name ISO-10646-UCS-4. - // - // the full code space. (same comment about byte order, - // these are 31-bit numbers. - UCS4 MIB = 1001 - - // UnicodeASCII is the MIB identifier with IANA name ISO-10646-UCS-Basic. - // - // ASCII subset of Unicode. Basic Latin = collection 1 - // See ISO 10646, Appendix A - UnicodeASCII MIB = 1002 - - // UnicodeLatin1 is the MIB identifier with IANA name ISO-10646-Unicode-Latin1. - // - // ISO Latin-1 subset of Unicode. Basic Latin and Latin-1 - // Supplement = collections 1 and 2. See ISO 10646, - // Appendix A. See rfc1815 . - UnicodeLatin1 MIB = 1003 - - // UnicodeJapanese is the MIB identifier with IANA name ISO-10646-J-1. - // - // ISO 10646 Japanese, see rfc1815 . - UnicodeJapanese MIB = 1004 - - // UnicodeIBM1261 is the MIB identifier with IANA name ISO-Unicode-IBM-1261. - // - // IBM Latin-2, -3, -5, Extended Presentation Set, GCSGID: 1261 - UnicodeIBM1261 MIB = 1005 - - // UnicodeIBM1268 is the MIB identifier with IANA name ISO-Unicode-IBM-1268. - // - // IBM Latin-4 Extended Presentation Set, GCSGID: 1268 - UnicodeIBM1268 MIB = 1006 - - // UnicodeIBM1276 is the MIB identifier with IANA name ISO-Unicode-IBM-1276. - // - // IBM Cyrillic Greek Extended Presentation Set, GCSGID: 1276 - UnicodeIBM1276 MIB = 1007 - - // UnicodeIBM1264 is the MIB identifier with IANA name ISO-Unicode-IBM-1264. - // - // IBM Arabic Presentation Set, GCSGID: 1264 - UnicodeIBM1264 MIB = 1008 - - // UnicodeIBM1265 is the MIB identifier with IANA name ISO-Unicode-IBM-1265. - // - // IBM Hebrew Presentation Set, GCSGID: 1265 - UnicodeIBM1265 MIB = 1009 - - // Unicode11 is the MIB identifier with IANA name UNICODE-1-1. - // - // rfc1641 - // Reference: RFC1641 - Unicode11 MIB = 1010 - - // SCSU is the MIB identifier with IANA name SCSU. - // - // SCSU See https://www.iana.org/assignments/charset-reg/SCSU - SCSU MIB = 1011 - - // UTF7 is the MIB identifier with IANA name UTF-7. - // - // rfc2152 - // Reference: RFC2152 - UTF7 MIB = 1012 - - // UTF16BE is the MIB identifier with IANA name UTF-16BE. - // - // rfc2781 - // Reference: RFC2781 - UTF16BE MIB = 1013 - - // UTF16LE is the MIB identifier with IANA name UTF-16LE. - // - // rfc2781 - // Reference: RFC2781 - UTF16LE MIB = 1014 - - // UTF16 is the MIB identifier with IANA name UTF-16. - // - // rfc2781 - // Reference: RFC2781 - UTF16 MIB = 1015 - - // CESU8 is the MIB identifier with IANA name CESU-8. - // - // https://www.unicode.org/reports/tr26 - CESU8 MIB = 1016 - - // UTF32 is the MIB identifier with IANA name UTF-32. - // - // https://www.unicode.org/reports/tr19/ - UTF32 MIB = 1017 - - // UTF32BE is the MIB identifier with IANA name UTF-32BE. - // - // https://www.unicode.org/reports/tr19/ - UTF32BE MIB = 1018 - - // UTF32LE is the MIB identifier with IANA name UTF-32LE. - // - // https://www.unicode.org/reports/tr19/ - UTF32LE MIB = 1019 - - // BOCU1 is the MIB identifier with IANA name BOCU-1. - // - // https://www.unicode.org/notes/tn6/ - BOCU1 MIB = 1020 - - // Windows30Latin1 is the MIB identifier with IANA name ISO-8859-1-Windows-3.0-Latin-1. - // - // Extended ISO 8859-1 Latin-1 for Windows 3.0. - // PCL Symbol Set id: 9U - Windows30Latin1 MIB = 2000 - - // Windows31Latin1 is the MIB identifier with IANA name ISO-8859-1-Windows-3.1-Latin-1. - // - // Extended ISO 8859-1 Latin-1 for Windows 3.1. - // PCL Symbol Set id: 19U - Windows31Latin1 MIB = 2001 - - // Windows31Latin2 is the MIB identifier with IANA name ISO-8859-2-Windows-Latin-2. - // - // Extended ISO 8859-2. Latin-2 for Windows 3.1. - // PCL Symbol Set id: 9E - Windows31Latin2 MIB = 2002 - - // Windows31Latin5 is the MIB identifier with IANA name ISO-8859-9-Windows-Latin-5. - // - // Extended ISO 8859-9. Latin-5 for Windows 3.1 - // PCL Symbol Set id: 5T - Windows31Latin5 MIB = 2003 - - // HPRoman8 is the MIB identifier with IANA name hp-roman8. - // - // LaserJet IIP Printer User's Manual, - // HP part no 33471-90901, Hewlet-Packard, June 1989. - // Reference: RFC1345 - HPRoman8 MIB = 2004 - - // AdobeStandardEncoding is the MIB identifier with IANA name Adobe-Standard-Encoding. - // - // PostScript Language Reference Manual - // PCL Symbol Set id: 10J - AdobeStandardEncoding MIB = 2005 - - // VenturaUS is the MIB identifier with IANA name Ventura-US. - // - // Ventura US. ASCII plus characters typically used in - // publishing, like pilcrow, copyright, registered, trade mark, - // section, dagger, and double dagger in the range A0 (hex) - // to FF (hex). - // PCL Symbol Set id: 14J - VenturaUS MIB = 2006 - - // VenturaInternational is the MIB identifier with IANA name Ventura-International. - // - // Ventura International. ASCII plus coded characters similar - // to Roman8. - // PCL Symbol Set id: 13J - VenturaInternational MIB = 2007 - - // DECMCS is the MIB identifier with IANA name DEC-MCS. - // - // VAX/VMS User's Manual, - // Order Number: AI-Y517A-TE, April 1986. - // Reference: RFC1345 - DECMCS MIB = 2008 - - // PC850Multilingual is the MIB identifier with IANA name IBM850. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - PC850Multilingual MIB = 2009 - - // PC8DanishNorwegian is the MIB identifier with IANA name PC8-Danish-Norwegian. - // - // PC Danish Norwegian - // 8-bit PC set for Danish Norwegian - // PCL Symbol Set id: 11U - PC8DanishNorwegian MIB = 2012 - - // PC862LatinHebrew is the MIB identifier with IANA name IBM862. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - PC862LatinHebrew MIB = 2013 - - // PC8Turkish is the MIB identifier with IANA name PC8-Turkish. - // - // PC Latin Turkish. PCL Symbol Set id: 9T - PC8Turkish MIB = 2014 - - // IBMSymbols is the MIB identifier with IANA name IBM-Symbols. - // - // Presentation Set, CPGID: 259 - IBMSymbols MIB = 2015 - - // IBMThai is the MIB identifier with IANA name IBM-Thai. - // - // Presentation Set, CPGID: 838 - IBMThai MIB = 2016 - - // HPLegal is the MIB identifier with IANA name HP-Legal. - // - // PCL 5 Comparison Guide, Hewlett-Packard, - // HP part number 5961-0510, October 1992 - // PCL Symbol Set id: 1U - HPLegal MIB = 2017 - - // HPPiFont is the MIB identifier with IANA name HP-Pi-font. - // - // PCL 5 Comparison Guide, Hewlett-Packard, - // HP part number 5961-0510, October 1992 - // PCL Symbol Set id: 15U - HPPiFont MIB = 2018 - - // HPMath8 is the MIB identifier with IANA name HP-Math8. - // - // PCL 5 Comparison Guide, Hewlett-Packard, - // HP part number 5961-0510, October 1992 - // PCL Symbol Set id: 8M - HPMath8 MIB = 2019 - - // HPPSMath is the MIB identifier with IANA name Adobe-Symbol-Encoding. - // - // PostScript Language Reference Manual - // PCL Symbol Set id: 5M - HPPSMath MIB = 2020 - - // HPDesktop is the MIB identifier with IANA name HP-DeskTop. - // - // PCL 5 Comparison Guide, Hewlett-Packard, - // HP part number 5961-0510, October 1992 - // PCL Symbol Set id: 7J - HPDesktop MIB = 2021 - - // VenturaMath is the MIB identifier with IANA name Ventura-Math. - // - // PCL 5 Comparison Guide, Hewlett-Packard, - // HP part number 5961-0510, October 1992 - // PCL Symbol Set id: 6M - VenturaMath MIB = 2022 - - // MicrosoftPublishing is the MIB identifier with IANA name Microsoft-Publishing. - // - // PCL 5 Comparison Guide, Hewlett-Packard, - // HP part number 5961-0510, October 1992 - // PCL Symbol Set id: 6J - MicrosoftPublishing MIB = 2023 - - // Windows31J is the MIB identifier with IANA name Windows-31J. - // - // Windows Japanese. A further extension of Shift_JIS - // to include NEC special characters (Row 13), NEC - // selection of IBM extensions (Rows 89 to 92), and IBM - // extensions (Rows 115 to 119). The CCS's are - // JIS X0201:1997, JIS X0208:1997, and these extensions. - // This charset can be used for the top-level media type "text", - // but it is of limited or specialized use (see rfc2278 ). - // PCL Symbol Set id: 19K - Windows31J MIB = 2024 - - // GB2312 is the MIB identifier with IANA name GB2312 (MIME: GB2312). - // - // Chinese for People's Republic of China (PRC) mixed one byte, - // two byte set: - // 20-7E = one byte ASCII - // A1-FE = two byte PRC Kanji - // See GB 2312-80 - // PCL Symbol Set Id: 18C - GB2312 MIB = 2025 - - // Big5 is the MIB identifier with IANA name Big5 (MIME: Big5). - // - // Chinese for Taiwan Multi-byte set. - // PCL Symbol Set Id: 18T - Big5 MIB = 2026 - - // Macintosh is the MIB identifier with IANA name macintosh. - // - // The Unicode Standard ver1.0, ISBN 0-201-56788-1, Oct 1991 - // Reference: RFC1345 - Macintosh MIB = 2027 - - // IBM037 is the MIB identifier with IANA name IBM037. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM037 MIB = 2028 - - // IBM038 is the MIB identifier with IANA name IBM038. - // - // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 - // Reference: RFC1345 - IBM038 MIB = 2029 - - // IBM273 is the MIB identifier with IANA name IBM273. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM273 MIB = 2030 - - // IBM274 is the MIB identifier with IANA name IBM274. - // - // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 - // Reference: RFC1345 - IBM274 MIB = 2031 - - // IBM275 is the MIB identifier with IANA name IBM275. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM275 MIB = 2032 - - // IBM277 is the MIB identifier with IANA name IBM277. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM277 MIB = 2033 - - // IBM278 is the MIB identifier with IANA name IBM278. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM278 MIB = 2034 - - // IBM280 is the MIB identifier with IANA name IBM280. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM280 MIB = 2035 - - // IBM281 is the MIB identifier with IANA name IBM281. - // - // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 - // Reference: RFC1345 - IBM281 MIB = 2036 - - // IBM284 is the MIB identifier with IANA name IBM284. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM284 MIB = 2037 - - // IBM285 is the MIB identifier with IANA name IBM285. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM285 MIB = 2038 - - // IBM290 is the MIB identifier with IANA name IBM290. - // - // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 - // Reference: RFC1345 - IBM290 MIB = 2039 - - // IBM297 is the MIB identifier with IANA name IBM297. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM297 MIB = 2040 - - // IBM420 is the MIB identifier with IANA name IBM420. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990, - // IBM NLS RM p 11-11 - // Reference: RFC1345 - IBM420 MIB = 2041 - - // IBM423 is the MIB identifier with IANA name IBM423. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM423 MIB = 2042 - - // IBM424 is the MIB identifier with IANA name IBM424. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM424 MIB = 2043 - - // PC8CodePage437 is the MIB identifier with IANA name IBM437. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - PC8CodePage437 MIB = 2011 - - // IBM500 is the MIB identifier with IANA name IBM500. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM500 MIB = 2044 - - // IBM851 is the MIB identifier with IANA name IBM851. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM851 MIB = 2045 - - // PCp852 is the MIB identifier with IANA name IBM852. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - PCp852 MIB = 2010 - - // IBM855 is the MIB identifier with IANA name IBM855. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM855 MIB = 2046 - - // IBM857 is the MIB identifier with IANA name IBM857. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM857 MIB = 2047 - - // IBM860 is the MIB identifier with IANA name IBM860. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM860 MIB = 2048 - - // IBM861 is the MIB identifier with IANA name IBM861. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM861 MIB = 2049 - - // IBM863 is the MIB identifier with IANA name IBM863. - // - // IBM Keyboard layouts and code pages, PN 07G4586 June 1991 - // Reference: RFC1345 - IBM863 MIB = 2050 - - // IBM864 is the MIB identifier with IANA name IBM864. - // - // IBM Keyboard layouts and code pages, PN 07G4586 June 1991 - // Reference: RFC1345 - IBM864 MIB = 2051 - - // IBM865 is the MIB identifier with IANA name IBM865. - // - // IBM DOS 3.3 Ref (Abridged), 94X9575 (Feb 1987) - // Reference: RFC1345 - IBM865 MIB = 2052 - - // IBM868 is the MIB identifier with IANA name IBM868. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM868 MIB = 2053 - - // IBM869 is the MIB identifier with IANA name IBM869. - // - // IBM Keyboard layouts and code pages, PN 07G4586 June 1991 - // Reference: RFC1345 - IBM869 MIB = 2054 - - // IBM870 is the MIB identifier with IANA name IBM870. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM870 MIB = 2055 - - // IBM871 is the MIB identifier with IANA name IBM871. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM871 MIB = 2056 - - // IBM880 is the MIB identifier with IANA name IBM880. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM880 MIB = 2057 - - // IBM891 is the MIB identifier with IANA name IBM891. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM891 MIB = 2058 - - // IBM903 is the MIB identifier with IANA name IBM903. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM903 MIB = 2059 - - // IBBM904 is the MIB identifier with IANA name IBM904. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBBM904 MIB = 2060 - - // IBM905 is the MIB identifier with IANA name IBM905. - // - // IBM 3174 Character Set Ref, GA27-3831-02, March 1990 - // Reference: RFC1345 - IBM905 MIB = 2061 - - // IBM918 is the MIB identifier with IANA name IBM918. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM918 MIB = 2062 - - // IBM1026 is the MIB identifier with IANA name IBM1026. - // - // IBM NLS RM Vol2 SE09-8002-01, March 1990 - // Reference: RFC1345 - IBM1026 MIB = 2063 - - // IBMEBCDICATDE is the MIB identifier with IANA name EBCDIC-AT-DE. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - IBMEBCDICATDE MIB = 2064 - - // EBCDICATDEA is the MIB identifier with IANA name EBCDIC-AT-DE-A. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICATDEA MIB = 2065 - - // EBCDICCAFR is the MIB identifier with IANA name EBCDIC-CA-FR. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICCAFR MIB = 2066 - - // EBCDICDKNO is the MIB identifier with IANA name EBCDIC-DK-NO. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICDKNO MIB = 2067 - - // EBCDICDKNOA is the MIB identifier with IANA name EBCDIC-DK-NO-A. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICDKNOA MIB = 2068 - - // EBCDICFISE is the MIB identifier with IANA name EBCDIC-FI-SE. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICFISE MIB = 2069 - - // EBCDICFISEA is the MIB identifier with IANA name EBCDIC-FI-SE-A. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICFISEA MIB = 2070 - - // EBCDICFR is the MIB identifier with IANA name EBCDIC-FR. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICFR MIB = 2071 - - // EBCDICIT is the MIB identifier with IANA name EBCDIC-IT. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICIT MIB = 2072 - - // EBCDICPT is the MIB identifier with IANA name EBCDIC-PT. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICPT MIB = 2073 - - // EBCDICES is the MIB identifier with IANA name EBCDIC-ES. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICES MIB = 2074 - - // EBCDICESA is the MIB identifier with IANA name EBCDIC-ES-A. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICESA MIB = 2075 - - // EBCDICESS is the MIB identifier with IANA name EBCDIC-ES-S. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICESS MIB = 2076 - - // EBCDICUK is the MIB identifier with IANA name EBCDIC-UK. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICUK MIB = 2077 - - // EBCDICUS is the MIB identifier with IANA name EBCDIC-US. - // - // IBM 3270 Char Set Ref Ch 10, GA27-2837-9, April 1987 - // Reference: RFC1345 - EBCDICUS MIB = 2078 - - // Unknown8BiT is the MIB identifier with IANA name UNKNOWN-8BIT. - // - // Reference: RFC1428 - Unknown8BiT MIB = 2079 - - // Mnemonic is the MIB identifier with IANA name MNEMONIC. - // - // rfc1345 , also known as "mnemonic+ascii+38" - // Reference: RFC1345 - Mnemonic MIB = 2080 - - // Mnem is the MIB identifier with IANA name MNEM. - // - // rfc1345 , also known as "mnemonic+ascii+8200" - // Reference: RFC1345 - Mnem MIB = 2081 - - // VISCII is the MIB identifier with IANA name VISCII. - // - // rfc1456 - // Reference: RFC1456 - VISCII MIB = 2082 - - // VIQR is the MIB identifier with IANA name VIQR. - // - // rfc1456 - // Reference: RFC1456 - VIQR MIB = 2083 - - // KOI8R is the MIB identifier with IANA name KOI8-R (MIME: KOI8-R). - // - // rfc1489 , based on GOST-19768-74, ISO-6937/8, - // INIS-Cyrillic, ISO-5427. - // Reference: RFC1489 - KOI8R MIB = 2084 - - // HZGB2312 is the MIB identifier with IANA name HZ-GB-2312. - // - // rfc1842 , rfc1843 rfc1843 rfc1842 - HZGB2312 MIB = 2085 - - // IBM866 is the MIB identifier with IANA name IBM866. - // - // IBM NLDG Volume 2 (SE09-8002-03) August 1994 - IBM866 MIB = 2086 - - // PC775Baltic is the MIB identifier with IANA name IBM775. - // - // HP PCL 5 Comparison Guide (P/N 5021-0329) pp B-13, 1996 - PC775Baltic MIB = 2087 - - // KOI8U is the MIB identifier with IANA name KOI8-U. - // - // rfc2319 - // Reference: RFC2319 - KOI8U MIB = 2088 - - // IBM00858 is the MIB identifier with IANA name IBM00858. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM00858 - IBM00858 MIB = 2089 - - // IBM00924 is the MIB identifier with IANA name IBM00924. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM00924 - IBM00924 MIB = 2090 - - // IBM01140 is the MIB identifier with IANA name IBM01140. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01140 - IBM01140 MIB = 2091 - - // IBM01141 is the MIB identifier with IANA name IBM01141. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01141 - IBM01141 MIB = 2092 - - // IBM01142 is the MIB identifier with IANA name IBM01142. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01142 - IBM01142 MIB = 2093 - - // IBM01143 is the MIB identifier with IANA name IBM01143. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01143 - IBM01143 MIB = 2094 - - // IBM01144 is the MIB identifier with IANA name IBM01144. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01144 - IBM01144 MIB = 2095 - - // IBM01145 is the MIB identifier with IANA name IBM01145. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01145 - IBM01145 MIB = 2096 - - // IBM01146 is the MIB identifier with IANA name IBM01146. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01146 - IBM01146 MIB = 2097 - - // IBM01147 is the MIB identifier with IANA name IBM01147. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01147 - IBM01147 MIB = 2098 - - // IBM01148 is the MIB identifier with IANA name IBM01148. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01148 - IBM01148 MIB = 2099 - - // IBM01149 is the MIB identifier with IANA name IBM01149. - // - // IBM See https://www.iana.org/assignments/charset-reg/IBM01149 - IBM01149 MIB = 2100 - - // Big5HKSCS is the MIB identifier with IANA name Big5-HKSCS. - // - // See https://www.iana.org/assignments/charset-reg/Big5-HKSCS - Big5HKSCS MIB = 2101 - - // IBM1047 is the MIB identifier with IANA name IBM1047. - // - // IBM1047 (EBCDIC Latin 1/Open Systems) https://www-1.ibm.com/servers/eserver/iseries/software/globalization/pdf/cp01047z.pdf - IBM1047 MIB = 2102 - - // PTCP154 is the MIB identifier with IANA name PTCP154. - // - // See https://www.iana.org/assignments/charset-reg/PTCP154 - PTCP154 MIB = 2103 - - // Amiga1251 is the MIB identifier with IANA name Amiga-1251. - // - // See https://www.amiga.ultranet.ru/Amiga-1251.html - Amiga1251 MIB = 2104 - - // KOI7switched is the MIB identifier with IANA name KOI7-switched. - // - // See https://www.iana.org/assignments/charset-reg/KOI7-switched - KOI7switched MIB = 2105 - - // BRF is the MIB identifier with IANA name BRF. - // - // See https://www.iana.org/assignments/charset-reg/BRF - BRF MIB = 2106 - - // TSCII is the MIB identifier with IANA name TSCII. - // - // See https://www.iana.org/assignments/charset-reg/TSCII - TSCII MIB = 2107 - - // CP51932 is the MIB identifier with IANA name CP51932. - // - // See https://www.iana.org/assignments/charset-reg/CP51932 - CP51932 MIB = 2108 - - // Windows874 is the MIB identifier with IANA name windows-874. - // - // See https://www.iana.org/assignments/charset-reg/windows-874 - Windows874 MIB = 2109 - - // Windows1250 is the MIB identifier with IANA name windows-1250. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1250 - Windows1250 MIB = 2250 - - // Windows1251 is the MIB identifier with IANA name windows-1251. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1251 - Windows1251 MIB = 2251 - - // Windows1252 is the MIB identifier with IANA name windows-1252. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1252 - Windows1252 MIB = 2252 - - // Windows1253 is the MIB identifier with IANA name windows-1253. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1253 - Windows1253 MIB = 2253 - - // Windows1254 is the MIB identifier with IANA name windows-1254. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1254 - Windows1254 MIB = 2254 - - // Windows1255 is the MIB identifier with IANA name windows-1255. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1255 - Windows1255 MIB = 2255 - - // Windows1256 is the MIB identifier with IANA name windows-1256. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1256 - Windows1256 MIB = 2256 - - // Windows1257 is the MIB identifier with IANA name windows-1257. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1257 - Windows1257 MIB = 2257 - - // Windows1258 is the MIB identifier with IANA name windows-1258. - // - // Microsoft https://www.iana.org/assignments/charset-reg/windows-1258 - Windows1258 MIB = 2258 - - // TIS620 is the MIB identifier with IANA name TIS-620. - // - // Thai Industrial Standards Institute (TISI) - TIS620 MIB = 2259 - - // CP50220 is the MIB identifier with IANA name CP50220. - // - // See https://www.iana.org/assignments/charset-reg/CP50220 - CP50220 MIB = 2260 -) diff --git a/vendor/golang.org/x/text/transform/transform.go b/vendor/golang.org/x/text/transform/transform.go deleted file mode 100644 index 48ec64b..0000000 --- a/vendor/golang.org/x/text/transform/transform.go +++ /dev/null @@ -1,709 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package transform provides reader and writer wrappers that transform the -// bytes passing through as well as various transformations. Example -// transformations provided by other packages include normalization and -// conversion between character sets. -package transform // import "golang.org/x/text/transform" - -import ( - "bytes" - "errors" - "io" - "unicode/utf8" -) - -var ( - // ErrShortDst means that the destination buffer was too short to - // receive all of the transformed bytes. - ErrShortDst = errors.New("transform: short destination buffer") - - // ErrShortSrc means that the source buffer has insufficient data to - // complete the transformation. - ErrShortSrc = errors.New("transform: short source buffer") - - // ErrEndOfSpan means that the input and output (the transformed input) - // are not identical. - ErrEndOfSpan = errors.New("transform: input and output are not identical") - - // errInconsistentByteCount means that Transform returned success (nil - // error) but also returned nSrc inconsistent with the src argument. - errInconsistentByteCount = errors.New("transform: inconsistent byte count returned") - - // errShortInternal means that an internal buffer is not large enough - // to make progress and the Transform operation must be aborted. - errShortInternal = errors.New("transform: short internal buffer") -) - -// Transformer transforms bytes. -type Transformer interface { - // Transform writes to dst the transformed bytes read from src, and - // returns the number of dst bytes written and src bytes read. The - // atEOF argument tells whether src represents the last bytes of the - // input. - // - // Callers should always process the nDst bytes produced and account - // for the nSrc bytes consumed before considering the error err. - // - // A nil error means that all of the transformed bytes (whether freshly - // transformed from src or left over from previous Transform calls) - // were written to dst. A nil error can be returned regardless of - // whether atEOF is true. If err is nil then nSrc must equal len(src); - // the converse is not necessarily true. - // - // ErrShortDst means that dst was too short to receive all of the - // transformed bytes. ErrShortSrc means that src had insufficient data - // to complete the transformation. If both conditions apply, then - // either error may be returned. Other than the error conditions listed - // here, implementations are free to report other errors that arise. - Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) - - // Reset resets the state and allows a Transformer to be reused. - Reset() -} - -// SpanningTransformer extends the Transformer interface with a Span method -// that determines how much of the input already conforms to the Transformer. -type SpanningTransformer interface { - Transformer - - // Span returns a position in src such that transforming src[:n] results in - // identical output src[:n] for these bytes. It does not necessarily return - // the largest such n. The atEOF argument tells whether src represents the - // last bytes of the input. - // - // Callers should always account for the n bytes consumed before - // considering the error err. - // - // A nil error means that all input bytes are known to be identical to the - // output produced by the Transformer. A nil error can be returned - // regardless of whether atEOF is true. If err is nil, then n must - // equal len(src); the converse is not necessarily true. - // - // ErrEndOfSpan means that the Transformer output may differ from the - // input after n bytes. Note that n may be len(src), meaning that the output - // would contain additional bytes after otherwise identical output. - // ErrShortSrc means that src had insufficient data to determine whether the - // remaining bytes would change. Other than the error conditions listed - // here, implementations are free to report other errors that arise. - // - // Calling Span can modify the Transformer state as a side effect. In - // effect, it does the transformation just as calling Transform would, only - // without copying to a destination buffer and only up to a point it can - // determine the input and output bytes are the same. This is obviously more - // limited than calling Transform, but can be more efficient in terms of - // copying and allocating buffers. Calls to Span and Transform may be - // interleaved. - Span(src []byte, atEOF bool) (n int, err error) -} - -// NopResetter can be embedded by implementations of Transformer to add a nop -// Reset method. -type NopResetter struct{} - -// Reset implements the Reset method of the Transformer interface. -func (NopResetter) Reset() {} - -// Reader wraps another io.Reader by transforming the bytes read. -type Reader struct { - r io.Reader - t Transformer - err error - - // dst[dst0:dst1] contains bytes that have been transformed by t but - // not yet copied out via Read. - dst []byte - dst0, dst1 int - - // src[src0:src1] contains bytes that have been read from r but not - // yet transformed through t. - src []byte - src0, src1 int - - // transformComplete is whether the transformation is complete, - // regardless of whether or not it was successful. - transformComplete bool -} - -const defaultBufSize = 4096 - -// NewReader returns a new Reader that wraps r by transforming the bytes read -// via t. It calls Reset on t. -func NewReader(r io.Reader, t Transformer) *Reader { - t.Reset() - return &Reader{ - r: r, - t: t, - dst: make([]byte, defaultBufSize), - src: make([]byte, defaultBufSize), - } -} - -// Read implements the io.Reader interface. -func (r *Reader) Read(p []byte) (int, error) { - n, err := 0, error(nil) - for { - // Copy out any transformed bytes and return the final error if we are done. - if r.dst0 != r.dst1 { - n = copy(p, r.dst[r.dst0:r.dst1]) - r.dst0 += n - if r.dst0 == r.dst1 && r.transformComplete { - return n, r.err - } - return n, nil - } else if r.transformComplete { - return 0, r.err - } - - // Try to transform some source bytes, or to flush the transformer if we - // are out of source bytes. We do this even if r.r.Read returned an error. - // As the io.Reader documentation says, "process the n > 0 bytes returned - // before considering the error". - if r.src0 != r.src1 || r.err != nil { - r.dst0 = 0 - r.dst1, n, err = r.t.Transform(r.dst, r.src[r.src0:r.src1], r.err == io.EOF) - r.src0 += n - - switch { - case err == nil: - if r.src0 != r.src1 { - r.err = errInconsistentByteCount - } - // The Transform call was successful; we are complete if we - // cannot read more bytes into src. - r.transformComplete = r.err != nil - continue - case err == ErrShortDst && (r.dst1 != 0 || n != 0): - // Make room in dst by copying out, and try again. - continue - case err == ErrShortSrc && r.src1-r.src0 != len(r.src) && r.err == nil: - // Read more bytes into src via the code below, and try again. - default: - r.transformComplete = true - // The reader error (r.err) takes precedence over the - // transformer error (err) unless r.err is nil or io.EOF. - if r.err == nil || r.err == io.EOF { - r.err = err - } - continue - } - } - - // Move any untransformed source bytes to the start of the buffer - // and read more bytes. - if r.src0 != 0 { - r.src0, r.src1 = 0, copy(r.src, r.src[r.src0:r.src1]) - } - n, r.err = r.r.Read(r.src[r.src1:]) - r.src1 += n - } -} - -// TODO: implement ReadByte (and ReadRune??). - -// Writer wraps another io.Writer by transforming the bytes read. -// The user needs to call Close to flush unwritten bytes that may -// be buffered. -type Writer struct { - w io.Writer - t Transformer - dst []byte - - // src[:n] contains bytes that have not yet passed through t. - src []byte - n int -} - -// NewWriter returns a new Writer that wraps w by transforming the bytes written -// via t. It calls Reset on t. -func NewWriter(w io.Writer, t Transformer) *Writer { - t.Reset() - return &Writer{ - w: w, - t: t, - dst: make([]byte, defaultBufSize), - src: make([]byte, defaultBufSize), - } -} - -// Write implements the io.Writer interface. If there are not enough -// bytes available to complete a Transform, the bytes will be buffered -// for the next write. Call Close to convert the remaining bytes. -func (w *Writer) Write(data []byte) (n int, err error) { - src := data - if w.n > 0 { - // Append bytes from data to the last remainder. - // TODO: limit the amount copied on first try. - n = copy(w.src[w.n:], data) - w.n += n - src = w.src[:w.n] - } - for { - nDst, nSrc, err := w.t.Transform(w.dst, src, false) - if _, werr := w.w.Write(w.dst[:nDst]); werr != nil { - return n, werr - } - src = src[nSrc:] - if w.n == 0 { - n += nSrc - } else if len(src) <= n { - // Enough bytes from w.src have been consumed. We make src point - // to data instead to reduce the copying. - w.n = 0 - n -= len(src) - src = data[n:] - if n < len(data) && (err == nil || err == ErrShortSrc) { - continue - } - } - switch err { - case ErrShortDst: - // This error is okay as long as we are making progress. - if nDst > 0 || nSrc > 0 { - continue - } - case ErrShortSrc: - if len(src) < len(w.src) { - m := copy(w.src, src) - // If w.n > 0, bytes from data were already copied to w.src and n - // was already set to the number of bytes consumed. - if w.n == 0 { - n += m - } - w.n = m - err = nil - } else if nDst > 0 || nSrc > 0 { - // Not enough buffer to store the remainder. Keep processing as - // long as there is progress. Without this case, transforms that - // require a lookahead larger than the buffer may result in an - // error. This is not something one may expect to be common in - // practice, but it may occur when buffers are set to small - // sizes during testing. - continue - } - case nil: - if w.n > 0 { - err = errInconsistentByteCount - } - } - return n, err - } -} - -// Close implements the io.Closer interface. -func (w *Writer) Close() error { - src := w.src[:w.n] - for { - nDst, nSrc, err := w.t.Transform(w.dst, src, true) - if _, werr := w.w.Write(w.dst[:nDst]); werr != nil { - return werr - } - if err != ErrShortDst { - return err - } - src = src[nSrc:] - } -} - -type nop struct{ NopResetter } - -func (nop) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - n := copy(dst, src) - if n < len(src) { - err = ErrShortDst - } - return n, n, err -} - -func (nop) Span(src []byte, atEOF bool) (n int, err error) { - return len(src), nil -} - -type discard struct{ NopResetter } - -func (discard) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - return 0, len(src), nil -} - -var ( - // Discard is a Transformer for which all Transform calls succeed - // by consuming all bytes and writing nothing. - Discard Transformer = discard{} - - // Nop is a SpanningTransformer that copies src to dst. - Nop SpanningTransformer = nop{} -) - -// chain is a sequence of links. A chain with N Transformers has N+1 links and -// N+1 buffers. Of those N+1 buffers, the first and last are the src and dst -// buffers given to chain.Transform and the middle N-1 buffers are intermediate -// buffers owned by the chain. The i'th link transforms bytes from the i'th -// buffer chain.link[i].b at read offset chain.link[i].p to the i+1'th buffer -// chain.link[i+1].b at write offset chain.link[i+1].n, for i in [0, N). -type chain struct { - link []link - err error - // errStart is the index at which the error occurred plus 1. Processing - // errStart at this level at the next call to Transform. As long as - // errStart > 0, chain will not consume any more source bytes. - errStart int -} - -func (c *chain) fatalError(errIndex int, err error) { - if i := errIndex + 1; i > c.errStart { - c.errStart = i - c.err = err - } -} - -type link struct { - t Transformer - // b[p:n] holds the bytes to be transformed by t. - b []byte - p int - n int -} - -func (l *link) src() []byte { - return l.b[l.p:l.n] -} - -func (l *link) dst() []byte { - return l.b[l.n:] -} - -// Chain returns a Transformer that applies t in sequence. -func Chain(t ...Transformer) Transformer { - if len(t) == 0 { - return nop{} - } - c := &chain{link: make([]link, len(t)+1)} - for i, tt := range t { - c.link[i].t = tt - } - // Allocate intermediate buffers. - b := make([][defaultBufSize]byte, len(t)-1) - for i := range b { - c.link[i+1].b = b[i][:] - } - return c -} - -// Reset resets the state of Chain. It calls Reset on all the Transformers. -func (c *chain) Reset() { - for i, l := range c.link { - if l.t != nil { - l.t.Reset() - } - c.link[i].p, c.link[i].n = 0, 0 - } -} - -// TODO: make chain use Span (is going to be fun to implement!) - -// Transform applies the transformers of c in sequence. -func (c *chain) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - // Set up src and dst in the chain. - srcL := &c.link[0] - dstL := &c.link[len(c.link)-1] - srcL.b, srcL.p, srcL.n = src, 0, len(src) - dstL.b, dstL.n = dst, 0 - var lastFull, needProgress bool // for detecting progress - - // i is the index of the next Transformer to apply, for i in [low, high]. - // low is the lowest index for which c.link[low] may still produce bytes. - // high is the highest index for which c.link[high] has a Transformer. - // The error returned by Transform determines whether to increase or - // decrease i. We try to completely fill a buffer before converting it. - for low, i, high := c.errStart, c.errStart, len(c.link)-2; low <= i && i <= high; { - in, out := &c.link[i], &c.link[i+1] - nDst, nSrc, err0 := in.t.Transform(out.dst(), in.src(), atEOF && low == i) - out.n += nDst - in.p += nSrc - if i > 0 && in.p == in.n { - in.p, in.n = 0, 0 - } - needProgress, lastFull = lastFull, false - switch err0 { - case ErrShortDst: - // Process the destination buffer next. Return if we are already - // at the high index. - if i == high { - return dstL.n, srcL.p, ErrShortDst - } - if out.n != 0 { - i++ - // If the Transformer at the next index is not able to process any - // source bytes there is nothing that can be done to make progress - // and the bytes will remain unprocessed. lastFull is used to - // detect this and break out of the loop with a fatal error. - lastFull = true - continue - } - // The destination buffer was too small, but is completely empty. - // Return a fatal error as this transformation can never complete. - c.fatalError(i, errShortInternal) - case ErrShortSrc: - if i == 0 { - // Save ErrShortSrc in err. All other errors take precedence. - err = ErrShortSrc - break - } - // Source bytes were depleted before filling up the destination buffer. - // Verify we made some progress, move the remaining bytes to the errStart - // and try to get more source bytes. - if needProgress && nSrc == 0 || in.n-in.p == len(in.b) { - // There were not enough source bytes to proceed while the source - // buffer cannot hold any more bytes. Return a fatal error as this - // transformation can never complete. - c.fatalError(i, errShortInternal) - break - } - // in.b is an internal buffer and we can make progress. - in.p, in.n = 0, copy(in.b, in.src()) - fallthrough - case nil: - // if i == low, we have depleted the bytes at index i or any lower levels. - // In that case we increase low and i. In all other cases we decrease i to - // fetch more bytes before proceeding to the next index. - if i > low { - i-- - continue - } - default: - c.fatalError(i, err0) - } - // Exhausted level low or fatal error: increase low and continue - // to process the bytes accepted so far. - i++ - low = i - } - - // If c.errStart > 0, this means we found a fatal error. We will clear - // all upstream buffers. At this point, no more progress can be made - // downstream, as Transform would have bailed while handling ErrShortDst. - if c.errStart > 0 { - for i := 1; i < c.errStart; i++ { - c.link[i].p, c.link[i].n = 0, 0 - } - err, c.errStart, c.err = c.err, 0, nil - } - return dstL.n, srcL.p, err -} - -// Deprecated: Use runes.Remove instead. -func RemoveFunc(f func(r rune) bool) Transformer { - return removeF(f) -} - -type removeF func(r rune) bool - -func (removeF) Reset() {} - -// Transform implements the Transformer interface. -func (t removeF) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { - for r, sz := rune(0), 0; len(src) > 0; src = src[sz:] { - - if r = rune(src[0]); r < utf8.RuneSelf { - sz = 1 - } else { - r, sz = utf8.DecodeRune(src) - - if sz == 1 { - // Invalid rune. - if !atEOF && !utf8.FullRune(src) { - err = ErrShortSrc - break - } - // We replace illegal bytes with RuneError. Not doing so might - // otherwise turn a sequence of invalid UTF-8 into valid UTF-8. - // The resulting byte sequence may subsequently contain runes - // for which t(r) is true that were passed unnoticed. - if !t(r) { - if nDst+3 > len(dst) { - err = ErrShortDst - break - } - nDst += copy(dst[nDst:], "\uFFFD") - } - nSrc++ - continue - } - } - - if !t(r) { - if nDst+sz > len(dst) { - err = ErrShortDst - break - } - nDst += copy(dst[nDst:], src[:sz]) - } - nSrc += sz - } - return -} - -// grow returns a new []byte that is longer than b, and copies the first n bytes -// of b to the start of the new slice. -func grow(b []byte, n int) []byte { - m := len(b) - if m <= 32 { - m = 64 - } else if m <= 256 { - m *= 2 - } else { - m += m >> 1 - } - buf := make([]byte, m) - copy(buf, b[:n]) - return buf -} - -const initialBufSize = 128 - -// String returns a string with the result of converting s[:n] using t, where -// n <= len(s). If err == nil, n will be len(s). It calls Reset on t. -func String(t Transformer, s string) (result string, n int, err error) { - t.Reset() - if s == "" { - // Fast path for the common case for empty input. Results in about a - // 86% reduction of running time for BenchmarkStringLowerEmpty. - if _, _, err := t.Transform(nil, nil, true); err == nil { - return "", 0, nil - } - } - - // Allocate only once. Note that both dst and src escape when passed to - // Transform. - buf := [2 * initialBufSize]byte{} - dst := buf[:initialBufSize:initialBufSize] - src := buf[initialBufSize : 2*initialBufSize] - - // The input string s is transformed in multiple chunks (starting with a - // chunk size of initialBufSize). nDst and nSrc are per-chunk (or - // per-Transform-call) indexes, pDst and pSrc are overall indexes. - nDst, nSrc := 0, 0 - pDst, pSrc := 0, 0 - - // pPrefix is the length of a common prefix: the first pPrefix bytes of the - // result will equal the first pPrefix bytes of s. It is not guaranteed to - // be the largest such value, but if pPrefix, len(result) and len(s) are - // all equal after the final transform (i.e. calling Transform with atEOF - // being true returned nil error) then we don't need to allocate a new - // result string. - pPrefix := 0 - for { - // Invariant: pDst == pPrefix && pSrc == pPrefix. - - n := copy(src, s[pSrc:]) - nDst, nSrc, err = t.Transform(dst, src[:n], pSrc+n == len(s)) - pDst += nDst - pSrc += nSrc - - // TODO: let transformers implement an optional Spanner interface, akin - // to norm's QuickSpan. This would even allow us to avoid any allocation. - if !bytes.Equal(dst[:nDst], src[:nSrc]) { - break - } - pPrefix = pSrc - if err == ErrShortDst { - // A buffer can only be short if a transformer modifies its input. - break - } else if err == ErrShortSrc { - if nSrc == 0 { - // No progress was made. - break - } - // Equal so far and !atEOF, so continue checking. - } else if err != nil || pPrefix == len(s) { - return string(s[:pPrefix]), pPrefix, err - } - } - // Post-condition: pDst == pPrefix + nDst && pSrc == pPrefix + nSrc. - - // We have transformed the first pSrc bytes of the input s to become pDst - // transformed bytes. Those transformed bytes are discontiguous: the first - // pPrefix of them equal s[:pPrefix] and the last nDst of them equal - // dst[:nDst]. We copy them around, into a new dst buffer if necessary, so - // that they become one contiguous slice: dst[:pDst]. - if pPrefix != 0 { - newDst := dst - if pDst > len(newDst) { - newDst = make([]byte, len(s)+nDst-nSrc) - } - copy(newDst[pPrefix:pDst], dst[:nDst]) - copy(newDst[:pPrefix], s[:pPrefix]) - dst = newDst - } - - // Prevent duplicate Transform calls with atEOF being true at the end of - // the input. Also return if we have an unrecoverable error. - if (err == nil && pSrc == len(s)) || - (err != nil && err != ErrShortDst && err != ErrShortSrc) { - return string(dst[:pDst]), pSrc, err - } - - // Transform the remaining input, growing dst and src buffers as necessary. - for { - n := copy(src, s[pSrc:]) - atEOF := pSrc+n == len(s) - nDst, nSrc, err := t.Transform(dst[pDst:], src[:n], atEOF) - pDst += nDst - pSrc += nSrc - - // If we got ErrShortDst or ErrShortSrc, do not grow as long as we can - // make progress. This may avoid excessive allocations. - if err == ErrShortDst { - if nDst == 0 { - dst = grow(dst, pDst) - } - } else if err == ErrShortSrc { - if atEOF { - return string(dst[:pDst]), pSrc, err - } - if nSrc == 0 { - src = grow(src, 0) - } - } else if err != nil || pSrc == len(s) { - return string(dst[:pDst]), pSrc, err - } - } -} - -// Bytes returns a new byte slice with the result of converting b[:n] using t, -// where n <= len(b). If err == nil, n will be len(b). It calls Reset on t. -func Bytes(t Transformer, b []byte) (result []byte, n int, err error) { - return doAppend(t, 0, make([]byte, len(b)), b) -} - -// Append appends the result of converting src[:n] using t to dst, where -// n <= len(src), If err == nil, n will be len(src). It calls Reset on t. -func Append(t Transformer, dst, src []byte) (result []byte, n int, err error) { - if len(dst) == cap(dst) { - n := len(src) + len(dst) // It is okay for this to be 0. - b := make([]byte, n) - dst = b[:copy(b, dst)] - } - return doAppend(t, len(dst), dst[:cap(dst)], src) -} - -func doAppend(t Transformer, pDst int, dst, src []byte) (result []byte, n int, err error) { - t.Reset() - pSrc := 0 - for { - nDst, nSrc, err := t.Transform(dst[pDst:], src[pSrc:], true) - pDst += nDst - pSrc += nSrc - if err != ErrShortDst { - return dst[:pDst], pSrc, err - } - - // Grow the destination buffer, but do not grow as long as we can make - // progress. This may avoid excessive allocations. - if nDst == 0 { - dst = grow(dst, pDst) - } - } -} diff --git a/vendor/gopkg.in/yaml.v2/.travis.yml b/vendor/gopkg.in/yaml.v2/.travis.yml deleted file mode 100644 index 7348c50..0000000 --- a/vendor/gopkg.in/yaml.v2/.travis.yml +++ /dev/null @@ -1,17 +0,0 @@ -language: go - -go: - - "1.4.x" - - "1.5.x" - - "1.6.x" - - "1.7.x" - - "1.8.x" - - "1.9.x" - - "1.10.x" - - "1.11.x" - - "1.12.x" - - "1.13.x" - - "1.14.x" - - "tip" - -go_import_path: gopkg.in/yaml.v2 diff --git a/vendor/gopkg.in/yaml.v2/LICENSE b/vendor/gopkg.in/yaml.v2/LICENSE deleted file mode 100644 index 8dada3e..0000000 --- a/vendor/gopkg.in/yaml.v2/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/vendor/gopkg.in/yaml.v2/LICENSE.libyaml b/vendor/gopkg.in/yaml.v2/LICENSE.libyaml deleted file mode 100644 index 8da58fb..0000000 --- a/vendor/gopkg.in/yaml.v2/LICENSE.libyaml +++ /dev/null @@ -1,31 +0,0 @@ -The following files were ported to Go from C files of libyaml, and thus -are still covered by their original copyright and license: - - apic.go - emitterc.go - parserc.go - readerc.go - scannerc.go - writerc.go - yamlh.go - yamlprivateh.go - -Copyright (c) 2006 Kirill Simonov - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/gopkg.in/yaml.v2/NOTICE b/vendor/gopkg.in/yaml.v2/NOTICE deleted file mode 100644 index 866d74a..0000000 --- a/vendor/gopkg.in/yaml.v2/NOTICE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2011-2016 Canonical Ltd. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/vendor/gopkg.in/yaml.v2/README.md b/vendor/gopkg.in/yaml.v2/README.md deleted file mode 100644 index b50c6e8..0000000 --- a/vendor/gopkg.in/yaml.v2/README.md +++ /dev/null @@ -1,133 +0,0 @@ -# YAML support for the Go language - -Introduction ------------- - -The yaml package enables Go programs to comfortably encode and decode YAML -values. It was developed within [Canonical](https://www.canonical.com) as -part of the [juju](https://juju.ubuntu.com) project, and is based on a -pure Go port of the well-known [libyaml](http://pyyaml.org/wiki/LibYAML) -C library to parse and generate YAML data quickly and reliably. - -Compatibility -------------- - -The yaml package supports most of YAML 1.1 and 1.2, including support for -anchors, tags, map merging, etc. Multi-document unmarshalling is not yet -implemented, and base-60 floats from YAML 1.1 are purposefully not -supported since they're a poor design and are gone in YAML 1.2. - -Installation and usage ----------------------- - -The import path for the package is *gopkg.in/yaml.v2*. - -To install it, run: - - go get gopkg.in/yaml.v2 - -API documentation ------------------ - -If opened in a browser, the import path itself leads to the API documentation: - - * [https://gopkg.in/yaml.v2](https://gopkg.in/yaml.v2) - -API stability -------------- - -The package API for yaml v2 will remain stable as described in [gopkg.in](https://gopkg.in). - - -License -------- - -The yaml package is licensed under the Apache License 2.0. Please see the LICENSE file for details. - - -Example -------- - -```Go -package main - -import ( - "fmt" - "log" - - "gopkg.in/yaml.v2" -) - -var data = ` -a: Easy! -b: - c: 2 - d: [3, 4] -` - -// Note: struct fields must be public in order for unmarshal to -// correctly populate the data. -type T struct { - A string - B struct { - RenamedC int `yaml:"c"` - D []int `yaml:",flow"` - } -} - -func main() { - t := T{} - - err := yaml.Unmarshal([]byte(data), &t) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- t:\n%v\n\n", t) - - d, err := yaml.Marshal(&t) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- t dump:\n%s\n\n", string(d)) - - m := make(map[interface{}]interface{}) - - err = yaml.Unmarshal([]byte(data), &m) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- m:\n%v\n\n", m) - - d, err = yaml.Marshal(&m) - if err != nil { - log.Fatalf("error: %v", err) - } - fmt.Printf("--- m dump:\n%s\n\n", string(d)) -} -``` - -This example will generate the following output: - -``` ---- t: -{Easy! {2 [3 4]}} - ---- t dump: -a: Easy! -b: - c: 2 - d: [3, 4] - - ---- m: -map[a:Easy! b:map[c:2 d:[3 4]]] - ---- m dump: -a: Easy! -b: - c: 2 - d: - - 3 - - 4 -``` - diff --git a/vendor/gopkg.in/yaml.v2/apic.go b/vendor/gopkg.in/yaml.v2/apic.go deleted file mode 100644 index acf7140..0000000 --- a/vendor/gopkg.in/yaml.v2/apic.go +++ /dev/null @@ -1,744 +0,0 @@ -package yaml - -import ( - "io" -) - -func yaml_insert_token(parser *yaml_parser_t, pos int, token *yaml_token_t) { - //fmt.Println("yaml_insert_token", "pos:", pos, "typ:", token.typ, "head:", parser.tokens_head, "len:", len(parser.tokens)) - - // Check if we can move the queue at the beginning of the buffer. - if parser.tokens_head > 0 && len(parser.tokens) == cap(parser.tokens) { - if parser.tokens_head != len(parser.tokens) { - copy(parser.tokens, parser.tokens[parser.tokens_head:]) - } - parser.tokens = parser.tokens[:len(parser.tokens)-parser.tokens_head] - parser.tokens_head = 0 - } - parser.tokens = append(parser.tokens, *token) - if pos < 0 { - return - } - copy(parser.tokens[parser.tokens_head+pos+1:], parser.tokens[parser.tokens_head+pos:]) - parser.tokens[parser.tokens_head+pos] = *token -} - -// Create a new parser object. -func yaml_parser_initialize(parser *yaml_parser_t) bool { - *parser = yaml_parser_t{ - raw_buffer: make([]byte, 0, input_raw_buffer_size), - buffer: make([]byte, 0, input_buffer_size), - } - return true -} - -// Destroy a parser object. -func yaml_parser_delete(parser *yaml_parser_t) { - *parser = yaml_parser_t{} -} - -// String read handler. -func yaml_string_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) { - if parser.input_pos == len(parser.input) { - return 0, io.EOF - } - n = copy(buffer, parser.input[parser.input_pos:]) - parser.input_pos += n - return n, nil -} - -// Reader read handler. -func yaml_reader_read_handler(parser *yaml_parser_t, buffer []byte) (n int, err error) { - return parser.input_reader.Read(buffer) -} - -// Set a string input. -func yaml_parser_set_input_string(parser *yaml_parser_t, input []byte) { - if parser.read_handler != nil { - panic("must set the input source only once") - } - parser.read_handler = yaml_string_read_handler - parser.input = input - parser.input_pos = 0 -} - -// Set a file input. -func yaml_parser_set_input_reader(parser *yaml_parser_t, r io.Reader) { - if parser.read_handler != nil { - panic("must set the input source only once") - } - parser.read_handler = yaml_reader_read_handler - parser.input_reader = r -} - -// Set the source encoding. -func yaml_parser_set_encoding(parser *yaml_parser_t, encoding yaml_encoding_t) { - if parser.encoding != yaml_ANY_ENCODING { - panic("must set the encoding only once") - } - parser.encoding = encoding -} - -var disableLineWrapping = false - -// Create a new emitter object. -func yaml_emitter_initialize(emitter *yaml_emitter_t) { - *emitter = yaml_emitter_t{ - buffer: make([]byte, output_buffer_size), - raw_buffer: make([]byte, 0, output_raw_buffer_size), - states: make([]yaml_emitter_state_t, 0, initial_stack_size), - events: make([]yaml_event_t, 0, initial_queue_size), - } - if disableLineWrapping { - emitter.best_width = -1 - } -} - -// Destroy an emitter object. -func yaml_emitter_delete(emitter *yaml_emitter_t) { - *emitter = yaml_emitter_t{} -} - -// String write handler. -func yaml_string_write_handler(emitter *yaml_emitter_t, buffer []byte) error { - *emitter.output_buffer = append(*emitter.output_buffer, buffer...) - return nil -} - -// yaml_writer_write_handler uses emitter.output_writer to write the -// emitted text. -func yaml_writer_write_handler(emitter *yaml_emitter_t, buffer []byte) error { - _, err := emitter.output_writer.Write(buffer) - return err -} - -// Set a string output. -func yaml_emitter_set_output_string(emitter *yaml_emitter_t, output_buffer *[]byte) { - if emitter.write_handler != nil { - panic("must set the output target only once") - } - emitter.write_handler = yaml_string_write_handler - emitter.output_buffer = output_buffer -} - -// Set a file output. -func yaml_emitter_set_output_writer(emitter *yaml_emitter_t, w io.Writer) { - if emitter.write_handler != nil { - panic("must set the output target only once") - } - emitter.write_handler = yaml_writer_write_handler - emitter.output_writer = w -} - -// Set the output encoding. -func yaml_emitter_set_encoding(emitter *yaml_emitter_t, encoding yaml_encoding_t) { - if emitter.encoding != yaml_ANY_ENCODING { - panic("must set the output encoding only once") - } - emitter.encoding = encoding -} - -// Set the canonical output style. -func yaml_emitter_set_canonical(emitter *yaml_emitter_t, canonical bool) { - emitter.canonical = canonical -} - -//// Set the indentation increment. -func yaml_emitter_set_indent(emitter *yaml_emitter_t, indent int) { - if indent < 2 || indent > 9 { - indent = 2 - } - emitter.best_indent = indent -} - -// Set the preferred line width. -func yaml_emitter_set_width(emitter *yaml_emitter_t, width int) { - if width < 0 { - width = -1 - } - emitter.best_width = width -} - -// Set if unescaped non-ASCII characters are allowed. -func yaml_emitter_set_unicode(emitter *yaml_emitter_t, unicode bool) { - emitter.unicode = unicode -} - -// Set the preferred line break character. -func yaml_emitter_set_break(emitter *yaml_emitter_t, line_break yaml_break_t) { - emitter.line_break = line_break -} - -///* -// * Destroy a token object. -// */ -// -//YAML_DECLARE(void) -//yaml_token_delete(yaml_token_t *token) -//{ -// assert(token); // Non-NULL token object expected. -// -// switch (token.type) -// { -// case YAML_TAG_DIRECTIVE_TOKEN: -// yaml_free(token.data.tag_directive.handle); -// yaml_free(token.data.tag_directive.prefix); -// break; -// -// case YAML_ALIAS_TOKEN: -// yaml_free(token.data.alias.value); -// break; -// -// case YAML_ANCHOR_TOKEN: -// yaml_free(token.data.anchor.value); -// break; -// -// case YAML_TAG_TOKEN: -// yaml_free(token.data.tag.handle); -// yaml_free(token.data.tag.suffix); -// break; -// -// case YAML_SCALAR_TOKEN: -// yaml_free(token.data.scalar.value); -// break; -// -// default: -// break; -// } -// -// memset(token, 0, sizeof(yaml_token_t)); -//} -// -///* -// * Check if a string is a valid UTF-8 sequence. -// * -// * Check 'reader.c' for more details on UTF-8 encoding. -// */ -// -//static int -//yaml_check_utf8(yaml_char_t *start, size_t length) -//{ -// yaml_char_t *end = start+length; -// yaml_char_t *pointer = start; -// -// while (pointer < end) { -// unsigned char octet; -// unsigned int width; -// unsigned int value; -// size_t k; -// -// octet = pointer[0]; -// width = (octet & 0x80) == 0x00 ? 1 : -// (octet & 0xE0) == 0xC0 ? 2 : -// (octet & 0xF0) == 0xE0 ? 3 : -// (octet & 0xF8) == 0xF0 ? 4 : 0; -// value = (octet & 0x80) == 0x00 ? octet & 0x7F : -// (octet & 0xE0) == 0xC0 ? octet & 0x1F : -// (octet & 0xF0) == 0xE0 ? octet & 0x0F : -// (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0; -// if (!width) return 0; -// if (pointer+width > end) return 0; -// for (k = 1; k < width; k ++) { -// octet = pointer[k]; -// if ((octet & 0xC0) != 0x80) return 0; -// value = (value << 6) + (octet & 0x3F); -// } -// if (!((width == 1) || -// (width == 2 && value >= 0x80) || -// (width == 3 && value >= 0x800) || -// (width == 4 && value >= 0x10000))) return 0; -// -// pointer += width; -// } -// -// return 1; -//} -// - -// Create STREAM-START. -func yaml_stream_start_event_initialize(event *yaml_event_t, encoding yaml_encoding_t) { - *event = yaml_event_t{ - typ: yaml_STREAM_START_EVENT, - encoding: encoding, - } -} - -// Create STREAM-END. -func yaml_stream_end_event_initialize(event *yaml_event_t) { - *event = yaml_event_t{ - typ: yaml_STREAM_END_EVENT, - } -} - -// Create DOCUMENT-START. -func yaml_document_start_event_initialize( - event *yaml_event_t, - version_directive *yaml_version_directive_t, - tag_directives []yaml_tag_directive_t, - implicit bool, -) { - *event = yaml_event_t{ - typ: yaml_DOCUMENT_START_EVENT, - version_directive: version_directive, - tag_directives: tag_directives, - implicit: implicit, - } -} - -// Create DOCUMENT-END. -func yaml_document_end_event_initialize(event *yaml_event_t, implicit bool) { - *event = yaml_event_t{ - typ: yaml_DOCUMENT_END_EVENT, - implicit: implicit, - } -} - -///* -// * Create ALIAS. -// */ -// -//YAML_DECLARE(int) -//yaml_alias_event_initialize(event *yaml_event_t, anchor *yaml_char_t) -//{ -// mark yaml_mark_t = { 0, 0, 0 } -// anchor_copy *yaml_char_t = NULL -// -// assert(event) // Non-NULL event object is expected. -// assert(anchor) // Non-NULL anchor is expected. -// -// if (!yaml_check_utf8(anchor, strlen((char *)anchor))) return 0 -// -// anchor_copy = yaml_strdup(anchor) -// if (!anchor_copy) -// return 0 -// -// ALIAS_EVENT_INIT(*event, anchor_copy, mark, mark) -// -// return 1 -//} - -// Create SCALAR. -func yaml_scalar_event_initialize(event *yaml_event_t, anchor, tag, value []byte, plain_implicit, quoted_implicit bool, style yaml_scalar_style_t) bool { - *event = yaml_event_t{ - typ: yaml_SCALAR_EVENT, - anchor: anchor, - tag: tag, - value: value, - implicit: plain_implicit, - quoted_implicit: quoted_implicit, - style: yaml_style_t(style), - } - return true -} - -// Create SEQUENCE-START. -func yaml_sequence_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_sequence_style_t) bool { - *event = yaml_event_t{ - typ: yaml_SEQUENCE_START_EVENT, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(style), - } - return true -} - -// Create SEQUENCE-END. -func yaml_sequence_end_event_initialize(event *yaml_event_t) bool { - *event = yaml_event_t{ - typ: yaml_SEQUENCE_END_EVENT, - } - return true -} - -// Create MAPPING-START. -func yaml_mapping_start_event_initialize(event *yaml_event_t, anchor, tag []byte, implicit bool, style yaml_mapping_style_t) { - *event = yaml_event_t{ - typ: yaml_MAPPING_START_EVENT, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(style), - } -} - -// Create MAPPING-END. -func yaml_mapping_end_event_initialize(event *yaml_event_t) { - *event = yaml_event_t{ - typ: yaml_MAPPING_END_EVENT, - } -} - -// Destroy an event object. -func yaml_event_delete(event *yaml_event_t) { - *event = yaml_event_t{} -} - -///* -// * Create a document object. -// */ -// -//YAML_DECLARE(int) -//yaml_document_initialize(document *yaml_document_t, -// version_directive *yaml_version_directive_t, -// tag_directives_start *yaml_tag_directive_t, -// tag_directives_end *yaml_tag_directive_t, -// start_implicit int, end_implicit int) -//{ -// struct { -// error yaml_error_type_t -// } context -// struct { -// start *yaml_node_t -// end *yaml_node_t -// top *yaml_node_t -// } nodes = { NULL, NULL, NULL } -// version_directive_copy *yaml_version_directive_t = NULL -// struct { -// start *yaml_tag_directive_t -// end *yaml_tag_directive_t -// top *yaml_tag_directive_t -// } tag_directives_copy = { NULL, NULL, NULL } -// value yaml_tag_directive_t = { NULL, NULL } -// mark yaml_mark_t = { 0, 0, 0 } -// -// assert(document) // Non-NULL document object is expected. -// assert((tag_directives_start && tag_directives_end) || -// (tag_directives_start == tag_directives_end)) -// // Valid tag directives are expected. -// -// if (!STACK_INIT(&context, nodes, INITIAL_STACK_SIZE)) goto error -// -// if (version_directive) { -// version_directive_copy = yaml_malloc(sizeof(yaml_version_directive_t)) -// if (!version_directive_copy) goto error -// version_directive_copy.major = version_directive.major -// version_directive_copy.minor = version_directive.minor -// } -// -// if (tag_directives_start != tag_directives_end) { -// tag_directive *yaml_tag_directive_t -// if (!STACK_INIT(&context, tag_directives_copy, INITIAL_STACK_SIZE)) -// goto error -// for (tag_directive = tag_directives_start -// tag_directive != tag_directives_end; tag_directive ++) { -// assert(tag_directive.handle) -// assert(tag_directive.prefix) -// if (!yaml_check_utf8(tag_directive.handle, -// strlen((char *)tag_directive.handle))) -// goto error -// if (!yaml_check_utf8(tag_directive.prefix, -// strlen((char *)tag_directive.prefix))) -// goto error -// value.handle = yaml_strdup(tag_directive.handle) -// value.prefix = yaml_strdup(tag_directive.prefix) -// if (!value.handle || !value.prefix) goto error -// if (!PUSH(&context, tag_directives_copy, value)) -// goto error -// value.handle = NULL -// value.prefix = NULL -// } -// } -// -// DOCUMENT_INIT(*document, nodes.start, nodes.end, version_directive_copy, -// tag_directives_copy.start, tag_directives_copy.top, -// start_implicit, end_implicit, mark, mark) -// -// return 1 -// -//error: -// STACK_DEL(&context, nodes) -// yaml_free(version_directive_copy) -// while (!STACK_EMPTY(&context, tag_directives_copy)) { -// value yaml_tag_directive_t = POP(&context, tag_directives_copy) -// yaml_free(value.handle) -// yaml_free(value.prefix) -// } -// STACK_DEL(&context, tag_directives_copy) -// yaml_free(value.handle) -// yaml_free(value.prefix) -// -// return 0 -//} -// -///* -// * Destroy a document object. -// */ -// -//YAML_DECLARE(void) -//yaml_document_delete(document *yaml_document_t) -//{ -// struct { -// error yaml_error_type_t -// } context -// tag_directive *yaml_tag_directive_t -// -// context.error = YAML_NO_ERROR // Eliminate a compiler warning. -// -// assert(document) // Non-NULL document object is expected. -// -// while (!STACK_EMPTY(&context, document.nodes)) { -// node yaml_node_t = POP(&context, document.nodes) -// yaml_free(node.tag) -// switch (node.type) { -// case YAML_SCALAR_NODE: -// yaml_free(node.data.scalar.value) -// break -// case YAML_SEQUENCE_NODE: -// STACK_DEL(&context, node.data.sequence.items) -// break -// case YAML_MAPPING_NODE: -// STACK_DEL(&context, node.data.mapping.pairs) -// break -// default: -// assert(0) // Should not happen. -// } -// } -// STACK_DEL(&context, document.nodes) -// -// yaml_free(document.version_directive) -// for (tag_directive = document.tag_directives.start -// tag_directive != document.tag_directives.end -// tag_directive++) { -// yaml_free(tag_directive.handle) -// yaml_free(tag_directive.prefix) -// } -// yaml_free(document.tag_directives.start) -// -// memset(document, 0, sizeof(yaml_document_t)) -//} -// -///** -// * Get a document node. -// */ -// -//YAML_DECLARE(yaml_node_t *) -//yaml_document_get_node(document *yaml_document_t, index int) -//{ -// assert(document) // Non-NULL document object is expected. -// -// if (index > 0 && document.nodes.start + index <= document.nodes.top) { -// return document.nodes.start + index - 1 -// } -// return NULL -//} -// -///** -// * Get the root object. -// */ -// -//YAML_DECLARE(yaml_node_t *) -//yaml_document_get_root_node(document *yaml_document_t) -//{ -// assert(document) // Non-NULL document object is expected. -// -// if (document.nodes.top != document.nodes.start) { -// return document.nodes.start -// } -// return NULL -//} -// -///* -// * Add a scalar node to a document. -// */ -// -//YAML_DECLARE(int) -//yaml_document_add_scalar(document *yaml_document_t, -// tag *yaml_char_t, value *yaml_char_t, length int, -// style yaml_scalar_style_t) -//{ -// struct { -// error yaml_error_type_t -// } context -// mark yaml_mark_t = { 0, 0, 0 } -// tag_copy *yaml_char_t = NULL -// value_copy *yaml_char_t = NULL -// node yaml_node_t -// -// assert(document) // Non-NULL document object is expected. -// assert(value) // Non-NULL value is expected. -// -// if (!tag) { -// tag = (yaml_char_t *)YAML_DEFAULT_SCALAR_TAG -// } -// -// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error -// tag_copy = yaml_strdup(tag) -// if (!tag_copy) goto error -// -// if (length < 0) { -// length = strlen((char *)value) -// } -// -// if (!yaml_check_utf8(value, length)) goto error -// value_copy = yaml_malloc(length+1) -// if (!value_copy) goto error -// memcpy(value_copy, value, length) -// value_copy[length] = '\0' -// -// SCALAR_NODE_INIT(node, tag_copy, value_copy, length, style, mark, mark) -// if (!PUSH(&context, document.nodes, node)) goto error -// -// return document.nodes.top - document.nodes.start -// -//error: -// yaml_free(tag_copy) -// yaml_free(value_copy) -// -// return 0 -//} -// -///* -// * Add a sequence node to a document. -// */ -// -//YAML_DECLARE(int) -//yaml_document_add_sequence(document *yaml_document_t, -// tag *yaml_char_t, style yaml_sequence_style_t) -//{ -// struct { -// error yaml_error_type_t -// } context -// mark yaml_mark_t = { 0, 0, 0 } -// tag_copy *yaml_char_t = NULL -// struct { -// start *yaml_node_item_t -// end *yaml_node_item_t -// top *yaml_node_item_t -// } items = { NULL, NULL, NULL } -// node yaml_node_t -// -// assert(document) // Non-NULL document object is expected. -// -// if (!tag) { -// tag = (yaml_char_t *)YAML_DEFAULT_SEQUENCE_TAG -// } -// -// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error -// tag_copy = yaml_strdup(tag) -// if (!tag_copy) goto error -// -// if (!STACK_INIT(&context, items, INITIAL_STACK_SIZE)) goto error -// -// SEQUENCE_NODE_INIT(node, tag_copy, items.start, items.end, -// style, mark, mark) -// if (!PUSH(&context, document.nodes, node)) goto error -// -// return document.nodes.top - document.nodes.start -// -//error: -// STACK_DEL(&context, items) -// yaml_free(tag_copy) -// -// return 0 -//} -// -///* -// * Add a mapping node to a document. -// */ -// -//YAML_DECLARE(int) -//yaml_document_add_mapping(document *yaml_document_t, -// tag *yaml_char_t, style yaml_mapping_style_t) -//{ -// struct { -// error yaml_error_type_t -// } context -// mark yaml_mark_t = { 0, 0, 0 } -// tag_copy *yaml_char_t = NULL -// struct { -// start *yaml_node_pair_t -// end *yaml_node_pair_t -// top *yaml_node_pair_t -// } pairs = { NULL, NULL, NULL } -// node yaml_node_t -// -// assert(document) // Non-NULL document object is expected. -// -// if (!tag) { -// tag = (yaml_char_t *)YAML_DEFAULT_MAPPING_TAG -// } -// -// if (!yaml_check_utf8(tag, strlen((char *)tag))) goto error -// tag_copy = yaml_strdup(tag) -// if (!tag_copy) goto error -// -// if (!STACK_INIT(&context, pairs, INITIAL_STACK_SIZE)) goto error -// -// MAPPING_NODE_INIT(node, tag_copy, pairs.start, pairs.end, -// style, mark, mark) -// if (!PUSH(&context, document.nodes, node)) goto error -// -// return document.nodes.top - document.nodes.start -// -//error: -// STACK_DEL(&context, pairs) -// yaml_free(tag_copy) -// -// return 0 -//} -// -///* -// * Append an item to a sequence node. -// */ -// -//YAML_DECLARE(int) -//yaml_document_append_sequence_item(document *yaml_document_t, -// sequence int, item int) -//{ -// struct { -// error yaml_error_type_t -// } context -// -// assert(document) // Non-NULL document is required. -// assert(sequence > 0 -// && document.nodes.start + sequence <= document.nodes.top) -// // Valid sequence id is required. -// assert(document.nodes.start[sequence-1].type == YAML_SEQUENCE_NODE) -// // A sequence node is required. -// assert(item > 0 && document.nodes.start + item <= document.nodes.top) -// // Valid item id is required. -// -// if (!PUSH(&context, -// document.nodes.start[sequence-1].data.sequence.items, item)) -// return 0 -// -// return 1 -//} -// -///* -// * Append a pair of a key and a value to a mapping node. -// */ -// -//YAML_DECLARE(int) -//yaml_document_append_mapping_pair(document *yaml_document_t, -// mapping int, key int, value int) -//{ -// struct { -// error yaml_error_type_t -// } context -// -// pair yaml_node_pair_t -// -// assert(document) // Non-NULL document is required. -// assert(mapping > 0 -// && document.nodes.start + mapping <= document.nodes.top) -// // Valid mapping id is required. -// assert(document.nodes.start[mapping-1].type == YAML_MAPPING_NODE) -// // A mapping node is required. -// assert(key > 0 && document.nodes.start + key <= document.nodes.top) -// // Valid key id is required. -// assert(value > 0 && document.nodes.start + value <= document.nodes.top) -// // Valid value id is required. -// -// pair.key = key -// pair.value = value -// -// if (!PUSH(&context, -// document.nodes.start[mapping-1].data.mapping.pairs, pair)) -// return 0 -// -// return 1 -//} -// -// diff --git a/vendor/gopkg.in/yaml.v2/decode.go b/vendor/gopkg.in/yaml.v2/decode.go deleted file mode 100644 index 129bc2a..0000000 --- a/vendor/gopkg.in/yaml.v2/decode.go +++ /dev/null @@ -1,815 +0,0 @@ -package yaml - -import ( - "encoding" - "encoding/base64" - "fmt" - "io" - "math" - "reflect" - "strconv" - "time" -) - -const ( - documentNode = 1 << iota - mappingNode - sequenceNode - scalarNode - aliasNode -) - -type node struct { - kind int - line, column int - tag string - // For an alias node, alias holds the resolved alias. - alias *node - value string - implicit bool - children []*node - anchors map[string]*node -} - -// ---------------------------------------------------------------------------- -// Parser, produces a node tree out of a libyaml event stream. - -type parser struct { - parser yaml_parser_t - event yaml_event_t - doc *node - doneInit bool -} - -func newParser(b []byte) *parser { - p := parser{} - if !yaml_parser_initialize(&p.parser) { - panic("failed to initialize YAML emitter") - } - if len(b) == 0 { - b = []byte{'\n'} - } - yaml_parser_set_input_string(&p.parser, b) - return &p -} - -func newParserFromReader(r io.Reader) *parser { - p := parser{} - if !yaml_parser_initialize(&p.parser) { - panic("failed to initialize YAML emitter") - } - yaml_parser_set_input_reader(&p.parser, r) - return &p -} - -func (p *parser) init() { - if p.doneInit { - return - } - p.expect(yaml_STREAM_START_EVENT) - p.doneInit = true -} - -func (p *parser) destroy() { - if p.event.typ != yaml_NO_EVENT { - yaml_event_delete(&p.event) - } - yaml_parser_delete(&p.parser) -} - -// expect consumes an event from the event stream and -// checks that it's of the expected type. -func (p *parser) expect(e yaml_event_type_t) { - if p.event.typ == yaml_NO_EVENT { - if !yaml_parser_parse(&p.parser, &p.event) { - p.fail() - } - } - if p.event.typ == yaml_STREAM_END_EVENT { - failf("attempted to go past the end of stream; corrupted value?") - } - if p.event.typ != e { - p.parser.problem = fmt.Sprintf("expected %s event but got %s", e, p.event.typ) - p.fail() - } - yaml_event_delete(&p.event) - p.event.typ = yaml_NO_EVENT -} - -// peek peeks at the next event in the event stream, -// puts the results into p.event and returns the event type. -func (p *parser) peek() yaml_event_type_t { - if p.event.typ != yaml_NO_EVENT { - return p.event.typ - } - if !yaml_parser_parse(&p.parser, &p.event) { - p.fail() - } - return p.event.typ -} - -func (p *parser) fail() { - var where string - var line int - if p.parser.problem_mark.line != 0 { - line = p.parser.problem_mark.line - // Scanner errors don't iterate line before returning error - if p.parser.error == yaml_SCANNER_ERROR { - line++ - } - } else if p.parser.context_mark.line != 0 { - line = p.parser.context_mark.line - } - if line != 0 { - where = "line " + strconv.Itoa(line) + ": " - } - var msg string - if len(p.parser.problem) > 0 { - msg = p.parser.problem - } else { - msg = "unknown problem parsing YAML content" - } - failf("%s%s", where, msg) -} - -func (p *parser) anchor(n *node, anchor []byte) { - if anchor != nil { - p.doc.anchors[string(anchor)] = n - } -} - -func (p *parser) parse() *node { - p.init() - switch p.peek() { - case yaml_SCALAR_EVENT: - return p.scalar() - case yaml_ALIAS_EVENT: - return p.alias() - case yaml_MAPPING_START_EVENT: - return p.mapping() - case yaml_SEQUENCE_START_EVENT: - return p.sequence() - case yaml_DOCUMENT_START_EVENT: - return p.document() - case yaml_STREAM_END_EVENT: - // Happens when attempting to decode an empty buffer. - return nil - default: - panic("attempted to parse unknown event: " + p.event.typ.String()) - } -} - -func (p *parser) node(kind int) *node { - return &node{ - kind: kind, - line: p.event.start_mark.line, - column: p.event.start_mark.column, - } -} - -func (p *parser) document() *node { - n := p.node(documentNode) - n.anchors = make(map[string]*node) - p.doc = n - p.expect(yaml_DOCUMENT_START_EVENT) - n.children = append(n.children, p.parse()) - p.expect(yaml_DOCUMENT_END_EVENT) - return n -} - -func (p *parser) alias() *node { - n := p.node(aliasNode) - n.value = string(p.event.anchor) - n.alias = p.doc.anchors[n.value] - if n.alias == nil { - failf("unknown anchor '%s' referenced", n.value) - } - p.expect(yaml_ALIAS_EVENT) - return n -} - -func (p *parser) scalar() *node { - n := p.node(scalarNode) - n.value = string(p.event.value) - n.tag = string(p.event.tag) - n.implicit = p.event.implicit - p.anchor(n, p.event.anchor) - p.expect(yaml_SCALAR_EVENT) - return n -} - -func (p *parser) sequence() *node { - n := p.node(sequenceNode) - p.anchor(n, p.event.anchor) - p.expect(yaml_SEQUENCE_START_EVENT) - for p.peek() != yaml_SEQUENCE_END_EVENT { - n.children = append(n.children, p.parse()) - } - p.expect(yaml_SEQUENCE_END_EVENT) - return n -} - -func (p *parser) mapping() *node { - n := p.node(mappingNode) - p.anchor(n, p.event.anchor) - p.expect(yaml_MAPPING_START_EVENT) - for p.peek() != yaml_MAPPING_END_EVENT { - n.children = append(n.children, p.parse(), p.parse()) - } - p.expect(yaml_MAPPING_END_EVENT) - return n -} - -// ---------------------------------------------------------------------------- -// Decoder, unmarshals a node into a provided value. - -type decoder struct { - doc *node - aliases map[*node]bool - mapType reflect.Type - terrors []string - strict bool - - decodeCount int - aliasCount int - aliasDepth int -} - -var ( - mapItemType = reflect.TypeOf(MapItem{}) - durationType = reflect.TypeOf(time.Duration(0)) - defaultMapType = reflect.TypeOf(map[interface{}]interface{}{}) - ifaceType = defaultMapType.Elem() - timeType = reflect.TypeOf(time.Time{}) - ptrTimeType = reflect.TypeOf(&time.Time{}) -) - -func newDecoder(strict bool) *decoder { - d := &decoder{mapType: defaultMapType, strict: strict} - d.aliases = make(map[*node]bool) - return d -} - -func (d *decoder) terror(n *node, tag string, out reflect.Value) { - if n.tag != "" { - tag = n.tag - } - value := n.value - if tag != yaml_SEQ_TAG && tag != yaml_MAP_TAG { - if len(value) > 10 { - value = " `" + value[:7] + "...`" - } else { - value = " `" + value + "`" - } - } - d.terrors = append(d.terrors, fmt.Sprintf("line %d: cannot unmarshal %s%s into %s", n.line+1, shortTag(tag), value, out.Type())) -} - -func (d *decoder) callUnmarshaler(n *node, u Unmarshaler) (good bool) { - terrlen := len(d.terrors) - err := u.UnmarshalYAML(func(v interface{}) (err error) { - defer handleErr(&err) - d.unmarshal(n, reflect.ValueOf(v)) - if len(d.terrors) > terrlen { - issues := d.terrors[terrlen:] - d.terrors = d.terrors[:terrlen] - return &TypeError{issues} - } - return nil - }) - if e, ok := err.(*TypeError); ok { - d.terrors = append(d.terrors, e.Errors...) - return false - } - if err != nil { - fail(err) - } - return true -} - -// d.prepare initializes and dereferences pointers and calls UnmarshalYAML -// if a value is found to implement it. -// It returns the initialized and dereferenced out value, whether -// unmarshalling was already done by UnmarshalYAML, and if so whether -// its types unmarshalled appropriately. -// -// If n holds a null value, prepare returns before doing anything. -func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unmarshaled, good bool) { - if n.tag == yaml_NULL_TAG || n.kind == scalarNode && n.tag == "" && (n.value == "null" || n.value == "~" || n.value == "" && n.implicit) { - return out, false, false - } - again := true - for again { - again = false - if out.Kind() == reflect.Ptr { - if out.IsNil() { - out.Set(reflect.New(out.Type().Elem())) - } - out = out.Elem() - again = true - } - if out.CanAddr() { - if u, ok := out.Addr().Interface().(Unmarshaler); ok { - good = d.callUnmarshaler(n, u) - return out, true, good - } - } - } - return out, false, false -} - -const ( - // 400,000 decode operations is ~500kb of dense object declarations, or - // ~5kb of dense object declarations with 10000% alias expansion - alias_ratio_range_low = 400000 - - // 4,000,000 decode operations is ~5MB of dense object declarations, or - // ~4.5MB of dense object declarations with 10% alias expansion - alias_ratio_range_high = 4000000 - - // alias_ratio_range is the range over which we scale allowed alias ratios - alias_ratio_range = float64(alias_ratio_range_high - alias_ratio_range_low) -) - -func allowedAliasRatio(decodeCount int) float64 { - switch { - case decodeCount <= alias_ratio_range_low: - // allow 99% to come from alias expansion for small-to-medium documents - return 0.99 - case decodeCount >= alias_ratio_range_high: - // allow 10% to come from alias expansion for very large documents - return 0.10 - default: - // scale smoothly from 99% down to 10% over the range. - // this maps to 396,000 - 400,000 allowed alias-driven decodes over the range. - // 400,000 decode operations is ~100MB of allocations in worst-case scenarios (single-item maps). - return 0.99 - 0.89*(float64(decodeCount-alias_ratio_range_low)/alias_ratio_range) - } -} - -func (d *decoder) unmarshal(n *node, out reflect.Value) (good bool) { - d.decodeCount++ - if d.aliasDepth > 0 { - d.aliasCount++ - } - if d.aliasCount > 100 && d.decodeCount > 1000 && float64(d.aliasCount)/float64(d.decodeCount) > allowedAliasRatio(d.decodeCount) { - failf("document contains excessive aliasing") - } - switch n.kind { - case documentNode: - return d.document(n, out) - case aliasNode: - return d.alias(n, out) - } - out, unmarshaled, good := d.prepare(n, out) - if unmarshaled { - return good - } - switch n.kind { - case scalarNode: - good = d.scalar(n, out) - case mappingNode: - good = d.mapping(n, out) - case sequenceNode: - good = d.sequence(n, out) - default: - panic("internal error: unknown node kind: " + strconv.Itoa(n.kind)) - } - return good -} - -func (d *decoder) document(n *node, out reflect.Value) (good bool) { - if len(n.children) == 1 { - d.doc = n - d.unmarshal(n.children[0], out) - return true - } - return false -} - -func (d *decoder) alias(n *node, out reflect.Value) (good bool) { - if d.aliases[n] { - // TODO this could actually be allowed in some circumstances. - failf("anchor '%s' value contains itself", n.value) - } - d.aliases[n] = true - d.aliasDepth++ - good = d.unmarshal(n.alias, out) - d.aliasDepth-- - delete(d.aliases, n) - return good -} - -var zeroValue reflect.Value - -func resetMap(out reflect.Value) { - for _, k := range out.MapKeys() { - out.SetMapIndex(k, zeroValue) - } -} - -func (d *decoder) scalar(n *node, out reflect.Value) bool { - var tag string - var resolved interface{} - if n.tag == "" && !n.implicit { - tag = yaml_STR_TAG - resolved = n.value - } else { - tag, resolved = resolve(n.tag, n.value) - if tag == yaml_BINARY_TAG { - data, err := base64.StdEncoding.DecodeString(resolved.(string)) - if err != nil { - failf("!!binary value contains invalid base64 data") - } - resolved = string(data) - } - } - if resolved == nil { - if out.Kind() == reflect.Map && !out.CanAddr() { - resetMap(out) - } else { - out.Set(reflect.Zero(out.Type())) - } - return true - } - if resolvedv := reflect.ValueOf(resolved); out.Type() == resolvedv.Type() { - // We've resolved to exactly the type we want, so use that. - out.Set(resolvedv) - return true - } - // Perhaps we can use the value as a TextUnmarshaler to - // set its value. - if out.CanAddr() { - u, ok := out.Addr().Interface().(encoding.TextUnmarshaler) - if ok { - var text []byte - if tag == yaml_BINARY_TAG { - text = []byte(resolved.(string)) - } else { - // We let any value be unmarshaled into TextUnmarshaler. - // That might be more lax than we'd like, but the - // TextUnmarshaler itself should bowl out any dubious values. - text = []byte(n.value) - } - err := u.UnmarshalText(text) - if err != nil { - fail(err) - } - return true - } - } - switch out.Kind() { - case reflect.String: - if tag == yaml_BINARY_TAG { - out.SetString(resolved.(string)) - return true - } - if resolved != nil { - out.SetString(n.value) - return true - } - case reflect.Interface: - if resolved == nil { - out.Set(reflect.Zero(out.Type())) - } else if tag == yaml_TIMESTAMP_TAG { - // It looks like a timestamp but for backward compatibility - // reasons we set it as a string, so that code that unmarshals - // timestamp-like values into interface{} will continue to - // see a string and not a time.Time. - // TODO(v3) Drop this. - out.Set(reflect.ValueOf(n.value)) - } else { - out.Set(reflect.ValueOf(resolved)) - } - return true - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - switch resolved := resolved.(type) { - case int: - if !out.OverflowInt(int64(resolved)) { - out.SetInt(int64(resolved)) - return true - } - case int64: - if !out.OverflowInt(resolved) { - out.SetInt(resolved) - return true - } - case uint64: - if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) { - out.SetInt(int64(resolved)) - return true - } - case float64: - if resolved <= math.MaxInt64 && !out.OverflowInt(int64(resolved)) { - out.SetInt(int64(resolved)) - return true - } - case string: - if out.Type() == durationType { - d, err := time.ParseDuration(resolved) - if err == nil { - out.SetInt(int64(d)) - return true - } - } - } - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - switch resolved := resolved.(type) { - case int: - if resolved >= 0 && !out.OverflowUint(uint64(resolved)) { - out.SetUint(uint64(resolved)) - return true - } - case int64: - if resolved >= 0 && !out.OverflowUint(uint64(resolved)) { - out.SetUint(uint64(resolved)) - return true - } - case uint64: - if !out.OverflowUint(uint64(resolved)) { - out.SetUint(uint64(resolved)) - return true - } - case float64: - if resolved <= math.MaxUint64 && !out.OverflowUint(uint64(resolved)) { - out.SetUint(uint64(resolved)) - return true - } - } - case reflect.Bool: - switch resolved := resolved.(type) { - case bool: - out.SetBool(resolved) - return true - } - case reflect.Float32, reflect.Float64: - switch resolved := resolved.(type) { - case int: - out.SetFloat(float64(resolved)) - return true - case int64: - out.SetFloat(float64(resolved)) - return true - case uint64: - out.SetFloat(float64(resolved)) - return true - case float64: - out.SetFloat(resolved) - return true - } - case reflect.Struct: - if resolvedv := reflect.ValueOf(resolved); out.Type() == resolvedv.Type() { - out.Set(resolvedv) - return true - } - case reflect.Ptr: - if out.Type().Elem() == reflect.TypeOf(resolved) { - // TODO DOes this make sense? When is out a Ptr except when decoding a nil value? - elem := reflect.New(out.Type().Elem()) - elem.Elem().Set(reflect.ValueOf(resolved)) - out.Set(elem) - return true - } - } - d.terror(n, tag, out) - return false -} - -func settableValueOf(i interface{}) reflect.Value { - v := reflect.ValueOf(i) - sv := reflect.New(v.Type()).Elem() - sv.Set(v) - return sv -} - -func (d *decoder) sequence(n *node, out reflect.Value) (good bool) { - l := len(n.children) - - var iface reflect.Value - switch out.Kind() { - case reflect.Slice: - out.Set(reflect.MakeSlice(out.Type(), l, l)) - case reflect.Array: - if l != out.Len() { - failf("invalid array: want %d elements but got %d", out.Len(), l) - } - case reflect.Interface: - // No type hints. Will have to use a generic sequence. - iface = out - out = settableValueOf(make([]interface{}, l)) - default: - d.terror(n, yaml_SEQ_TAG, out) - return false - } - et := out.Type().Elem() - - j := 0 - for i := 0; i < l; i++ { - e := reflect.New(et).Elem() - if ok := d.unmarshal(n.children[i], e); ok { - out.Index(j).Set(e) - j++ - } - } - if out.Kind() != reflect.Array { - out.Set(out.Slice(0, j)) - } - if iface.IsValid() { - iface.Set(out) - } - return true -} - -func (d *decoder) mapping(n *node, out reflect.Value) (good bool) { - switch out.Kind() { - case reflect.Struct: - return d.mappingStruct(n, out) - case reflect.Slice: - return d.mappingSlice(n, out) - case reflect.Map: - // okay - case reflect.Interface: - if d.mapType.Kind() == reflect.Map { - iface := out - out = reflect.MakeMap(d.mapType) - iface.Set(out) - } else { - slicev := reflect.New(d.mapType).Elem() - if !d.mappingSlice(n, slicev) { - return false - } - out.Set(slicev) - return true - } - default: - d.terror(n, yaml_MAP_TAG, out) - return false - } - outt := out.Type() - kt := outt.Key() - et := outt.Elem() - - mapType := d.mapType - if outt.Key() == ifaceType && outt.Elem() == ifaceType { - d.mapType = outt - } - - if out.IsNil() { - out.Set(reflect.MakeMap(outt)) - } - l := len(n.children) - for i := 0; i < l; i += 2 { - if isMerge(n.children[i]) { - d.merge(n.children[i+1], out) - continue - } - k := reflect.New(kt).Elem() - if d.unmarshal(n.children[i], k) { - kkind := k.Kind() - if kkind == reflect.Interface { - kkind = k.Elem().Kind() - } - if kkind == reflect.Map || kkind == reflect.Slice { - failf("invalid map key: %#v", k.Interface()) - } - e := reflect.New(et).Elem() - if d.unmarshal(n.children[i+1], e) { - d.setMapIndex(n.children[i+1], out, k, e) - } - } - } - d.mapType = mapType - return true -} - -func (d *decoder) setMapIndex(n *node, out, k, v reflect.Value) { - if d.strict && out.MapIndex(k) != zeroValue { - d.terrors = append(d.terrors, fmt.Sprintf("line %d: key %#v already set in map", n.line+1, k.Interface())) - return - } - out.SetMapIndex(k, v) -} - -func (d *decoder) mappingSlice(n *node, out reflect.Value) (good bool) { - outt := out.Type() - if outt.Elem() != mapItemType { - d.terror(n, yaml_MAP_TAG, out) - return false - } - - mapType := d.mapType - d.mapType = outt - - var slice []MapItem - var l = len(n.children) - for i := 0; i < l; i += 2 { - if isMerge(n.children[i]) { - d.merge(n.children[i+1], out) - continue - } - item := MapItem{} - k := reflect.ValueOf(&item.Key).Elem() - if d.unmarshal(n.children[i], k) { - v := reflect.ValueOf(&item.Value).Elem() - if d.unmarshal(n.children[i+1], v) { - slice = append(slice, item) - } - } - } - out.Set(reflect.ValueOf(slice)) - d.mapType = mapType - return true -} - -func (d *decoder) mappingStruct(n *node, out reflect.Value) (good bool) { - sinfo, err := getStructInfo(out.Type()) - if err != nil { - panic(err) - } - name := settableValueOf("") - l := len(n.children) - - var inlineMap reflect.Value - var elemType reflect.Type - if sinfo.InlineMap != -1 { - inlineMap = out.Field(sinfo.InlineMap) - inlineMap.Set(reflect.New(inlineMap.Type()).Elem()) - elemType = inlineMap.Type().Elem() - } - - var doneFields []bool - if d.strict { - doneFields = make([]bool, len(sinfo.FieldsList)) - } - for i := 0; i < l; i += 2 { - ni := n.children[i] - if isMerge(ni) { - d.merge(n.children[i+1], out) - continue - } - if !d.unmarshal(ni, name) { - continue - } - if info, ok := sinfo.FieldsMap[name.String()]; ok { - if d.strict { - if doneFields[info.Id] { - d.terrors = append(d.terrors, fmt.Sprintf("line %d: field %s already set in type %s", ni.line+1, name.String(), out.Type())) - continue - } - doneFields[info.Id] = true - } - var field reflect.Value - if info.Inline == nil { - field = out.Field(info.Num) - } else { - field = out.FieldByIndex(info.Inline) - } - d.unmarshal(n.children[i+1], field) - } else if sinfo.InlineMap != -1 { - if inlineMap.IsNil() { - inlineMap.Set(reflect.MakeMap(inlineMap.Type())) - } - value := reflect.New(elemType).Elem() - d.unmarshal(n.children[i+1], value) - d.setMapIndex(n.children[i+1], inlineMap, name, value) - } else if d.strict { - d.terrors = append(d.terrors, fmt.Sprintf("line %d: field %s not found in type %s", ni.line+1, name.String(), out.Type())) - } - } - return true -} - -func failWantMap() { - failf("map merge requires map or sequence of maps as the value") -} - -func (d *decoder) merge(n *node, out reflect.Value) { - switch n.kind { - case mappingNode: - d.unmarshal(n, out) - case aliasNode: - if n.alias != nil && n.alias.kind != mappingNode { - failWantMap() - } - d.unmarshal(n, out) - case sequenceNode: - // Step backwards as earlier nodes take precedence. - for i := len(n.children) - 1; i >= 0; i-- { - ni := n.children[i] - if ni.kind == aliasNode { - if ni.alias != nil && ni.alias.kind != mappingNode { - failWantMap() - } - } else if ni.kind != mappingNode { - failWantMap() - } - d.unmarshal(ni, out) - } - default: - failWantMap() - } -} - -func isMerge(n *node) bool { - return n.kind == scalarNode && n.value == "<<" && (n.implicit == true || n.tag == yaml_MERGE_TAG) -} diff --git a/vendor/gopkg.in/yaml.v2/emitterc.go b/vendor/gopkg.in/yaml.v2/emitterc.go deleted file mode 100644 index a1c2cc5..0000000 --- a/vendor/gopkg.in/yaml.v2/emitterc.go +++ /dev/null @@ -1,1685 +0,0 @@ -package yaml - -import ( - "bytes" - "fmt" -) - -// Flush the buffer if needed. -func flush(emitter *yaml_emitter_t) bool { - if emitter.buffer_pos+5 >= len(emitter.buffer) { - return yaml_emitter_flush(emitter) - } - return true -} - -// Put a character to the output buffer. -func put(emitter *yaml_emitter_t, value byte) bool { - if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { - return false - } - emitter.buffer[emitter.buffer_pos] = value - emitter.buffer_pos++ - emitter.column++ - return true -} - -// Put a line break to the output buffer. -func put_break(emitter *yaml_emitter_t) bool { - if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { - return false - } - switch emitter.line_break { - case yaml_CR_BREAK: - emitter.buffer[emitter.buffer_pos] = '\r' - emitter.buffer_pos += 1 - case yaml_LN_BREAK: - emitter.buffer[emitter.buffer_pos] = '\n' - emitter.buffer_pos += 1 - case yaml_CRLN_BREAK: - emitter.buffer[emitter.buffer_pos+0] = '\r' - emitter.buffer[emitter.buffer_pos+1] = '\n' - emitter.buffer_pos += 2 - default: - panic("unknown line break setting") - } - emitter.column = 0 - emitter.line++ - return true -} - -// Copy a character from a string into buffer. -func write(emitter *yaml_emitter_t, s []byte, i *int) bool { - if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) { - return false - } - p := emitter.buffer_pos - w := width(s[*i]) - switch w { - case 4: - emitter.buffer[p+3] = s[*i+3] - fallthrough - case 3: - emitter.buffer[p+2] = s[*i+2] - fallthrough - case 2: - emitter.buffer[p+1] = s[*i+1] - fallthrough - case 1: - emitter.buffer[p+0] = s[*i+0] - default: - panic("unknown character width") - } - emitter.column++ - emitter.buffer_pos += w - *i += w - return true -} - -// Write a whole string into buffer. -func write_all(emitter *yaml_emitter_t, s []byte) bool { - for i := 0; i < len(s); { - if !write(emitter, s, &i) { - return false - } - } - return true -} - -// Copy a line break character from a string into buffer. -func write_break(emitter *yaml_emitter_t, s []byte, i *int) bool { - if s[*i] == '\n' { - if !put_break(emitter) { - return false - } - *i++ - } else { - if !write(emitter, s, i) { - return false - } - emitter.column = 0 - emitter.line++ - } - return true -} - -// Set an emitter error and return false. -func yaml_emitter_set_emitter_error(emitter *yaml_emitter_t, problem string) bool { - emitter.error = yaml_EMITTER_ERROR - emitter.problem = problem - return false -} - -// Emit an event. -func yaml_emitter_emit(emitter *yaml_emitter_t, event *yaml_event_t) bool { - emitter.events = append(emitter.events, *event) - for !yaml_emitter_need_more_events(emitter) { - event := &emitter.events[emitter.events_head] - if !yaml_emitter_analyze_event(emitter, event) { - return false - } - if !yaml_emitter_state_machine(emitter, event) { - return false - } - yaml_event_delete(event) - emitter.events_head++ - } - return true -} - -// Check if we need to accumulate more events before emitting. -// -// We accumulate extra -// - 1 event for DOCUMENT-START -// - 2 events for SEQUENCE-START -// - 3 events for MAPPING-START -// -func yaml_emitter_need_more_events(emitter *yaml_emitter_t) bool { - if emitter.events_head == len(emitter.events) { - return true - } - var accumulate int - switch emitter.events[emitter.events_head].typ { - case yaml_DOCUMENT_START_EVENT: - accumulate = 1 - break - case yaml_SEQUENCE_START_EVENT: - accumulate = 2 - break - case yaml_MAPPING_START_EVENT: - accumulate = 3 - break - default: - return false - } - if len(emitter.events)-emitter.events_head > accumulate { - return false - } - var level int - for i := emitter.events_head; i < len(emitter.events); i++ { - switch emitter.events[i].typ { - case yaml_STREAM_START_EVENT, yaml_DOCUMENT_START_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT: - level++ - case yaml_STREAM_END_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_END_EVENT, yaml_MAPPING_END_EVENT: - level-- - } - if level == 0 { - return false - } - } - return true -} - -// Append a directive to the directives stack. -func yaml_emitter_append_tag_directive(emitter *yaml_emitter_t, value *yaml_tag_directive_t, allow_duplicates bool) bool { - for i := 0; i < len(emitter.tag_directives); i++ { - if bytes.Equal(value.handle, emitter.tag_directives[i].handle) { - if allow_duplicates { - return true - } - return yaml_emitter_set_emitter_error(emitter, "duplicate %TAG directive") - } - } - - // [Go] Do we actually need to copy this given garbage collection - // and the lack of deallocating destructors? - tag_copy := yaml_tag_directive_t{ - handle: make([]byte, len(value.handle)), - prefix: make([]byte, len(value.prefix)), - } - copy(tag_copy.handle, value.handle) - copy(tag_copy.prefix, value.prefix) - emitter.tag_directives = append(emitter.tag_directives, tag_copy) - return true -} - -// Increase the indentation level. -func yaml_emitter_increase_indent(emitter *yaml_emitter_t, flow, indentless bool) bool { - emitter.indents = append(emitter.indents, emitter.indent) - if emitter.indent < 0 { - if flow { - emitter.indent = emitter.best_indent - } else { - emitter.indent = 0 - } - } else if !indentless { - emitter.indent += emitter.best_indent - } - return true -} - -// State dispatcher. -func yaml_emitter_state_machine(emitter *yaml_emitter_t, event *yaml_event_t) bool { - switch emitter.state { - default: - case yaml_EMIT_STREAM_START_STATE: - return yaml_emitter_emit_stream_start(emitter, event) - - case yaml_EMIT_FIRST_DOCUMENT_START_STATE: - return yaml_emitter_emit_document_start(emitter, event, true) - - case yaml_EMIT_DOCUMENT_START_STATE: - return yaml_emitter_emit_document_start(emitter, event, false) - - case yaml_EMIT_DOCUMENT_CONTENT_STATE: - return yaml_emitter_emit_document_content(emitter, event) - - case yaml_EMIT_DOCUMENT_END_STATE: - return yaml_emitter_emit_document_end(emitter, event) - - case yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE: - return yaml_emitter_emit_flow_sequence_item(emitter, event, true) - - case yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE: - return yaml_emitter_emit_flow_sequence_item(emitter, event, false) - - case yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE: - return yaml_emitter_emit_flow_mapping_key(emitter, event, true) - - case yaml_EMIT_FLOW_MAPPING_KEY_STATE: - return yaml_emitter_emit_flow_mapping_key(emitter, event, false) - - case yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE: - return yaml_emitter_emit_flow_mapping_value(emitter, event, true) - - case yaml_EMIT_FLOW_MAPPING_VALUE_STATE: - return yaml_emitter_emit_flow_mapping_value(emitter, event, false) - - case yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE: - return yaml_emitter_emit_block_sequence_item(emitter, event, true) - - case yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE: - return yaml_emitter_emit_block_sequence_item(emitter, event, false) - - case yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE: - return yaml_emitter_emit_block_mapping_key(emitter, event, true) - - case yaml_EMIT_BLOCK_MAPPING_KEY_STATE: - return yaml_emitter_emit_block_mapping_key(emitter, event, false) - - case yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE: - return yaml_emitter_emit_block_mapping_value(emitter, event, true) - - case yaml_EMIT_BLOCK_MAPPING_VALUE_STATE: - return yaml_emitter_emit_block_mapping_value(emitter, event, false) - - case yaml_EMIT_END_STATE: - return yaml_emitter_set_emitter_error(emitter, "expected nothing after STREAM-END") - } - panic("invalid emitter state") -} - -// Expect STREAM-START. -func yaml_emitter_emit_stream_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if event.typ != yaml_STREAM_START_EVENT { - return yaml_emitter_set_emitter_error(emitter, "expected STREAM-START") - } - if emitter.encoding == yaml_ANY_ENCODING { - emitter.encoding = event.encoding - if emitter.encoding == yaml_ANY_ENCODING { - emitter.encoding = yaml_UTF8_ENCODING - } - } - if emitter.best_indent < 2 || emitter.best_indent > 9 { - emitter.best_indent = 2 - } - if emitter.best_width >= 0 && emitter.best_width <= emitter.best_indent*2 { - emitter.best_width = 80 - } - if emitter.best_width < 0 { - emitter.best_width = 1<<31 - 1 - } - if emitter.line_break == yaml_ANY_BREAK { - emitter.line_break = yaml_LN_BREAK - } - - emitter.indent = -1 - emitter.line = 0 - emitter.column = 0 - emitter.whitespace = true - emitter.indention = true - - if emitter.encoding != yaml_UTF8_ENCODING { - if !yaml_emitter_write_bom(emitter) { - return false - } - } - emitter.state = yaml_EMIT_FIRST_DOCUMENT_START_STATE - return true -} - -// Expect DOCUMENT-START or STREAM-END. -func yaml_emitter_emit_document_start(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - - if event.typ == yaml_DOCUMENT_START_EVENT { - - if event.version_directive != nil { - if !yaml_emitter_analyze_version_directive(emitter, event.version_directive) { - return false - } - } - - for i := 0; i < len(event.tag_directives); i++ { - tag_directive := &event.tag_directives[i] - if !yaml_emitter_analyze_tag_directive(emitter, tag_directive) { - return false - } - if !yaml_emitter_append_tag_directive(emitter, tag_directive, false) { - return false - } - } - - for i := 0; i < len(default_tag_directives); i++ { - tag_directive := &default_tag_directives[i] - if !yaml_emitter_append_tag_directive(emitter, tag_directive, true) { - return false - } - } - - implicit := event.implicit - if !first || emitter.canonical { - implicit = false - } - - if emitter.open_ended && (event.version_directive != nil || len(event.tag_directives) > 0) { - if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - - if event.version_directive != nil { - implicit = false - if !yaml_emitter_write_indicator(emitter, []byte("%YAML"), true, false, false) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte("1.1"), true, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - - if len(event.tag_directives) > 0 { - implicit = false - for i := 0; i < len(event.tag_directives); i++ { - tag_directive := &event.tag_directives[i] - if !yaml_emitter_write_indicator(emitter, []byte("%TAG"), true, false, false) { - return false - } - if !yaml_emitter_write_tag_handle(emitter, tag_directive.handle) { - return false - } - if !yaml_emitter_write_tag_content(emitter, tag_directive.prefix, true) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - } - - if yaml_emitter_check_empty_document(emitter) { - implicit = false - } - if !implicit { - if !yaml_emitter_write_indent(emitter) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte("---"), true, false, false) { - return false - } - if emitter.canonical { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - } - - emitter.state = yaml_EMIT_DOCUMENT_CONTENT_STATE - return true - } - - if event.typ == yaml_STREAM_END_EVENT { - if emitter.open_ended { - if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_flush(emitter) { - return false - } - emitter.state = yaml_EMIT_END_STATE - return true - } - - return yaml_emitter_set_emitter_error(emitter, "expected DOCUMENT-START or STREAM-END") -} - -// Expect the root node. -func yaml_emitter_emit_document_content(emitter *yaml_emitter_t, event *yaml_event_t) bool { - emitter.states = append(emitter.states, yaml_EMIT_DOCUMENT_END_STATE) - return yaml_emitter_emit_node(emitter, event, true, false, false, false) -} - -// Expect DOCUMENT-END. -func yaml_emitter_emit_document_end(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if event.typ != yaml_DOCUMENT_END_EVENT { - return yaml_emitter_set_emitter_error(emitter, "expected DOCUMENT-END") - } - if !yaml_emitter_write_indent(emitter) { - return false - } - if !event.implicit { - // [Go] Allocate the slice elsewhere. - if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_flush(emitter) { - return false - } - emitter.state = yaml_EMIT_DOCUMENT_START_STATE - emitter.tag_directives = emitter.tag_directives[:0] - return true -} - -// Expect a flow item node. -func yaml_emitter_emit_flow_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_write_indicator(emitter, []byte{'['}, true, true, false) { - return false - } - if !yaml_emitter_increase_indent(emitter, true, false) { - return false - } - emitter.flow_level++ - } - - if event.typ == yaml_SEQUENCE_END_EVENT { - emitter.flow_level-- - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - if emitter.canonical && !first { - if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{']'}, false, false, false) { - return false - } - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - - return true - } - - if !first { - if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { - return false - } - } - - if emitter.canonical || emitter.column > emitter.best_width { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - emitter.states = append(emitter.states, yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE) - return yaml_emitter_emit_node(emitter, event, false, true, false, false) -} - -// Expect a flow key node. -func yaml_emitter_emit_flow_mapping_key(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_write_indicator(emitter, []byte{'{'}, true, true, false) { - return false - } - if !yaml_emitter_increase_indent(emitter, true, false) { - return false - } - emitter.flow_level++ - } - - if event.typ == yaml_MAPPING_END_EVENT { - emitter.flow_level-- - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - if emitter.canonical && !first { - if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { - return false - } - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{'}'}, false, false, false) { - return false - } - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true - } - - if !first { - if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) { - return false - } - } - if emitter.canonical || emitter.column > emitter.best_width { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - - if !emitter.canonical && yaml_emitter_check_simple_key(emitter) { - emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, true) - } - if !yaml_emitter_write_indicator(emitter, []byte{'?'}, true, false, false) { - return false - } - emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_VALUE_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, false) -} - -// Expect a flow value node. -func yaml_emitter_emit_flow_mapping_value(emitter *yaml_emitter_t, event *yaml_event_t, simple bool) bool { - if simple { - if !yaml_emitter_write_indicator(emitter, []byte{':'}, false, false, false) { - return false - } - } else { - if emitter.canonical || emitter.column > emitter.best_width { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{':'}, true, false, false) { - return false - } - } - emitter.states = append(emitter.states, yaml_EMIT_FLOW_MAPPING_KEY_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, false) -} - -// Expect a block item node. -func yaml_emitter_emit_block_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_increase_indent(emitter, false, emitter.mapping_context && !emitter.indention) { - return false - } - } - if event.typ == yaml_SEQUENCE_END_EVENT { - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true - } - if !yaml_emitter_write_indent(emitter) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte{'-'}, true, false, true) { - return false - } - emitter.states = append(emitter.states, yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE) - return yaml_emitter_emit_node(emitter, event, false, true, false, false) -} - -// Expect a block key node. -func yaml_emitter_emit_block_mapping_key(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool { - if first { - if !yaml_emitter_increase_indent(emitter, false, false) { - return false - } - } - if event.typ == yaml_MAPPING_END_EVENT { - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true - } - if !yaml_emitter_write_indent(emitter) { - return false - } - if yaml_emitter_check_simple_key(emitter) { - emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, true) - } - if !yaml_emitter_write_indicator(emitter, []byte{'?'}, true, false, true) { - return false - } - emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_VALUE_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, false) -} - -// Expect a block value node. -func yaml_emitter_emit_block_mapping_value(emitter *yaml_emitter_t, event *yaml_event_t, simple bool) bool { - if simple { - if !yaml_emitter_write_indicator(emitter, []byte{':'}, false, false, false) { - return false - } - } else { - if !yaml_emitter_write_indent(emitter) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte{':'}, true, false, true) { - return false - } - } - emitter.states = append(emitter.states, yaml_EMIT_BLOCK_MAPPING_KEY_STATE) - return yaml_emitter_emit_node(emitter, event, false, false, true, false) -} - -// Expect a node. -func yaml_emitter_emit_node(emitter *yaml_emitter_t, event *yaml_event_t, - root bool, sequence bool, mapping bool, simple_key bool) bool { - - emitter.root_context = root - emitter.sequence_context = sequence - emitter.mapping_context = mapping - emitter.simple_key_context = simple_key - - switch event.typ { - case yaml_ALIAS_EVENT: - return yaml_emitter_emit_alias(emitter, event) - case yaml_SCALAR_EVENT: - return yaml_emitter_emit_scalar(emitter, event) - case yaml_SEQUENCE_START_EVENT: - return yaml_emitter_emit_sequence_start(emitter, event) - case yaml_MAPPING_START_EVENT: - return yaml_emitter_emit_mapping_start(emitter, event) - default: - return yaml_emitter_set_emitter_error(emitter, - fmt.Sprintf("expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS, but got %v", event.typ)) - } -} - -// Expect ALIAS. -func yaml_emitter_emit_alias(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_process_anchor(emitter) { - return false - } - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true -} - -// Expect SCALAR. -func yaml_emitter_emit_scalar(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_select_scalar_style(emitter, event) { - return false - } - if !yaml_emitter_process_anchor(emitter) { - return false - } - if !yaml_emitter_process_tag(emitter) { - return false - } - if !yaml_emitter_increase_indent(emitter, true, false) { - return false - } - if !yaml_emitter_process_scalar(emitter) { - return false - } - emitter.indent = emitter.indents[len(emitter.indents)-1] - emitter.indents = emitter.indents[:len(emitter.indents)-1] - emitter.state = emitter.states[len(emitter.states)-1] - emitter.states = emitter.states[:len(emitter.states)-1] - return true -} - -// Expect SEQUENCE-START. -func yaml_emitter_emit_sequence_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_process_anchor(emitter) { - return false - } - if !yaml_emitter_process_tag(emitter) { - return false - } - if emitter.flow_level > 0 || emitter.canonical || event.sequence_style() == yaml_FLOW_SEQUENCE_STYLE || - yaml_emitter_check_empty_sequence(emitter) { - emitter.state = yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE - } else { - emitter.state = yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE - } - return true -} - -// Expect MAPPING-START. -func yaml_emitter_emit_mapping_start(emitter *yaml_emitter_t, event *yaml_event_t) bool { - if !yaml_emitter_process_anchor(emitter) { - return false - } - if !yaml_emitter_process_tag(emitter) { - return false - } - if emitter.flow_level > 0 || emitter.canonical || event.mapping_style() == yaml_FLOW_MAPPING_STYLE || - yaml_emitter_check_empty_mapping(emitter) { - emitter.state = yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE - } else { - emitter.state = yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE - } - return true -} - -// Check if the document content is an empty scalar. -func yaml_emitter_check_empty_document(emitter *yaml_emitter_t) bool { - return false // [Go] Huh? -} - -// Check if the next events represent an empty sequence. -func yaml_emitter_check_empty_sequence(emitter *yaml_emitter_t) bool { - if len(emitter.events)-emitter.events_head < 2 { - return false - } - return emitter.events[emitter.events_head].typ == yaml_SEQUENCE_START_EVENT && - emitter.events[emitter.events_head+1].typ == yaml_SEQUENCE_END_EVENT -} - -// Check if the next events represent an empty mapping. -func yaml_emitter_check_empty_mapping(emitter *yaml_emitter_t) bool { - if len(emitter.events)-emitter.events_head < 2 { - return false - } - return emitter.events[emitter.events_head].typ == yaml_MAPPING_START_EVENT && - emitter.events[emitter.events_head+1].typ == yaml_MAPPING_END_EVENT -} - -// Check if the next node can be expressed as a simple key. -func yaml_emitter_check_simple_key(emitter *yaml_emitter_t) bool { - length := 0 - switch emitter.events[emitter.events_head].typ { - case yaml_ALIAS_EVENT: - length += len(emitter.anchor_data.anchor) - case yaml_SCALAR_EVENT: - if emitter.scalar_data.multiline { - return false - } - length += len(emitter.anchor_data.anchor) + - len(emitter.tag_data.handle) + - len(emitter.tag_data.suffix) + - len(emitter.scalar_data.value) - case yaml_SEQUENCE_START_EVENT: - if !yaml_emitter_check_empty_sequence(emitter) { - return false - } - length += len(emitter.anchor_data.anchor) + - len(emitter.tag_data.handle) + - len(emitter.tag_data.suffix) - case yaml_MAPPING_START_EVENT: - if !yaml_emitter_check_empty_mapping(emitter) { - return false - } - length += len(emitter.anchor_data.anchor) + - len(emitter.tag_data.handle) + - len(emitter.tag_data.suffix) - default: - return false - } - return length <= 128 -} - -// Determine an acceptable scalar style. -func yaml_emitter_select_scalar_style(emitter *yaml_emitter_t, event *yaml_event_t) bool { - - no_tag := len(emitter.tag_data.handle) == 0 && len(emitter.tag_data.suffix) == 0 - if no_tag && !event.implicit && !event.quoted_implicit { - return yaml_emitter_set_emitter_error(emitter, "neither tag nor implicit flags are specified") - } - - style := event.scalar_style() - if style == yaml_ANY_SCALAR_STYLE { - style = yaml_PLAIN_SCALAR_STYLE - } - if emitter.canonical { - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - if emitter.simple_key_context && emitter.scalar_data.multiline { - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - - if style == yaml_PLAIN_SCALAR_STYLE { - if emitter.flow_level > 0 && !emitter.scalar_data.flow_plain_allowed || - emitter.flow_level == 0 && !emitter.scalar_data.block_plain_allowed { - style = yaml_SINGLE_QUOTED_SCALAR_STYLE - } - if len(emitter.scalar_data.value) == 0 && (emitter.flow_level > 0 || emitter.simple_key_context) { - style = yaml_SINGLE_QUOTED_SCALAR_STYLE - } - if no_tag && !event.implicit { - style = yaml_SINGLE_QUOTED_SCALAR_STYLE - } - } - if style == yaml_SINGLE_QUOTED_SCALAR_STYLE { - if !emitter.scalar_data.single_quoted_allowed { - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - } - if style == yaml_LITERAL_SCALAR_STYLE || style == yaml_FOLDED_SCALAR_STYLE { - if !emitter.scalar_data.block_allowed || emitter.flow_level > 0 || emitter.simple_key_context { - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - } - - if no_tag && !event.quoted_implicit && style != yaml_PLAIN_SCALAR_STYLE { - emitter.tag_data.handle = []byte{'!'} - } - emitter.scalar_data.style = style - return true -} - -// Write an anchor. -func yaml_emitter_process_anchor(emitter *yaml_emitter_t) bool { - if emitter.anchor_data.anchor == nil { - return true - } - c := []byte{'&'} - if emitter.anchor_data.alias { - c[0] = '*' - } - if !yaml_emitter_write_indicator(emitter, c, true, false, false) { - return false - } - return yaml_emitter_write_anchor(emitter, emitter.anchor_data.anchor) -} - -// Write a tag. -func yaml_emitter_process_tag(emitter *yaml_emitter_t) bool { - if len(emitter.tag_data.handle) == 0 && len(emitter.tag_data.suffix) == 0 { - return true - } - if len(emitter.tag_data.handle) > 0 { - if !yaml_emitter_write_tag_handle(emitter, emitter.tag_data.handle) { - return false - } - if len(emitter.tag_data.suffix) > 0 { - if !yaml_emitter_write_tag_content(emitter, emitter.tag_data.suffix, false) { - return false - } - } - } else { - // [Go] Allocate these slices elsewhere. - if !yaml_emitter_write_indicator(emitter, []byte("!<"), true, false, false) { - return false - } - if !yaml_emitter_write_tag_content(emitter, emitter.tag_data.suffix, false) { - return false - } - if !yaml_emitter_write_indicator(emitter, []byte{'>'}, false, false, false) { - return false - } - } - return true -} - -// Write a scalar. -func yaml_emitter_process_scalar(emitter *yaml_emitter_t) bool { - switch emitter.scalar_data.style { - case yaml_PLAIN_SCALAR_STYLE: - return yaml_emitter_write_plain_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) - - case yaml_SINGLE_QUOTED_SCALAR_STYLE: - return yaml_emitter_write_single_quoted_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) - - case yaml_DOUBLE_QUOTED_SCALAR_STYLE: - return yaml_emitter_write_double_quoted_scalar(emitter, emitter.scalar_data.value, !emitter.simple_key_context) - - case yaml_LITERAL_SCALAR_STYLE: - return yaml_emitter_write_literal_scalar(emitter, emitter.scalar_data.value) - - case yaml_FOLDED_SCALAR_STYLE: - return yaml_emitter_write_folded_scalar(emitter, emitter.scalar_data.value) - } - panic("unknown scalar style") -} - -// Check if a %YAML directive is valid. -func yaml_emitter_analyze_version_directive(emitter *yaml_emitter_t, version_directive *yaml_version_directive_t) bool { - if version_directive.major != 1 || version_directive.minor != 1 { - return yaml_emitter_set_emitter_error(emitter, "incompatible %YAML directive") - } - return true -} - -// Check if a %TAG directive is valid. -func yaml_emitter_analyze_tag_directive(emitter *yaml_emitter_t, tag_directive *yaml_tag_directive_t) bool { - handle := tag_directive.handle - prefix := tag_directive.prefix - if len(handle) == 0 { - return yaml_emitter_set_emitter_error(emitter, "tag handle must not be empty") - } - if handle[0] != '!' { - return yaml_emitter_set_emitter_error(emitter, "tag handle must start with '!'") - } - if handle[len(handle)-1] != '!' { - return yaml_emitter_set_emitter_error(emitter, "tag handle must end with '!'") - } - for i := 1; i < len(handle)-1; i += width(handle[i]) { - if !is_alpha(handle, i) { - return yaml_emitter_set_emitter_error(emitter, "tag handle must contain alphanumerical characters only") - } - } - if len(prefix) == 0 { - return yaml_emitter_set_emitter_error(emitter, "tag prefix must not be empty") - } - return true -} - -// Check if an anchor is valid. -func yaml_emitter_analyze_anchor(emitter *yaml_emitter_t, anchor []byte, alias bool) bool { - if len(anchor) == 0 { - problem := "anchor value must not be empty" - if alias { - problem = "alias value must not be empty" - } - return yaml_emitter_set_emitter_error(emitter, problem) - } - for i := 0; i < len(anchor); i += width(anchor[i]) { - if !is_alpha(anchor, i) { - problem := "anchor value must contain alphanumerical characters only" - if alias { - problem = "alias value must contain alphanumerical characters only" - } - return yaml_emitter_set_emitter_error(emitter, problem) - } - } - emitter.anchor_data.anchor = anchor - emitter.anchor_data.alias = alias - return true -} - -// Check if a tag is valid. -func yaml_emitter_analyze_tag(emitter *yaml_emitter_t, tag []byte) bool { - if len(tag) == 0 { - return yaml_emitter_set_emitter_error(emitter, "tag value must not be empty") - } - for i := 0; i < len(emitter.tag_directives); i++ { - tag_directive := &emitter.tag_directives[i] - if bytes.HasPrefix(tag, tag_directive.prefix) { - emitter.tag_data.handle = tag_directive.handle - emitter.tag_data.suffix = tag[len(tag_directive.prefix):] - return true - } - } - emitter.tag_data.suffix = tag - return true -} - -// Check if a scalar is valid. -func yaml_emitter_analyze_scalar(emitter *yaml_emitter_t, value []byte) bool { - var ( - block_indicators = false - flow_indicators = false - line_breaks = false - special_characters = false - - leading_space = false - leading_break = false - trailing_space = false - trailing_break = false - break_space = false - space_break = false - - preceded_by_whitespace = false - followed_by_whitespace = false - previous_space = false - previous_break = false - ) - - emitter.scalar_data.value = value - - if len(value) == 0 { - emitter.scalar_data.multiline = false - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = true - emitter.scalar_data.single_quoted_allowed = true - emitter.scalar_data.block_allowed = false - return true - } - - if len(value) >= 3 && ((value[0] == '-' && value[1] == '-' && value[2] == '-') || (value[0] == '.' && value[1] == '.' && value[2] == '.')) { - block_indicators = true - flow_indicators = true - } - - preceded_by_whitespace = true - for i, w := 0, 0; i < len(value); i += w { - w = width(value[i]) - followed_by_whitespace = i+w >= len(value) || is_blank(value, i+w) - - if i == 0 { - switch value[i] { - case '#', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`': - flow_indicators = true - block_indicators = true - case '?', ':': - flow_indicators = true - if followed_by_whitespace { - block_indicators = true - } - case '-': - if followed_by_whitespace { - flow_indicators = true - block_indicators = true - } - } - } else { - switch value[i] { - case ',', '?', '[', ']', '{', '}': - flow_indicators = true - case ':': - flow_indicators = true - if followed_by_whitespace { - block_indicators = true - } - case '#': - if preceded_by_whitespace { - flow_indicators = true - block_indicators = true - } - } - } - - if !is_printable(value, i) || !is_ascii(value, i) && !emitter.unicode { - special_characters = true - } - if is_space(value, i) { - if i == 0 { - leading_space = true - } - if i+width(value[i]) == len(value) { - trailing_space = true - } - if previous_break { - break_space = true - } - previous_space = true - previous_break = false - } else if is_break(value, i) { - line_breaks = true - if i == 0 { - leading_break = true - } - if i+width(value[i]) == len(value) { - trailing_break = true - } - if previous_space { - space_break = true - } - previous_space = false - previous_break = true - } else { - previous_space = false - previous_break = false - } - - // [Go]: Why 'z'? Couldn't be the end of the string as that's the loop condition. - preceded_by_whitespace = is_blankz(value, i) - } - - emitter.scalar_data.multiline = line_breaks - emitter.scalar_data.flow_plain_allowed = true - emitter.scalar_data.block_plain_allowed = true - emitter.scalar_data.single_quoted_allowed = true - emitter.scalar_data.block_allowed = true - - if leading_space || leading_break || trailing_space || trailing_break { - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = false - } - if trailing_space { - emitter.scalar_data.block_allowed = false - } - if break_space { - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = false - emitter.scalar_data.single_quoted_allowed = false - } - if space_break || special_characters { - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = false - emitter.scalar_data.single_quoted_allowed = false - emitter.scalar_data.block_allowed = false - } - if line_breaks { - emitter.scalar_data.flow_plain_allowed = false - emitter.scalar_data.block_plain_allowed = false - } - if flow_indicators { - emitter.scalar_data.flow_plain_allowed = false - } - if block_indicators { - emitter.scalar_data.block_plain_allowed = false - } - return true -} - -// Check if the event data is valid. -func yaml_emitter_analyze_event(emitter *yaml_emitter_t, event *yaml_event_t) bool { - - emitter.anchor_data.anchor = nil - emitter.tag_data.handle = nil - emitter.tag_data.suffix = nil - emitter.scalar_data.value = nil - - switch event.typ { - case yaml_ALIAS_EVENT: - if !yaml_emitter_analyze_anchor(emitter, event.anchor, true) { - return false - } - - case yaml_SCALAR_EVENT: - if len(event.anchor) > 0 { - if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { - return false - } - } - if len(event.tag) > 0 && (emitter.canonical || (!event.implicit && !event.quoted_implicit)) { - if !yaml_emitter_analyze_tag(emitter, event.tag) { - return false - } - } - if !yaml_emitter_analyze_scalar(emitter, event.value) { - return false - } - - case yaml_SEQUENCE_START_EVENT: - if len(event.anchor) > 0 { - if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { - return false - } - } - if len(event.tag) > 0 && (emitter.canonical || !event.implicit) { - if !yaml_emitter_analyze_tag(emitter, event.tag) { - return false - } - } - - case yaml_MAPPING_START_EVENT: - if len(event.anchor) > 0 { - if !yaml_emitter_analyze_anchor(emitter, event.anchor, false) { - return false - } - } - if len(event.tag) > 0 && (emitter.canonical || !event.implicit) { - if !yaml_emitter_analyze_tag(emitter, event.tag) { - return false - } - } - } - return true -} - -// Write the BOM character. -func yaml_emitter_write_bom(emitter *yaml_emitter_t) bool { - if !flush(emitter) { - return false - } - pos := emitter.buffer_pos - emitter.buffer[pos+0] = '\xEF' - emitter.buffer[pos+1] = '\xBB' - emitter.buffer[pos+2] = '\xBF' - emitter.buffer_pos += 3 - return true -} - -func yaml_emitter_write_indent(emitter *yaml_emitter_t) bool { - indent := emitter.indent - if indent < 0 { - indent = 0 - } - if !emitter.indention || emitter.column > indent || (emitter.column == indent && !emitter.whitespace) { - if !put_break(emitter) { - return false - } - } - for emitter.column < indent { - if !put(emitter, ' ') { - return false - } - } - emitter.whitespace = true - emitter.indention = true - return true -} - -func yaml_emitter_write_indicator(emitter *yaml_emitter_t, indicator []byte, need_whitespace, is_whitespace, is_indention bool) bool { - if need_whitespace && !emitter.whitespace { - if !put(emitter, ' ') { - return false - } - } - if !write_all(emitter, indicator) { - return false - } - emitter.whitespace = is_whitespace - emitter.indention = (emitter.indention && is_indention) - emitter.open_ended = false - return true -} - -func yaml_emitter_write_anchor(emitter *yaml_emitter_t, value []byte) bool { - if !write_all(emitter, value) { - return false - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_tag_handle(emitter *yaml_emitter_t, value []byte) bool { - if !emitter.whitespace { - if !put(emitter, ' ') { - return false - } - } - if !write_all(emitter, value) { - return false - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_tag_content(emitter *yaml_emitter_t, value []byte, need_whitespace bool) bool { - if need_whitespace && !emitter.whitespace { - if !put(emitter, ' ') { - return false - } - } - for i := 0; i < len(value); { - var must_write bool - switch value[i] { - case ';', '/', '?', ':', '@', '&', '=', '+', '$', ',', '_', '.', '~', '*', '\'', '(', ')', '[', ']': - must_write = true - default: - must_write = is_alpha(value, i) - } - if must_write { - if !write(emitter, value, &i) { - return false - } - } else { - w := width(value[i]) - for k := 0; k < w; k++ { - octet := value[i] - i++ - if !put(emitter, '%') { - return false - } - - c := octet >> 4 - if c < 10 { - c += '0' - } else { - c += 'A' - 10 - } - if !put(emitter, c) { - return false - } - - c = octet & 0x0f - if c < 10 { - c += '0' - } else { - c += 'A' - 10 - } - if !put(emitter, c) { - return false - } - } - } - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_plain_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { - if !emitter.whitespace { - if !put(emitter, ' ') { - return false - } - } - - spaces := false - breaks := false - for i := 0; i < len(value); { - if is_space(value, i) { - if allow_breaks && !spaces && emitter.column > emitter.best_width && !is_space(value, i+1) { - if !yaml_emitter_write_indent(emitter) { - return false - } - i += width(value[i]) - } else { - if !write(emitter, value, &i) { - return false - } - } - spaces = true - } else if is_break(value, i) { - if !breaks && value[i] == '\n' { - if !put_break(emitter) { - return false - } - } - if !write_break(emitter, value, &i) { - return false - } - emitter.indention = true - breaks = true - } else { - if breaks { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !write(emitter, value, &i) { - return false - } - emitter.indention = false - spaces = false - breaks = false - } - } - - emitter.whitespace = false - emitter.indention = false - if emitter.root_context { - emitter.open_ended = true - } - - return true -} - -func yaml_emitter_write_single_quoted_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { - - if !yaml_emitter_write_indicator(emitter, []byte{'\''}, true, false, false) { - return false - } - - spaces := false - breaks := false - for i := 0; i < len(value); { - if is_space(value, i) { - if allow_breaks && !spaces && emitter.column > emitter.best_width && i > 0 && i < len(value)-1 && !is_space(value, i+1) { - if !yaml_emitter_write_indent(emitter) { - return false - } - i += width(value[i]) - } else { - if !write(emitter, value, &i) { - return false - } - } - spaces = true - } else if is_break(value, i) { - if !breaks && value[i] == '\n' { - if !put_break(emitter) { - return false - } - } - if !write_break(emitter, value, &i) { - return false - } - emitter.indention = true - breaks = true - } else { - if breaks { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if value[i] == '\'' { - if !put(emitter, '\'') { - return false - } - } - if !write(emitter, value, &i) { - return false - } - emitter.indention = false - spaces = false - breaks = false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{'\''}, false, false, false) { - return false - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_double_quoted_scalar(emitter *yaml_emitter_t, value []byte, allow_breaks bool) bool { - spaces := false - if !yaml_emitter_write_indicator(emitter, []byte{'"'}, true, false, false) { - return false - } - - for i := 0; i < len(value); { - if !is_printable(value, i) || (!emitter.unicode && !is_ascii(value, i)) || - is_bom(value, i) || is_break(value, i) || - value[i] == '"' || value[i] == '\\' { - - octet := value[i] - - var w int - var v rune - switch { - case octet&0x80 == 0x00: - w, v = 1, rune(octet&0x7F) - case octet&0xE0 == 0xC0: - w, v = 2, rune(octet&0x1F) - case octet&0xF0 == 0xE0: - w, v = 3, rune(octet&0x0F) - case octet&0xF8 == 0xF0: - w, v = 4, rune(octet&0x07) - } - for k := 1; k < w; k++ { - octet = value[i+k] - v = (v << 6) + (rune(octet) & 0x3F) - } - i += w - - if !put(emitter, '\\') { - return false - } - - var ok bool - switch v { - case 0x00: - ok = put(emitter, '0') - case 0x07: - ok = put(emitter, 'a') - case 0x08: - ok = put(emitter, 'b') - case 0x09: - ok = put(emitter, 't') - case 0x0A: - ok = put(emitter, 'n') - case 0x0b: - ok = put(emitter, 'v') - case 0x0c: - ok = put(emitter, 'f') - case 0x0d: - ok = put(emitter, 'r') - case 0x1b: - ok = put(emitter, 'e') - case 0x22: - ok = put(emitter, '"') - case 0x5c: - ok = put(emitter, '\\') - case 0x85: - ok = put(emitter, 'N') - case 0xA0: - ok = put(emitter, '_') - case 0x2028: - ok = put(emitter, 'L') - case 0x2029: - ok = put(emitter, 'P') - default: - if v <= 0xFF { - ok = put(emitter, 'x') - w = 2 - } else if v <= 0xFFFF { - ok = put(emitter, 'u') - w = 4 - } else { - ok = put(emitter, 'U') - w = 8 - } - for k := (w - 1) * 4; ok && k >= 0; k -= 4 { - digit := byte((v >> uint(k)) & 0x0F) - if digit < 10 { - ok = put(emitter, digit+'0') - } else { - ok = put(emitter, digit+'A'-10) - } - } - } - if !ok { - return false - } - spaces = false - } else if is_space(value, i) { - if allow_breaks && !spaces && emitter.column > emitter.best_width && i > 0 && i < len(value)-1 { - if !yaml_emitter_write_indent(emitter) { - return false - } - if is_space(value, i+1) { - if !put(emitter, '\\') { - return false - } - } - i += width(value[i]) - } else if !write(emitter, value, &i) { - return false - } - spaces = true - } else { - if !write(emitter, value, &i) { - return false - } - spaces = false - } - } - if !yaml_emitter_write_indicator(emitter, []byte{'"'}, false, false, false) { - return false - } - emitter.whitespace = false - emitter.indention = false - return true -} - -func yaml_emitter_write_block_scalar_hints(emitter *yaml_emitter_t, value []byte) bool { - if is_space(value, 0) || is_break(value, 0) { - indent_hint := []byte{'0' + byte(emitter.best_indent)} - if !yaml_emitter_write_indicator(emitter, indent_hint, false, false, false) { - return false - } - } - - emitter.open_ended = false - - var chomp_hint [1]byte - if len(value) == 0 { - chomp_hint[0] = '-' - } else { - i := len(value) - 1 - for value[i]&0xC0 == 0x80 { - i-- - } - if !is_break(value, i) { - chomp_hint[0] = '-' - } else if i == 0 { - chomp_hint[0] = '+' - emitter.open_ended = true - } else { - i-- - for value[i]&0xC0 == 0x80 { - i-- - } - if is_break(value, i) { - chomp_hint[0] = '+' - emitter.open_ended = true - } - } - } - if chomp_hint[0] != 0 { - if !yaml_emitter_write_indicator(emitter, chomp_hint[:], false, false, false) { - return false - } - } - return true -} - -func yaml_emitter_write_literal_scalar(emitter *yaml_emitter_t, value []byte) bool { - if !yaml_emitter_write_indicator(emitter, []byte{'|'}, true, false, false) { - return false - } - if !yaml_emitter_write_block_scalar_hints(emitter, value) { - return false - } - if !put_break(emitter) { - return false - } - emitter.indention = true - emitter.whitespace = true - breaks := true - for i := 0; i < len(value); { - if is_break(value, i) { - if !write_break(emitter, value, &i) { - return false - } - emitter.indention = true - breaks = true - } else { - if breaks { - if !yaml_emitter_write_indent(emitter) { - return false - } - } - if !write(emitter, value, &i) { - return false - } - emitter.indention = false - breaks = false - } - } - - return true -} - -func yaml_emitter_write_folded_scalar(emitter *yaml_emitter_t, value []byte) bool { - if !yaml_emitter_write_indicator(emitter, []byte{'>'}, true, false, false) { - return false - } - if !yaml_emitter_write_block_scalar_hints(emitter, value) { - return false - } - - if !put_break(emitter) { - return false - } - emitter.indention = true - emitter.whitespace = true - - breaks := true - leading_spaces := true - for i := 0; i < len(value); { - if is_break(value, i) { - if !breaks && !leading_spaces && value[i] == '\n' { - k := 0 - for is_break(value, k) { - k += width(value[k]) - } - if !is_blankz(value, k) { - if !put_break(emitter) { - return false - } - } - } - if !write_break(emitter, value, &i) { - return false - } - emitter.indention = true - breaks = true - } else { - if breaks { - if !yaml_emitter_write_indent(emitter) { - return false - } - leading_spaces = is_blank(value, i) - } - if !breaks && is_space(value, i) && !is_space(value, i+1) && emitter.column > emitter.best_width { - if !yaml_emitter_write_indent(emitter) { - return false - } - i += width(value[i]) - } else { - if !write(emitter, value, &i) { - return false - } - } - emitter.indention = false - breaks = false - } - } - return true -} diff --git a/vendor/gopkg.in/yaml.v2/encode.go b/vendor/gopkg.in/yaml.v2/encode.go deleted file mode 100644 index 0ee738e..0000000 --- a/vendor/gopkg.in/yaml.v2/encode.go +++ /dev/null @@ -1,390 +0,0 @@ -package yaml - -import ( - "encoding" - "fmt" - "io" - "reflect" - "regexp" - "sort" - "strconv" - "strings" - "time" - "unicode/utf8" -) - -// jsonNumber is the interface of the encoding/json.Number datatype. -// Repeating the interface here avoids a dependency on encoding/json, and also -// supports other libraries like jsoniter, which use a similar datatype with -// the same interface. Detecting this interface is useful when dealing with -// structures containing json.Number, which is a string under the hood. The -// encoder should prefer the use of Int64(), Float64() and string(), in that -// order, when encoding this type. -type jsonNumber interface { - Float64() (float64, error) - Int64() (int64, error) - String() string -} - -type encoder struct { - emitter yaml_emitter_t - event yaml_event_t - out []byte - flow bool - // doneInit holds whether the initial stream_start_event has been - // emitted. - doneInit bool -} - -func newEncoder() *encoder { - e := &encoder{} - yaml_emitter_initialize(&e.emitter) - yaml_emitter_set_output_string(&e.emitter, &e.out) - yaml_emitter_set_unicode(&e.emitter, true) - return e -} - -func newEncoderWithWriter(w io.Writer) *encoder { - e := &encoder{} - yaml_emitter_initialize(&e.emitter) - yaml_emitter_set_output_writer(&e.emitter, w) - yaml_emitter_set_unicode(&e.emitter, true) - return e -} - -func (e *encoder) init() { - if e.doneInit { - return - } - yaml_stream_start_event_initialize(&e.event, yaml_UTF8_ENCODING) - e.emit() - e.doneInit = true -} - -func (e *encoder) finish() { - e.emitter.open_ended = false - yaml_stream_end_event_initialize(&e.event) - e.emit() -} - -func (e *encoder) destroy() { - yaml_emitter_delete(&e.emitter) -} - -func (e *encoder) emit() { - // This will internally delete the e.event value. - e.must(yaml_emitter_emit(&e.emitter, &e.event)) -} - -func (e *encoder) must(ok bool) { - if !ok { - msg := e.emitter.problem - if msg == "" { - msg = "unknown problem generating YAML content" - } - failf("%s", msg) - } -} - -func (e *encoder) marshalDoc(tag string, in reflect.Value) { - e.init() - yaml_document_start_event_initialize(&e.event, nil, nil, true) - e.emit() - e.marshal(tag, in) - yaml_document_end_event_initialize(&e.event, true) - e.emit() -} - -func (e *encoder) marshal(tag string, in reflect.Value) { - if !in.IsValid() || in.Kind() == reflect.Ptr && in.IsNil() { - e.nilv() - return - } - iface := in.Interface() - switch m := iface.(type) { - case jsonNumber: - integer, err := m.Int64() - if err == nil { - // In this case the json.Number is a valid int64 - in = reflect.ValueOf(integer) - break - } - float, err := m.Float64() - if err == nil { - // In this case the json.Number is a valid float64 - in = reflect.ValueOf(float) - break - } - // fallback case - no number could be obtained - in = reflect.ValueOf(m.String()) - case time.Time, *time.Time: - // Although time.Time implements TextMarshaler, - // we don't want to treat it as a string for YAML - // purposes because YAML has special support for - // timestamps. - case Marshaler: - v, err := m.MarshalYAML() - if err != nil { - fail(err) - } - if v == nil { - e.nilv() - return - } - in = reflect.ValueOf(v) - case encoding.TextMarshaler: - text, err := m.MarshalText() - if err != nil { - fail(err) - } - in = reflect.ValueOf(string(text)) - case nil: - e.nilv() - return - } - switch in.Kind() { - case reflect.Interface: - e.marshal(tag, in.Elem()) - case reflect.Map: - e.mapv(tag, in) - case reflect.Ptr: - if in.Type() == ptrTimeType { - e.timev(tag, in.Elem()) - } else { - e.marshal(tag, in.Elem()) - } - case reflect.Struct: - if in.Type() == timeType { - e.timev(tag, in) - } else { - e.structv(tag, in) - } - case reflect.Slice, reflect.Array: - if in.Type().Elem() == mapItemType { - e.itemsv(tag, in) - } else { - e.slicev(tag, in) - } - case reflect.String: - e.stringv(tag, in) - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - if in.Type() == durationType { - e.stringv(tag, reflect.ValueOf(iface.(time.Duration).String())) - } else { - e.intv(tag, in) - } - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - e.uintv(tag, in) - case reflect.Float32, reflect.Float64: - e.floatv(tag, in) - case reflect.Bool: - e.boolv(tag, in) - default: - panic("cannot marshal type: " + in.Type().String()) - } -} - -func (e *encoder) mapv(tag string, in reflect.Value) { - e.mappingv(tag, func() { - keys := keyList(in.MapKeys()) - sort.Sort(keys) - for _, k := range keys { - e.marshal("", k) - e.marshal("", in.MapIndex(k)) - } - }) -} - -func (e *encoder) itemsv(tag string, in reflect.Value) { - e.mappingv(tag, func() { - slice := in.Convert(reflect.TypeOf([]MapItem{})).Interface().([]MapItem) - for _, item := range slice { - e.marshal("", reflect.ValueOf(item.Key)) - e.marshal("", reflect.ValueOf(item.Value)) - } - }) -} - -func (e *encoder) structv(tag string, in reflect.Value) { - sinfo, err := getStructInfo(in.Type()) - if err != nil { - panic(err) - } - e.mappingv(tag, func() { - for _, info := range sinfo.FieldsList { - var value reflect.Value - if info.Inline == nil { - value = in.Field(info.Num) - } else { - value = in.FieldByIndex(info.Inline) - } - if info.OmitEmpty && isZero(value) { - continue - } - e.marshal("", reflect.ValueOf(info.Key)) - e.flow = info.Flow - e.marshal("", value) - } - if sinfo.InlineMap >= 0 { - m := in.Field(sinfo.InlineMap) - if m.Len() > 0 { - e.flow = false - keys := keyList(m.MapKeys()) - sort.Sort(keys) - for _, k := range keys { - if _, found := sinfo.FieldsMap[k.String()]; found { - panic(fmt.Sprintf("Can't have key %q in inlined map; conflicts with struct field", k.String())) - } - e.marshal("", k) - e.flow = false - e.marshal("", m.MapIndex(k)) - } - } - } - }) -} - -func (e *encoder) mappingv(tag string, f func()) { - implicit := tag == "" - style := yaml_BLOCK_MAPPING_STYLE - if e.flow { - e.flow = false - style = yaml_FLOW_MAPPING_STYLE - } - yaml_mapping_start_event_initialize(&e.event, nil, []byte(tag), implicit, style) - e.emit() - f() - yaml_mapping_end_event_initialize(&e.event) - e.emit() -} - -func (e *encoder) slicev(tag string, in reflect.Value) { - implicit := tag == "" - style := yaml_BLOCK_SEQUENCE_STYLE - if e.flow { - e.flow = false - style = yaml_FLOW_SEQUENCE_STYLE - } - e.must(yaml_sequence_start_event_initialize(&e.event, nil, []byte(tag), implicit, style)) - e.emit() - n := in.Len() - for i := 0; i < n; i++ { - e.marshal("", in.Index(i)) - } - e.must(yaml_sequence_end_event_initialize(&e.event)) - e.emit() -} - -// isBase60 returns whether s is in base 60 notation as defined in YAML 1.1. -// -// The base 60 float notation in YAML 1.1 is a terrible idea and is unsupported -// in YAML 1.2 and by this package, but these should be marshalled quoted for -// the time being for compatibility with other parsers. -func isBase60Float(s string) (result bool) { - // Fast path. - if s == "" { - return false - } - c := s[0] - if !(c == '+' || c == '-' || c >= '0' && c <= '9') || strings.IndexByte(s, ':') < 0 { - return false - } - // Do the full match. - return base60float.MatchString(s) -} - -// From http://yaml.org/type/float.html, except the regular expression there -// is bogus. In practice parsers do not enforce the "\.[0-9_]*" suffix. -var base60float = regexp.MustCompile(`^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+(?:\.[0-9_]*)?$`) - -func (e *encoder) stringv(tag string, in reflect.Value) { - var style yaml_scalar_style_t - s := in.String() - canUsePlain := true - switch { - case !utf8.ValidString(s): - if tag == yaml_BINARY_TAG { - failf("explicitly tagged !!binary data must be base64-encoded") - } - if tag != "" { - failf("cannot marshal invalid UTF-8 data as %s", shortTag(tag)) - } - // It can't be encoded directly as YAML so use a binary tag - // and encode it as base64. - tag = yaml_BINARY_TAG - s = encodeBase64(s) - case tag == "": - // Check to see if it would resolve to a specific - // tag when encoded unquoted. If it doesn't, - // there's no need to quote it. - rtag, _ := resolve("", s) - canUsePlain = rtag == yaml_STR_TAG && !isBase60Float(s) - } - // Note: it's possible for user code to emit invalid YAML - // if they explicitly specify a tag and a string containing - // text that's incompatible with that tag. - switch { - case strings.Contains(s, "\n"): - style = yaml_LITERAL_SCALAR_STYLE - case canUsePlain: - style = yaml_PLAIN_SCALAR_STYLE - default: - style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - e.emitScalar(s, "", tag, style) -} - -func (e *encoder) boolv(tag string, in reflect.Value) { - var s string - if in.Bool() { - s = "true" - } else { - s = "false" - } - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) intv(tag string, in reflect.Value) { - s := strconv.FormatInt(in.Int(), 10) - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) uintv(tag string, in reflect.Value) { - s := strconv.FormatUint(in.Uint(), 10) - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) timev(tag string, in reflect.Value) { - t := in.Interface().(time.Time) - s := t.Format(time.RFC3339Nano) - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) floatv(tag string, in reflect.Value) { - // Issue #352: When formatting, use the precision of the underlying value - precision := 64 - if in.Kind() == reflect.Float32 { - precision = 32 - } - - s := strconv.FormatFloat(in.Float(), 'g', -1, precision) - switch s { - case "+Inf": - s = ".inf" - case "-Inf": - s = "-.inf" - case "NaN": - s = ".nan" - } - e.emitScalar(s, "", tag, yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) nilv() { - e.emitScalar("null", "", "", yaml_PLAIN_SCALAR_STYLE) -} - -func (e *encoder) emitScalar(value, anchor, tag string, style yaml_scalar_style_t) { - implicit := tag == "" - e.must(yaml_scalar_event_initialize(&e.event, []byte(anchor), []byte(tag), []byte(value), implicit, implicit, style)) - e.emit() -} diff --git a/vendor/gopkg.in/yaml.v2/parserc.go b/vendor/gopkg.in/yaml.v2/parserc.go deleted file mode 100644 index 81d05df..0000000 --- a/vendor/gopkg.in/yaml.v2/parserc.go +++ /dev/null @@ -1,1095 +0,0 @@ -package yaml - -import ( - "bytes" -) - -// The parser implements the following grammar: -// -// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END -// implicit_document ::= block_node DOCUMENT-END* -// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -// block_node_or_indentless_sequence ::= -// ALIAS -// | properties (block_content | indentless_block_sequence)? -// | block_content -// | indentless_block_sequence -// block_node ::= ALIAS -// | properties block_content? -// | block_content -// flow_node ::= ALIAS -// | properties flow_content? -// | flow_content -// properties ::= TAG ANCHOR? | ANCHOR TAG? -// block_content ::= block_collection | flow_collection | SCALAR -// flow_content ::= flow_collection | SCALAR -// block_collection ::= block_sequence | block_mapping -// flow_collection ::= flow_sequence | flow_mapping -// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END -// indentless_sequence ::= (BLOCK-ENTRY block_node?)+ -// block_mapping ::= BLOCK-MAPPING_START -// ((KEY block_node_or_indentless_sequence?)? -// (VALUE block_node_or_indentless_sequence?)?)* -// BLOCK-END -// flow_sequence ::= FLOW-SEQUENCE-START -// (flow_sequence_entry FLOW-ENTRY)* -// flow_sequence_entry? -// FLOW-SEQUENCE-END -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// flow_mapping ::= FLOW-MAPPING-START -// (flow_mapping_entry FLOW-ENTRY)* -// flow_mapping_entry? -// FLOW-MAPPING-END -// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? - -// Peek the next token in the token queue. -func peek_token(parser *yaml_parser_t) *yaml_token_t { - if parser.token_available || yaml_parser_fetch_more_tokens(parser) { - return &parser.tokens[parser.tokens_head] - } - return nil -} - -// Remove the next token from the queue (must be called after peek_token). -func skip_token(parser *yaml_parser_t) { - parser.token_available = false - parser.tokens_parsed++ - parser.stream_end_produced = parser.tokens[parser.tokens_head].typ == yaml_STREAM_END_TOKEN - parser.tokens_head++ -} - -// Get the next event. -func yaml_parser_parse(parser *yaml_parser_t, event *yaml_event_t) bool { - // Erase the event object. - *event = yaml_event_t{} - - // No events after the end of the stream or error. - if parser.stream_end_produced || parser.error != yaml_NO_ERROR || parser.state == yaml_PARSE_END_STATE { - return true - } - - // Generate the next event. - return yaml_parser_state_machine(parser, event) -} - -// Set parser error. -func yaml_parser_set_parser_error(parser *yaml_parser_t, problem string, problem_mark yaml_mark_t) bool { - parser.error = yaml_PARSER_ERROR - parser.problem = problem - parser.problem_mark = problem_mark - return false -} - -func yaml_parser_set_parser_error_context(parser *yaml_parser_t, context string, context_mark yaml_mark_t, problem string, problem_mark yaml_mark_t) bool { - parser.error = yaml_PARSER_ERROR - parser.context = context - parser.context_mark = context_mark - parser.problem = problem - parser.problem_mark = problem_mark - return false -} - -// State dispatcher. -func yaml_parser_state_machine(parser *yaml_parser_t, event *yaml_event_t) bool { - //trace("yaml_parser_state_machine", "state:", parser.state.String()) - - switch parser.state { - case yaml_PARSE_STREAM_START_STATE: - return yaml_parser_parse_stream_start(parser, event) - - case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE: - return yaml_parser_parse_document_start(parser, event, true) - - case yaml_PARSE_DOCUMENT_START_STATE: - return yaml_parser_parse_document_start(parser, event, false) - - case yaml_PARSE_DOCUMENT_CONTENT_STATE: - return yaml_parser_parse_document_content(parser, event) - - case yaml_PARSE_DOCUMENT_END_STATE: - return yaml_parser_parse_document_end(parser, event) - - case yaml_PARSE_BLOCK_NODE_STATE: - return yaml_parser_parse_node(parser, event, true, false) - - case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE: - return yaml_parser_parse_node(parser, event, true, true) - - case yaml_PARSE_FLOW_NODE_STATE: - return yaml_parser_parse_node(parser, event, false, false) - - case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE: - return yaml_parser_parse_block_sequence_entry(parser, event, true) - - case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_block_sequence_entry(parser, event, false) - - case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_indentless_sequence_entry(parser, event) - - case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE: - return yaml_parser_parse_block_mapping_key(parser, event, true) - - case yaml_PARSE_BLOCK_MAPPING_KEY_STATE: - return yaml_parser_parse_block_mapping_key(parser, event, false) - - case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE: - return yaml_parser_parse_block_mapping_value(parser, event) - - case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE: - return yaml_parser_parse_flow_sequence_entry(parser, event, true) - - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE: - return yaml_parser_parse_flow_sequence_entry(parser, event, false) - - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_key(parser, event) - - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_value(parser, event) - - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE: - return yaml_parser_parse_flow_sequence_entry_mapping_end(parser, event) - - case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE: - return yaml_parser_parse_flow_mapping_key(parser, event, true) - - case yaml_PARSE_FLOW_MAPPING_KEY_STATE: - return yaml_parser_parse_flow_mapping_key(parser, event, false) - - case yaml_PARSE_FLOW_MAPPING_VALUE_STATE: - return yaml_parser_parse_flow_mapping_value(parser, event, false) - - case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE: - return yaml_parser_parse_flow_mapping_value(parser, event, true) - - default: - panic("invalid parser state") - } -} - -// Parse the production: -// stream ::= STREAM-START implicit_document? explicit_document* STREAM-END -// ************ -func yaml_parser_parse_stream_start(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_STREAM_START_TOKEN { - return yaml_parser_set_parser_error(parser, "did not find expected ", token.start_mark) - } - parser.state = yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE - *event = yaml_event_t{ - typ: yaml_STREAM_START_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - encoding: token.encoding, - } - skip_token(parser) - return true -} - -// Parse the productions: -// implicit_document ::= block_node DOCUMENT-END* -// * -// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -// ************************* -func yaml_parser_parse_document_start(parser *yaml_parser_t, event *yaml_event_t, implicit bool) bool { - - token := peek_token(parser) - if token == nil { - return false - } - - // Parse extra document end indicators. - if !implicit { - for token.typ == yaml_DOCUMENT_END_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } - } - - if implicit && token.typ != yaml_VERSION_DIRECTIVE_TOKEN && - token.typ != yaml_TAG_DIRECTIVE_TOKEN && - token.typ != yaml_DOCUMENT_START_TOKEN && - token.typ != yaml_STREAM_END_TOKEN { - // Parse an implicit document. - if !yaml_parser_process_directives(parser, nil, nil) { - return false - } - parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE) - parser.state = yaml_PARSE_BLOCK_NODE_STATE - - *event = yaml_event_t{ - typ: yaml_DOCUMENT_START_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - - } else if token.typ != yaml_STREAM_END_TOKEN { - // Parse an explicit document. - var version_directive *yaml_version_directive_t - var tag_directives []yaml_tag_directive_t - start_mark := token.start_mark - if !yaml_parser_process_directives(parser, &version_directive, &tag_directives) { - return false - } - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_DOCUMENT_START_TOKEN { - yaml_parser_set_parser_error(parser, - "did not find expected ", token.start_mark) - return false - } - parser.states = append(parser.states, yaml_PARSE_DOCUMENT_END_STATE) - parser.state = yaml_PARSE_DOCUMENT_CONTENT_STATE - end_mark := token.end_mark - - *event = yaml_event_t{ - typ: yaml_DOCUMENT_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - version_directive: version_directive, - tag_directives: tag_directives, - implicit: false, - } - skip_token(parser) - - } else { - // Parse the stream end. - parser.state = yaml_PARSE_END_STATE - *event = yaml_event_t{ - typ: yaml_STREAM_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - skip_token(parser) - } - - return true -} - -// Parse the productions: -// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -// *********** -// -func yaml_parser_parse_document_content(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_VERSION_DIRECTIVE_TOKEN || - token.typ == yaml_TAG_DIRECTIVE_TOKEN || - token.typ == yaml_DOCUMENT_START_TOKEN || - token.typ == yaml_DOCUMENT_END_TOKEN || - token.typ == yaml_STREAM_END_TOKEN { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - return yaml_parser_process_empty_scalar(parser, event, - token.start_mark) - } - return yaml_parser_parse_node(parser, event, true, false) -} - -// Parse the productions: -// implicit_document ::= block_node DOCUMENT-END* -// ************* -// explicit_document ::= DIRECTIVE* DOCUMENT-START block_node? DOCUMENT-END* -// -func yaml_parser_parse_document_end(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - - start_mark := token.start_mark - end_mark := token.start_mark - - implicit := true - if token.typ == yaml_DOCUMENT_END_TOKEN { - end_mark = token.end_mark - skip_token(parser) - implicit = false - } - - parser.tag_directives = parser.tag_directives[:0] - - parser.state = yaml_PARSE_DOCUMENT_START_STATE - *event = yaml_event_t{ - typ: yaml_DOCUMENT_END_EVENT, - start_mark: start_mark, - end_mark: end_mark, - implicit: implicit, - } - return true -} - -// Parse the productions: -// block_node_or_indentless_sequence ::= -// ALIAS -// ***** -// | properties (block_content | indentless_block_sequence)? -// ********** * -// | block_content | indentless_block_sequence -// * -// block_node ::= ALIAS -// ***** -// | properties block_content? -// ********** * -// | block_content -// * -// flow_node ::= ALIAS -// ***** -// | properties flow_content? -// ********** * -// | flow_content -// * -// properties ::= TAG ANCHOR? | ANCHOR TAG? -// ************************* -// block_content ::= block_collection | flow_collection | SCALAR -// ****** -// flow_content ::= flow_collection | SCALAR -// ****** -func yaml_parser_parse_node(parser *yaml_parser_t, event *yaml_event_t, block, indentless_sequence bool) bool { - //defer trace("yaml_parser_parse_node", "block:", block, "indentless_sequence:", indentless_sequence)() - - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ == yaml_ALIAS_TOKEN { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - *event = yaml_event_t{ - typ: yaml_ALIAS_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - anchor: token.value, - } - skip_token(parser) - return true - } - - start_mark := token.start_mark - end_mark := token.start_mark - - var tag_token bool - var tag_handle, tag_suffix, anchor []byte - var tag_mark yaml_mark_t - if token.typ == yaml_ANCHOR_TOKEN { - anchor = token.value - start_mark = token.start_mark - end_mark = token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_TAG_TOKEN { - tag_token = true - tag_handle = token.value - tag_suffix = token.suffix - tag_mark = token.start_mark - end_mark = token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } - } else if token.typ == yaml_TAG_TOKEN { - tag_token = true - tag_handle = token.value - tag_suffix = token.suffix - start_mark = token.start_mark - tag_mark = token.start_mark - end_mark = token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_ANCHOR_TOKEN { - anchor = token.value - end_mark = token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } - } - - var tag []byte - if tag_token { - if len(tag_handle) == 0 { - tag = tag_suffix - tag_suffix = nil - } else { - for i := range parser.tag_directives { - if bytes.Equal(parser.tag_directives[i].handle, tag_handle) { - tag = append([]byte(nil), parser.tag_directives[i].prefix...) - tag = append(tag, tag_suffix...) - break - } - } - if len(tag) == 0 { - yaml_parser_set_parser_error_context(parser, - "while parsing a node", start_mark, - "found undefined tag handle", tag_mark) - return false - } - } - } - - implicit := len(tag) == 0 - if indentless_sequence && token.typ == yaml_BLOCK_ENTRY_TOKEN { - end_mark = token.end_mark - parser.state = yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE - *event = yaml_event_t{ - typ: yaml_SEQUENCE_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_BLOCK_SEQUENCE_STYLE), - } - return true - } - if token.typ == yaml_SCALAR_TOKEN { - var plain_implicit, quoted_implicit bool - end_mark = token.end_mark - if (len(tag) == 0 && token.style == yaml_PLAIN_SCALAR_STYLE) || (len(tag) == 1 && tag[0] == '!') { - plain_implicit = true - } else if len(tag) == 0 { - quoted_implicit = true - } - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - - *event = yaml_event_t{ - typ: yaml_SCALAR_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - value: token.value, - implicit: plain_implicit, - quoted_implicit: quoted_implicit, - style: yaml_style_t(token.style), - } - skip_token(parser) - return true - } - if token.typ == yaml_FLOW_SEQUENCE_START_TOKEN { - // [Go] Some of the events below can be merged as they differ only on style. - end_mark = token.end_mark - parser.state = yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE - *event = yaml_event_t{ - typ: yaml_SEQUENCE_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_FLOW_SEQUENCE_STYLE), - } - return true - } - if token.typ == yaml_FLOW_MAPPING_START_TOKEN { - end_mark = token.end_mark - parser.state = yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE - *event = yaml_event_t{ - typ: yaml_MAPPING_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_FLOW_MAPPING_STYLE), - } - return true - } - if block && token.typ == yaml_BLOCK_SEQUENCE_START_TOKEN { - end_mark = token.end_mark - parser.state = yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE - *event = yaml_event_t{ - typ: yaml_SEQUENCE_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_BLOCK_SEQUENCE_STYLE), - } - return true - } - if block && token.typ == yaml_BLOCK_MAPPING_START_TOKEN { - end_mark = token.end_mark - parser.state = yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE - *event = yaml_event_t{ - typ: yaml_MAPPING_START_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - style: yaml_style_t(yaml_BLOCK_MAPPING_STYLE), - } - return true - } - if len(anchor) > 0 || len(tag) > 0 { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - - *event = yaml_event_t{ - typ: yaml_SCALAR_EVENT, - start_mark: start_mark, - end_mark: end_mark, - anchor: anchor, - tag: tag, - implicit: implicit, - quoted_implicit: false, - style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE), - } - return true - } - - context := "while parsing a flow node" - if block { - context = "while parsing a block node" - } - yaml_parser_set_parser_error_context(parser, context, start_mark, - "did not find expected node content", token.start_mark) - return false -} - -// Parse the productions: -// block_sequence ::= BLOCK-SEQUENCE-START (BLOCK-ENTRY block_node?)* BLOCK-END -// ******************** *********** * ********* -// -func yaml_parser_parse_block_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { - if first { - token := peek_token(parser) - parser.marks = append(parser.marks, token.start_mark) - skip_token(parser) - } - - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ == yaml_BLOCK_ENTRY_TOKEN { - mark := token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_BLOCK_ENTRY_TOKEN && token.typ != yaml_BLOCK_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE) - return yaml_parser_parse_node(parser, event, true, false) - } else { - parser.state = yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) - } - } - if token.typ == yaml_BLOCK_END_TOKEN { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - - *event = yaml_event_t{ - typ: yaml_SEQUENCE_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - - skip_token(parser) - return true - } - - context_mark := parser.marks[len(parser.marks)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - return yaml_parser_set_parser_error_context(parser, - "while parsing a block collection", context_mark, - "did not find expected '-' indicator", token.start_mark) -} - -// Parse the productions: -// indentless_sequence ::= (BLOCK-ENTRY block_node?)+ -// *********** * -func yaml_parser_parse_indentless_sequence_entry(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ == yaml_BLOCK_ENTRY_TOKEN { - mark := token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_BLOCK_ENTRY_TOKEN && - token.typ != yaml_KEY_TOKEN && - token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_BLOCK_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE) - return yaml_parser_parse_node(parser, event, true, false) - } - parser.state = yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) - } - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - - *event = yaml_event_t{ - typ: yaml_SEQUENCE_END_EVENT, - start_mark: token.start_mark, - end_mark: token.start_mark, // [Go] Shouldn't this be token.end_mark? - } - return true -} - -// Parse the productions: -// block_mapping ::= BLOCK-MAPPING_START -// ******************* -// ((KEY block_node_or_indentless_sequence?)? -// *** * -// (VALUE block_node_or_indentless_sequence?)?)* -// -// BLOCK-END -// ********* -// -func yaml_parser_parse_block_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { - if first { - token := peek_token(parser) - parser.marks = append(parser.marks, token.start_mark) - skip_token(parser) - } - - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ == yaml_KEY_TOKEN { - mark := token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_KEY_TOKEN && - token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_BLOCK_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_BLOCK_MAPPING_VALUE_STATE) - return yaml_parser_parse_node(parser, event, true, true) - } else { - parser.state = yaml_PARSE_BLOCK_MAPPING_VALUE_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) - } - } else if token.typ == yaml_BLOCK_END_TOKEN { - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - *event = yaml_event_t{ - typ: yaml_MAPPING_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - skip_token(parser) - return true - } - - context_mark := parser.marks[len(parser.marks)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - return yaml_parser_set_parser_error_context(parser, - "while parsing a block mapping", context_mark, - "did not find expected key", token.start_mark) -} - -// Parse the productions: -// block_mapping ::= BLOCK-MAPPING_START -// -// ((KEY block_node_or_indentless_sequence?)? -// -// (VALUE block_node_or_indentless_sequence?)?)* -// ***** * -// BLOCK-END -// -// -func yaml_parser_parse_block_mapping_value(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_VALUE_TOKEN { - mark := token.end_mark - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_KEY_TOKEN && - token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_BLOCK_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_BLOCK_MAPPING_KEY_STATE) - return yaml_parser_parse_node(parser, event, true, true) - } - parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) - } - parser.state = yaml_PARSE_BLOCK_MAPPING_KEY_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) -} - -// Parse the productions: -// flow_sequence ::= FLOW-SEQUENCE-START -// ******************* -// (flow_sequence_entry FLOW-ENTRY)* -// * ********** -// flow_sequence_entry? -// * -// FLOW-SEQUENCE-END -// ***************** -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// * -// -func yaml_parser_parse_flow_sequence_entry(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { - if first { - token := peek_token(parser) - parser.marks = append(parser.marks, token.start_mark) - skip_token(parser) - } - token := peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { - if !first { - if token.typ == yaml_FLOW_ENTRY_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } else { - context_mark := parser.marks[len(parser.marks)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - return yaml_parser_set_parser_error_context(parser, - "while parsing a flow sequence", context_mark, - "did not find expected ',' or ']'", token.start_mark) - } - } - - if token.typ == yaml_KEY_TOKEN { - parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE - *event = yaml_event_t{ - typ: yaml_MAPPING_START_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - implicit: true, - style: yaml_style_t(yaml_FLOW_MAPPING_STYLE), - } - skip_token(parser) - return true - } else if token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - } - - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - - *event = yaml_event_t{ - typ: yaml_SEQUENCE_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - - skip_token(parser) - return true -} - -// -// Parse the productions: -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// *** * -// -func yaml_parser_parse_flow_sequence_entry_mapping_key(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_FLOW_ENTRY_TOKEN && - token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - mark := token.end_mark - skip_token(parser) - parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE - return yaml_parser_process_empty_scalar(parser, event, mark) -} - -// Parse the productions: -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// ***** * -// -func yaml_parser_parse_flow_sequence_entry_mapping_value(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - if token.typ == yaml_VALUE_TOKEN { - skip_token(parser) - token := peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_FLOW_ENTRY_TOKEN && token.typ != yaml_FLOW_SEQUENCE_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - } - parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) -} - -// Parse the productions: -// flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// * -// -func yaml_parser_parse_flow_sequence_entry_mapping_end(parser *yaml_parser_t, event *yaml_event_t) bool { - token := peek_token(parser) - if token == nil { - return false - } - parser.state = yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE - *event = yaml_event_t{ - typ: yaml_MAPPING_END_EVENT, - start_mark: token.start_mark, - end_mark: token.start_mark, // [Go] Shouldn't this be end_mark? - } - return true -} - -// Parse the productions: -// flow_mapping ::= FLOW-MAPPING-START -// ****************** -// (flow_mapping_entry FLOW-ENTRY)* -// * ********** -// flow_mapping_entry? -// ****************** -// FLOW-MAPPING-END -// **************** -// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// * *** * -// -func yaml_parser_parse_flow_mapping_key(parser *yaml_parser_t, event *yaml_event_t, first bool) bool { - if first { - token := peek_token(parser) - parser.marks = append(parser.marks, token.start_mark) - skip_token(parser) - } - - token := peek_token(parser) - if token == nil { - return false - } - - if token.typ != yaml_FLOW_MAPPING_END_TOKEN { - if !first { - if token.typ == yaml_FLOW_ENTRY_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } else { - context_mark := parser.marks[len(parser.marks)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - return yaml_parser_set_parser_error_context(parser, - "while parsing a flow mapping", context_mark, - "did not find expected ',' or '}'", token.start_mark) - } - } - - if token.typ == yaml_KEY_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_VALUE_TOKEN && - token.typ != yaml_FLOW_ENTRY_TOKEN && - token.typ != yaml_FLOW_MAPPING_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_VALUE_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } else { - parser.state = yaml_PARSE_FLOW_MAPPING_VALUE_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) - } - } else if token.typ != yaml_FLOW_MAPPING_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - } - - parser.state = parser.states[len(parser.states)-1] - parser.states = parser.states[:len(parser.states)-1] - parser.marks = parser.marks[:len(parser.marks)-1] - *event = yaml_event_t{ - typ: yaml_MAPPING_END_EVENT, - start_mark: token.start_mark, - end_mark: token.end_mark, - } - skip_token(parser) - return true -} - -// Parse the productions: -// flow_mapping_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? -// * ***** * -// -func yaml_parser_parse_flow_mapping_value(parser *yaml_parser_t, event *yaml_event_t, empty bool) bool { - token := peek_token(parser) - if token == nil { - return false - } - if empty { - parser.state = yaml_PARSE_FLOW_MAPPING_KEY_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) - } - if token.typ == yaml_VALUE_TOKEN { - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - if token.typ != yaml_FLOW_ENTRY_TOKEN && token.typ != yaml_FLOW_MAPPING_END_TOKEN { - parser.states = append(parser.states, yaml_PARSE_FLOW_MAPPING_KEY_STATE) - return yaml_parser_parse_node(parser, event, false, false) - } - } - parser.state = yaml_PARSE_FLOW_MAPPING_KEY_STATE - return yaml_parser_process_empty_scalar(parser, event, token.start_mark) -} - -// Generate an empty scalar event. -func yaml_parser_process_empty_scalar(parser *yaml_parser_t, event *yaml_event_t, mark yaml_mark_t) bool { - *event = yaml_event_t{ - typ: yaml_SCALAR_EVENT, - start_mark: mark, - end_mark: mark, - value: nil, // Empty - implicit: true, - style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE), - } - return true -} - -var default_tag_directives = []yaml_tag_directive_t{ - {[]byte("!"), []byte("!")}, - {[]byte("!!"), []byte("tag:yaml.org,2002:")}, -} - -// Parse directives. -func yaml_parser_process_directives(parser *yaml_parser_t, - version_directive_ref **yaml_version_directive_t, - tag_directives_ref *[]yaml_tag_directive_t) bool { - - var version_directive *yaml_version_directive_t - var tag_directives []yaml_tag_directive_t - - token := peek_token(parser) - if token == nil { - return false - } - - for token.typ == yaml_VERSION_DIRECTIVE_TOKEN || token.typ == yaml_TAG_DIRECTIVE_TOKEN { - if token.typ == yaml_VERSION_DIRECTIVE_TOKEN { - if version_directive != nil { - yaml_parser_set_parser_error(parser, - "found duplicate %YAML directive", token.start_mark) - return false - } - if token.major != 1 || token.minor != 1 { - yaml_parser_set_parser_error(parser, - "found incompatible YAML document", token.start_mark) - return false - } - version_directive = &yaml_version_directive_t{ - major: token.major, - minor: token.minor, - } - } else if token.typ == yaml_TAG_DIRECTIVE_TOKEN { - value := yaml_tag_directive_t{ - handle: token.value, - prefix: token.prefix, - } - if !yaml_parser_append_tag_directive(parser, value, false, token.start_mark) { - return false - } - tag_directives = append(tag_directives, value) - } - - skip_token(parser) - token = peek_token(parser) - if token == nil { - return false - } - } - - for i := range default_tag_directives { - if !yaml_parser_append_tag_directive(parser, default_tag_directives[i], true, token.start_mark) { - return false - } - } - - if version_directive_ref != nil { - *version_directive_ref = version_directive - } - if tag_directives_ref != nil { - *tag_directives_ref = tag_directives - } - return true -} - -// Append a tag directive to the directives stack. -func yaml_parser_append_tag_directive(parser *yaml_parser_t, value yaml_tag_directive_t, allow_duplicates bool, mark yaml_mark_t) bool { - for i := range parser.tag_directives { - if bytes.Equal(value.handle, parser.tag_directives[i].handle) { - if allow_duplicates { - return true - } - return yaml_parser_set_parser_error(parser, "found duplicate %TAG directive", mark) - } - } - - // [Go] I suspect the copy is unnecessary. This was likely done - // because there was no way to track ownership of the data. - value_copy := yaml_tag_directive_t{ - handle: make([]byte, len(value.handle)), - prefix: make([]byte, len(value.prefix)), - } - copy(value_copy.handle, value.handle) - copy(value_copy.prefix, value.prefix) - parser.tag_directives = append(parser.tag_directives, value_copy) - return true -} diff --git a/vendor/gopkg.in/yaml.v2/readerc.go b/vendor/gopkg.in/yaml.v2/readerc.go deleted file mode 100644 index 7c1f5fa..0000000 --- a/vendor/gopkg.in/yaml.v2/readerc.go +++ /dev/null @@ -1,412 +0,0 @@ -package yaml - -import ( - "io" -) - -// Set the reader error and return 0. -func yaml_parser_set_reader_error(parser *yaml_parser_t, problem string, offset int, value int) bool { - parser.error = yaml_READER_ERROR - parser.problem = problem - parser.problem_offset = offset - parser.problem_value = value - return false -} - -// Byte order marks. -const ( - bom_UTF8 = "\xef\xbb\xbf" - bom_UTF16LE = "\xff\xfe" - bom_UTF16BE = "\xfe\xff" -) - -// Determine the input stream encoding by checking the BOM symbol. If no BOM is -// found, the UTF-8 encoding is assumed. Return 1 on success, 0 on failure. -func yaml_parser_determine_encoding(parser *yaml_parser_t) bool { - // Ensure that we had enough bytes in the raw buffer. - for !parser.eof && len(parser.raw_buffer)-parser.raw_buffer_pos < 3 { - if !yaml_parser_update_raw_buffer(parser) { - return false - } - } - - // Determine the encoding. - buf := parser.raw_buffer - pos := parser.raw_buffer_pos - avail := len(buf) - pos - if avail >= 2 && buf[pos] == bom_UTF16LE[0] && buf[pos+1] == bom_UTF16LE[1] { - parser.encoding = yaml_UTF16LE_ENCODING - parser.raw_buffer_pos += 2 - parser.offset += 2 - } else if avail >= 2 && buf[pos] == bom_UTF16BE[0] && buf[pos+1] == bom_UTF16BE[1] { - parser.encoding = yaml_UTF16BE_ENCODING - parser.raw_buffer_pos += 2 - parser.offset += 2 - } else if avail >= 3 && buf[pos] == bom_UTF8[0] && buf[pos+1] == bom_UTF8[1] && buf[pos+2] == bom_UTF8[2] { - parser.encoding = yaml_UTF8_ENCODING - parser.raw_buffer_pos += 3 - parser.offset += 3 - } else { - parser.encoding = yaml_UTF8_ENCODING - } - return true -} - -// Update the raw buffer. -func yaml_parser_update_raw_buffer(parser *yaml_parser_t) bool { - size_read := 0 - - // Return if the raw buffer is full. - if parser.raw_buffer_pos == 0 && len(parser.raw_buffer) == cap(parser.raw_buffer) { - return true - } - - // Return on EOF. - if parser.eof { - return true - } - - // Move the remaining bytes in the raw buffer to the beginning. - if parser.raw_buffer_pos > 0 && parser.raw_buffer_pos < len(parser.raw_buffer) { - copy(parser.raw_buffer, parser.raw_buffer[parser.raw_buffer_pos:]) - } - parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)-parser.raw_buffer_pos] - parser.raw_buffer_pos = 0 - - // Call the read handler to fill the buffer. - size_read, err := parser.read_handler(parser, parser.raw_buffer[len(parser.raw_buffer):cap(parser.raw_buffer)]) - parser.raw_buffer = parser.raw_buffer[:len(parser.raw_buffer)+size_read] - if err == io.EOF { - parser.eof = true - } else if err != nil { - return yaml_parser_set_reader_error(parser, "input error: "+err.Error(), parser.offset, -1) - } - return true -} - -// Ensure that the buffer contains at least `length` characters. -// Return true on success, false on failure. -// -// The length is supposed to be significantly less that the buffer size. -func yaml_parser_update_buffer(parser *yaml_parser_t, length int) bool { - if parser.read_handler == nil { - panic("read handler must be set") - } - - // [Go] This function was changed to guarantee the requested length size at EOF. - // The fact we need to do this is pretty awful, but the description above implies - // for that to be the case, and there are tests - - // If the EOF flag is set and the raw buffer is empty, do nothing. - if parser.eof && parser.raw_buffer_pos == len(parser.raw_buffer) { - // [Go] ACTUALLY! Read the documentation of this function above. - // This is just broken. To return true, we need to have the - // given length in the buffer. Not doing that means every single - // check that calls this function to make sure the buffer has a - // given length is Go) panicking; or C) accessing invalid memory. - //return true - } - - // Return if the buffer contains enough characters. - if parser.unread >= length { - return true - } - - // Determine the input encoding if it is not known yet. - if parser.encoding == yaml_ANY_ENCODING { - if !yaml_parser_determine_encoding(parser) { - return false - } - } - - // Move the unread characters to the beginning of the buffer. - buffer_len := len(parser.buffer) - if parser.buffer_pos > 0 && parser.buffer_pos < buffer_len { - copy(parser.buffer, parser.buffer[parser.buffer_pos:]) - buffer_len -= parser.buffer_pos - parser.buffer_pos = 0 - } else if parser.buffer_pos == buffer_len { - buffer_len = 0 - parser.buffer_pos = 0 - } - - // Open the whole buffer for writing, and cut it before returning. - parser.buffer = parser.buffer[:cap(parser.buffer)] - - // Fill the buffer until it has enough characters. - first := true - for parser.unread < length { - - // Fill the raw buffer if necessary. - if !first || parser.raw_buffer_pos == len(parser.raw_buffer) { - if !yaml_parser_update_raw_buffer(parser) { - parser.buffer = parser.buffer[:buffer_len] - return false - } - } - first = false - - // Decode the raw buffer. - inner: - for parser.raw_buffer_pos != len(parser.raw_buffer) { - var value rune - var width int - - raw_unread := len(parser.raw_buffer) - parser.raw_buffer_pos - - // Decode the next character. - switch parser.encoding { - case yaml_UTF8_ENCODING: - // Decode a UTF-8 character. Check RFC 3629 - // (http://www.ietf.org/rfc/rfc3629.txt) for more details. - // - // The following table (taken from the RFC) is used for - // decoding. - // - // Char. number range | UTF-8 octet sequence - // (hexadecimal) | (binary) - // --------------------+------------------------------------ - // 0000 0000-0000 007F | 0xxxxxxx - // 0000 0080-0000 07FF | 110xxxxx 10xxxxxx - // 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx - // 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - // - // Additionally, the characters in the range 0xD800-0xDFFF - // are prohibited as they are reserved for use with UTF-16 - // surrogate pairs. - - // Determine the length of the UTF-8 sequence. - octet := parser.raw_buffer[parser.raw_buffer_pos] - switch { - case octet&0x80 == 0x00: - width = 1 - case octet&0xE0 == 0xC0: - width = 2 - case octet&0xF0 == 0xE0: - width = 3 - case octet&0xF8 == 0xF0: - width = 4 - default: - // The leading octet is invalid. - return yaml_parser_set_reader_error(parser, - "invalid leading UTF-8 octet", - parser.offset, int(octet)) - } - - // Check if the raw buffer contains an incomplete character. - if width > raw_unread { - if parser.eof { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-8 octet sequence", - parser.offset, -1) - } - break inner - } - - // Decode the leading octet. - switch { - case octet&0x80 == 0x00: - value = rune(octet & 0x7F) - case octet&0xE0 == 0xC0: - value = rune(octet & 0x1F) - case octet&0xF0 == 0xE0: - value = rune(octet & 0x0F) - case octet&0xF8 == 0xF0: - value = rune(octet & 0x07) - default: - value = 0 - } - - // Check and decode the trailing octets. - for k := 1; k < width; k++ { - octet = parser.raw_buffer[parser.raw_buffer_pos+k] - - // Check if the octet is valid. - if (octet & 0xC0) != 0x80 { - return yaml_parser_set_reader_error(parser, - "invalid trailing UTF-8 octet", - parser.offset+k, int(octet)) - } - - // Decode the octet. - value = (value << 6) + rune(octet&0x3F) - } - - // Check the length of the sequence against the value. - switch { - case width == 1: - case width == 2 && value >= 0x80: - case width == 3 && value >= 0x800: - case width == 4 && value >= 0x10000: - default: - return yaml_parser_set_reader_error(parser, - "invalid length of a UTF-8 sequence", - parser.offset, -1) - } - - // Check the range of the value. - if value >= 0xD800 && value <= 0xDFFF || value > 0x10FFFF { - return yaml_parser_set_reader_error(parser, - "invalid Unicode character", - parser.offset, int(value)) - } - - case yaml_UTF16LE_ENCODING, yaml_UTF16BE_ENCODING: - var low, high int - if parser.encoding == yaml_UTF16LE_ENCODING { - low, high = 0, 1 - } else { - low, high = 1, 0 - } - - // The UTF-16 encoding is not as simple as one might - // naively think. Check RFC 2781 - // (http://www.ietf.org/rfc/rfc2781.txt). - // - // Normally, two subsequent bytes describe a Unicode - // character. However a special technique (called a - // surrogate pair) is used for specifying character - // values larger than 0xFFFF. - // - // A surrogate pair consists of two pseudo-characters: - // high surrogate area (0xD800-0xDBFF) - // low surrogate area (0xDC00-0xDFFF) - // - // The following formulas are used for decoding - // and encoding characters using surrogate pairs: - // - // U = U' + 0x10000 (0x01 00 00 <= U <= 0x10 FF FF) - // U' = yyyyyyyyyyxxxxxxxxxx (0 <= U' <= 0x0F FF FF) - // W1 = 110110yyyyyyyyyy - // W2 = 110111xxxxxxxxxx - // - // where U is the character value, W1 is the high surrogate - // area, W2 is the low surrogate area. - - // Check for incomplete UTF-16 character. - if raw_unread < 2 { - if parser.eof { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-16 character", - parser.offset, -1) - } - break inner - } - - // Get the character. - value = rune(parser.raw_buffer[parser.raw_buffer_pos+low]) + - (rune(parser.raw_buffer[parser.raw_buffer_pos+high]) << 8) - - // Check for unexpected low surrogate area. - if value&0xFC00 == 0xDC00 { - return yaml_parser_set_reader_error(parser, - "unexpected low surrogate area", - parser.offset, int(value)) - } - - // Check for a high surrogate area. - if value&0xFC00 == 0xD800 { - width = 4 - - // Check for incomplete surrogate pair. - if raw_unread < 4 { - if parser.eof { - return yaml_parser_set_reader_error(parser, - "incomplete UTF-16 surrogate pair", - parser.offset, -1) - } - break inner - } - - // Get the next character. - value2 := rune(parser.raw_buffer[parser.raw_buffer_pos+low+2]) + - (rune(parser.raw_buffer[parser.raw_buffer_pos+high+2]) << 8) - - // Check for a low surrogate area. - if value2&0xFC00 != 0xDC00 { - return yaml_parser_set_reader_error(parser, - "expected low surrogate area", - parser.offset+2, int(value2)) - } - - // Generate the value of the surrogate pair. - value = 0x10000 + ((value & 0x3FF) << 10) + (value2 & 0x3FF) - } else { - width = 2 - } - - default: - panic("impossible") - } - - // Check if the character is in the allowed range: - // #x9 | #xA | #xD | [#x20-#x7E] (8 bit) - // | #x85 | [#xA0-#xD7FF] | [#xE000-#xFFFD] (16 bit) - // | [#x10000-#x10FFFF] (32 bit) - switch { - case value == 0x09: - case value == 0x0A: - case value == 0x0D: - case value >= 0x20 && value <= 0x7E: - case value == 0x85: - case value >= 0xA0 && value <= 0xD7FF: - case value >= 0xE000 && value <= 0xFFFD: - case value >= 0x10000 && value <= 0x10FFFF: - default: - return yaml_parser_set_reader_error(parser, - "control characters are not allowed", - parser.offset, int(value)) - } - - // Move the raw pointers. - parser.raw_buffer_pos += width - parser.offset += width - - // Finally put the character into the buffer. - if value <= 0x7F { - // 0000 0000-0000 007F . 0xxxxxxx - parser.buffer[buffer_len+0] = byte(value) - buffer_len += 1 - } else if value <= 0x7FF { - // 0000 0080-0000 07FF . 110xxxxx 10xxxxxx - parser.buffer[buffer_len+0] = byte(0xC0 + (value >> 6)) - parser.buffer[buffer_len+1] = byte(0x80 + (value & 0x3F)) - buffer_len += 2 - } else if value <= 0xFFFF { - // 0000 0800-0000 FFFF . 1110xxxx 10xxxxxx 10xxxxxx - parser.buffer[buffer_len+0] = byte(0xE0 + (value >> 12)) - parser.buffer[buffer_len+1] = byte(0x80 + ((value >> 6) & 0x3F)) - parser.buffer[buffer_len+2] = byte(0x80 + (value & 0x3F)) - buffer_len += 3 - } else { - // 0001 0000-0010 FFFF . 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx - parser.buffer[buffer_len+0] = byte(0xF0 + (value >> 18)) - parser.buffer[buffer_len+1] = byte(0x80 + ((value >> 12) & 0x3F)) - parser.buffer[buffer_len+2] = byte(0x80 + ((value >> 6) & 0x3F)) - parser.buffer[buffer_len+3] = byte(0x80 + (value & 0x3F)) - buffer_len += 4 - } - - parser.unread++ - } - - // On EOF, put NUL into the buffer and return. - if parser.eof { - parser.buffer[buffer_len] = 0 - buffer_len++ - parser.unread++ - break - } - } - // [Go] Read the documentation of this function above. To return true, - // we need to have the given length in the buffer. Not doing that means - // every single check that calls this function to make sure the buffer - // has a given length is Go) panicking; or C) accessing invalid memory. - // This happens here due to the EOF above breaking early. - for buffer_len < length { - parser.buffer[buffer_len] = 0 - buffer_len++ - } - parser.buffer = parser.buffer[:buffer_len] - return true -} diff --git a/vendor/gopkg.in/yaml.v2/resolve.go b/vendor/gopkg.in/yaml.v2/resolve.go deleted file mode 100644 index 4120e0c..0000000 --- a/vendor/gopkg.in/yaml.v2/resolve.go +++ /dev/null @@ -1,258 +0,0 @@ -package yaml - -import ( - "encoding/base64" - "math" - "regexp" - "strconv" - "strings" - "time" -) - -type resolveMapItem struct { - value interface{} - tag string -} - -var resolveTable = make([]byte, 256) -var resolveMap = make(map[string]resolveMapItem) - -func init() { - t := resolveTable - t[int('+')] = 'S' // Sign - t[int('-')] = 'S' - for _, c := range "0123456789" { - t[int(c)] = 'D' // Digit - } - for _, c := range "yYnNtTfFoO~" { - t[int(c)] = 'M' // In map - } - t[int('.')] = '.' // Float (potentially in map) - - var resolveMapList = []struct { - v interface{} - tag string - l []string - }{ - {true, yaml_BOOL_TAG, []string{"y", "Y", "yes", "Yes", "YES"}}, - {true, yaml_BOOL_TAG, []string{"true", "True", "TRUE"}}, - {true, yaml_BOOL_TAG, []string{"on", "On", "ON"}}, - {false, yaml_BOOL_TAG, []string{"n", "N", "no", "No", "NO"}}, - {false, yaml_BOOL_TAG, []string{"false", "False", "FALSE"}}, - {false, yaml_BOOL_TAG, []string{"off", "Off", "OFF"}}, - {nil, yaml_NULL_TAG, []string{"", "~", "null", "Null", "NULL"}}, - {math.NaN(), yaml_FLOAT_TAG, []string{".nan", ".NaN", ".NAN"}}, - {math.Inf(+1), yaml_FLOAT_TAG, []string{".inf", ".Inf", ".INF"}}, - {math.Inf(+1), yaml_FLOAT_TAG, []string{"+.inf", "+.Inf", "+.INF"}}, - {math.Inf(-1), yaml_FLOAT_TAG, []string{"-.inf", "-.Inf", "-.INF"}}, - {"<<", yaml_MERGE_TAG, []string{"<<"}}, - } - - m := resolveMap - for _, item := range resolveMapList { - for _, s := range item.l { - m[s] = resolveMapItem{item.v, item.tag} - } - } -} - -const longTagPrefix = "tag:yaml.org,2002:" - -func shortTag(tag string) string { - // TODO This can easily be made faster and produce less garbage. - if strings.HasPrefix(tag, longTagPrefix) { - return "!!" + tag[len(longTagPrefix):] - } - return tag -} - -func longTag(tag string) string { - if strings.HasPrefix(tag, "!!") { - return longTagPrefix + tag[2:] - } - return tag -} - -func resolvableTag(tag string) bool { - switch tag { - case "", yaml_STR_TAG, yaml_BOOL_TAG, yaml_INT_TAG, yaml_FLOAT_TAG, yaml_NULL_TAG, yaml_TIMESTAMP_TAG: - return true - } - return false -} - -var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`) - -func resolve(tag string, in string) (rtag string, out interface{}) { - if !resolvableTag(tag) { - return tag, in - } - - defer func() { - switch tag { - case "", rtag, yaml_STR_TAG, yaml_BINARY_TAG: - return - case yaml_FLOAT_TAG: - if rtag == yaml_INT_TAG { - switch v := out.(type) { - case int64: - rtag = yaml_FLOAT_TAG - out = float64(v) - return - case int: - rtag = yaml_FLOAT_TAG - out = float64(v) - return - } - } - } - failf("cannot decode %s `%s` as a %s", shortTag(rtag), in, shortTag(tag)) - }() - - // Any data is accepted as a !!str or !!binary. - // Otherwise, the prefix is enough of a hint about what it might be. - hint := byte('N') - if in != "" { - hint = resolveTable[in[0]] - } - if hint != 0 && tag != yaml_STR_TAG && tag != yaml_BINARY_TAG { - // Handle things we can lookup in a map. - if item, ok := resolveMap[in]; ok { - return item.tag, item.value - } - - // Base 60 floats are a bad idea, were dropped in YAML 1.2, and - // are purposefully unsupported here. They're still quoted on - // the way out for compatibility with other parser, though. - - switch hint { - case 'M': - // We've already checked the map above. - - case '.': - // Not in the map, so maybe a normal float. - floatv, err := strconv.ParseFloat(in, 64) - if err == nil { - return yaml_FLOAT_TAG, floatv - } - - case 'D', 'S': - // Int, float, or timestamp. - // Only try values as a timestamp if the value is unquoted or there's an explicit - // !!timestamp tag. - if tag == "" || tag == yaml_TIMESTAMP_TAG { - t, ok := parseTimestamp(in) - if ok { - return yaml_TIMESTAMP_TAG, t - } - } - - plain := strings.Replace(in, "_", "", -1) - intv, err := strconv.ParseInt(plain, 0, 64) - if err == nil { - if intv == int64(int(intv)) { - return yaml_INT_TAG, int(intv) - } else { - return yaml_INT_TAG, intv - } - } - uintv, err := strconv.ParseUint(plain, 0, 64) - if err == nil { - return yaml_INT_TAG, uintv - } - if yamlStyleFloat.MatchString(plain) { - floatv, err := strconv.ParseFloat(plain, 64) - if err == nil { - return yaml_FLOAT_TAG, floatv - } - } - if strings.HasPrefix(plain, "0b") { - intv, err := strconv.ParseInt(plain[2:], 2, 64) - if err == nil { - if intv == int64(int(intv)) { - return yaml_INT_TAG, int(intv) - } else { - return yaml_INT_TAG, intv - } - } - uintv, err := strconv.ParseUint(plain[2:], 2, 64) - if err == nil { - return yaml_INT_TAG, uintv - } - } else if strings.HasPrefix(plain, "-0b") { - intv, err := strconv.ParseInt("-" + plain[3:], 2, 64) - if err == nil { - if true || intv == int64(int(intv)) { - return yaml_INT_TAG, int(intv) - } else { - return yaml_INT_TAG, intv - } - } - } - default: - panic("resolveTable item not yet handled: " + string(rune(hint)) + " (with " + in + ")") - } - } - return yaml_STR_TAG, in -} - -// encodeBase64 encodes s as base64 that is broken up into multiple lines -// as appropriate for the resulting length. -func encodeBase64(s string) string { - const lineLen = 70 - encLen := base64.StdEncoding.EncodedLen(len(s)) - lines := encLen/lineLen + 1 - buf := make([]byte, encLen*2+lines) - in := buf[0:encLen] - out := buf[encLen:] - base64.StdEncoding.Encode(in, []byte(s)) - k := 0 - for i := 0; i < len(in); i += lineLen { - j := i + lineLen - if j > len(in) { - j = len(in) - } - k += copy(out[k:], in[i:j]) - if lines > 1 { - out[k] = '\n' - k++ - } - } - return string(out[:k]) -} - -// This is a subset of the formats allowed by the regular expression -// defined at http://yaml.org/type/timestamp.html. -var allowedTimestampFormats = []string{ - "2006-1-2T15:4:5.999999999Z07:00", // RCF3339Nano with short date fields. - "2006-1-2t15:4:5.999999999Z07:00", // RFC3339Nano with short date fields and lower-case "t". - "2006-1-2 15:4:5.999999999", // space separated with no time zone - "2006-1-2", // date only - // Notable exception: time.Parse cannot handle: "2001-12-14 21:59:43.10 -5" - // from the set of examples. -} - -// parseTimestamp parses s as a timestamp string and -// returns the timestamp and reports whether it succeeded. -// Timestamp formats are defined at http://yaml.org/type/timestamp.html -func parseTimestamp(s string) (time.Time, bool) { - // TODO write code to check all the formats supported by - // http://yaml.org/type/timestamp.html instead of using time.Parse. - - // Quick check: all date formats start with YYYY-. - i := 0 - for ; i < len(s); i++ { - if c := s[i]; c < '0' || c > '9' { - break - } - } - if i != 4 || i == len(s) || s[i] != '-' { - return time.Time{}, false - } - for _, format := range allowedTimestampFormats { - if t, err := time.Parse(format, s); err == nil { - return t, true - } - } - return time.Time{}, false -} diff --git a/vendor/gopkg.in/yaml.v2/scannerc.go b/vendor/gopkg.in/yaml.v2/scannerc.go deleted file mode 100644 index 0b9bb60..0000000 --- a/vendor/gopkg.in/yaml.v2/scannerc.go +++ /dev/null @@ -1,2711 +0,0 @@ -package yaml - -import ( - "bytes" - "fmt" -) - -// Introduction -// ************ -// -// The following notes assume that you are familiar with the YAML specification -// (http://yaml.org/spec/1.2/spec.html). We mostly follow it, although in -// some cases we are less restrictive that it requires. -// -// The process of transforming a YAML stream into a sequence of events is -// divided on two steps: Scanning and Parsing. -// -// The Scanner transforms the input stream into a sequence of tokens, while the -// parser transform the sequence of tokens produced by the Scanner into a -// sequence of parsing events. -// -// The Scanner is rather clever and complicated. The Parser, on the contrary, -// is a straightforward implementation of a recursive-descendant parser (or, -// LL(1) parser, as it is usually called). -// -// Actually there are two issues of Scanning that might be called "clever", the -// rest is quite straightforward. The issues are "block collection start" and -// "simple keys". Both issues are explained below in details. -// -// Here the Scanning step is explained and implemented. We start with the list -// of all the tokens produced by the Scanner together with short descriptions. -// -// Now, tokens: -// -// STREAM-START(encoding) # The stream start. -// STREAM-END # The stream end. -// VERSION-DIRECTIVE(major,minor) # The '%YAML' directive. -// TAG-DIRECTIVE(handle,prefix) # The '%TAG' directive. -// DOCUMENT-START # '---' -// DOCUMENT-END # '...' -// BLOCK-SEQUENCE-START # Indentation increase denoting a block -// BLOCK-MAPPING-START # sequence or a block mapping. -// BLOCK-END # Indentation decrease. -// FLOW-SEQUENCE-START # '[' -// FLOW-SEQUENCE-END # ']' -// BLOCK-SEQUENCE-START # '{' -// BLOCK-SEQUENCE-END # '}' -// BLOCK-ENTRY # '-' -// FLOW-ENTRY # ',' -// KEY # '?' or nothing (simple keys). -// VALUE # ':' -// ALIAS(anchor) # '*anchor' -// ANCHOR(anchor) # '&anchor' -// TAG(handle,suffix) # '!handle!suffix' -// SCALAR(value,style) # A scalar. -// -// The following two tokens are "virtual" tokens denoting the beginning and the -// end of the stream: -// -// STREAM-START(encoding) -// STREAM-END -// -// We pass the information about the input stream encoding with the -// STREAM-START token. -// -// The next two tokens are responsible for tags: -// -// VERSION-DIRECTIVE(major,minor) -// TAG-DIRECTIVE(handle,prefix) -// -// Example: -// -// %YAML 1.1 -// %TAG ! !foo -// %TAG !yaml! tag:yaml.org,2002: -// --- -// -// The correspoding sequence of tokens: -// -// STREAM-START(utf-8) -// VERSION-DIRECTIVE(1,1) -// TAG-DIRECTIVE("!","!foo") -// TAG-DIRECTIVE("!yaml","tag:yaml.org,2002:") -// DOCUMENT-START -// STREAM-END -// -// Note that the VERSION-DIRECTIVE and TAG-DIRECTIVE tokens occupy a whole -// line. -// -// The document start and end indicators are represented by: -// -// DOCUMENT-START -// DOCUMENT-END -// -// Note that if a YAML stream contains an implicit document (without '---' -// and '...' indicators), no DOCUMENT-START and DOCUMENT-END tokens will be -// produced. -// -// In the following examples, we present whole documents together with the -// produced tokens. -// -// 1. An implicit document: -// -// 'a scalar' -// -// Tokens: -// -// STREAM-START(utf-8) -// SCALAR("a scalar",single-quoted) -// STREAM-END -// -// 2. An explicit document: -// -// --- -// 'a scalar' -// ... -// -// Tokens: -// -// STREAM-START(utf-8) -// DOCUMENT-START -// SCALAR("a scalar",single-quoted) -// DOCUMENT-END -// STREAM-END -// -// 3. Several documents in a stream: -// -// 'a scalar' -// --- -// 'another scalar' -// --- -// 'yet another scalar' -// -// Tokens: -// -// STREAM-START(utf-8) -// SCALAR("a scalar",single-quoted) -// DOCUMENT-START -// SCALAR("another scalar",single-quoted) -// DOCUMENT-START -// SCALAR("yet another scalar",single-quoted) -// STREAM-END -// -// We have already introduced the SCALAR token above. The following tokens are -// used to describe aliases, anchors, tag, and scalars: -// -// ALIAS(anchor) -// ANCHOR(anchor) -// TAG(handle,suffix) -// SCALAR(value,style) -// -// The following series of examples illustrate the usage of these tokens: -// -// 1. A recursive sequence: -// -// &A [ *A ] -// -// Tokens: -// -// STREAM-START(utf-8) -// ANCHOR("A") -// FLOW-SEQUENCE-START -// ALIAS("A") -// FLOW-SEQUENCE-END -// STREAM-END -// -// 2. A tagged scalar: -// -// !!float "3.14" # A good approximation. -// -// Tokens: -// -// STREAM-START(utf-8) -// TAG("!!","float") -// SCALAR("3.14",double-quoted) -// STREAM-END -// -// 3. Various scalar styles: -// -// --- # Implicit empty plain scalars do not produce tokens. -// --- a plain scalar -// --- 'a single-quoted scalar' -// --- "a double-quoted scalar" -// --- |- -// a literal scalar -// --- >- -// a folded -// scalar -// -// Tokens: -// -// STREAM-START(utf-8) -// DOCUMENT-START -// DOCUMENT-START -// SCALAR("a plain scalar",plain) -// DOCUMENT-START -// SCALAR("a single-quoted scalar",single-quoted) -// DOCUMENT-START -// SCALAR("a double-quoted scalar",double-quoted) -// DOCUMENT-START -// SCALAR("a literal scalar",literal) -// DOCUMENT-START -// SCALAR("a folded scalar",folded) -// STREAM-END -// -// Now it's time to review collection-related tokens. We will start with -// flow collections: -// -// FLOW-SEQUENCE-START -// FLOW-SEQUENCE-END -// FLOW-MAPPING-START -// FLOW-MAPPING-END -// FLOW-ENTRY -// KEY -// VALUE -// -// The tokens FLOW-SEQUENCE-START, FLOW-SEQUENCE-END, FLOW-MAPPING-START, and -// FLOW-MAPPING-END represent the indicators '[', ']', '{', and '}' -// correspondingly. FLOW-ENTRY represent the ',' indicator. Finally the -// indicators '?' and ':', which are used for denoting mapping keys and values, -// are represented by the KEY and VALUE tokens. -// -// The following examples show flow collections: -// -// 1. A flow sequence: -// -// [item 1, item 2, item 3] -// -// Tokens: -// -// STREAM-START(utf-8) -// FLOW-SEQUENCE-START -// SCALAR("item 1",plain) -// FLOW-ENTRY -// SCALAR("item 2",plain) -// FLOW-ENTRY -// SCALAR("item 3",plain) -// FLOW-SEQUENCE-END -// STREAM-END -// -// 2. A flow mapping: -// -// { -// a simple key: a value, # Note that the KEY token is produced. -// ? a complex key: another value, -// } -// -// Tokens: -// -// STREAM-START(utf-8) -// FLOW-MAPPING-START -// KEY -// SCALAR("a simple key",plain) -// VALUE -// SCALAR("a value",plain) -// FLOW-ENTRY -// KEY -// SCALAR("a complex key",plain) -// VALUE -// SCALAR("another value",plain) -// FLOW-ENTRY -// FLOW-MAPPING-END -// STREAM-END -// -// A simple key is a key which is not denoted by the '?' indicator. Note that -// the Scanner still produce the KEY token whenever it encounters a simple key. -// -// For scanning block collections, the following tokens are used (note that we -// repeat KEY and VALUE here): -// -// BLOCK-SEQUENCE-START -// BLOCK-MAPPING-START -// BLOCK-END -// BLOCK-ENTRY -// KEY -// VALUE -// -// The tokens BLOCK-SEQUENCE-START and BLOCK-MAPPING-START denote indentation -// increase that precedes a block collection (cf. the INDENT token in Python). -// The token BLOCK-END denote indentation decrease that ends a block collection -// (cf. the DEDENT token in Python). However YAML has some syntax pecularities -// that makes detections of these tokens more complex. -// -// The tokens BLOCK-ENTRY, KEY, and VALUE are used to represent the indicators -// '-', '?', and ':' correspondingly. -// -// The following examples show how the tokens BLOCK-SEQUENCE-START, -// BLOCK-MAPPING-START, and BLOCK-END are emitted by the Scanner: -// -// 1. Block sequences: -// -// - item 1 -// - item 2 -// - -// - item 3.1 -// - item 3.2 -// - -// key 1: value 1 -// key 2: value 2 -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-ENTRY -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 3.1",plain) -// BLOCK-ENTRY -// SCALAR("item 3.2",plain) -// BLOCK-END -// BLOCK-ENTRY -// BLOCK-MAPPING-START -// KEY -// SCALAR("key 1",plain) -// VALUE -// SCALAR("value 1",plain) -// KEY -// SCALAR("key 2",plain) -// VALUE -// SCALAR("value 2",plain) -// BLOCK-END -// BLOCK-END -// STREAM-END -// -// 2. Block mappings: -// -// a simple key: a value # The KEY token is produced here. -// ? a complex key -// : another value -// a mapping: -// key 1: value 1 -// key 2: value 2 -// a sequence: -// - item 1 -// - item 2 -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-MAPPING-START -// KEY -// SCALAR("a simple key",plain) -// VALUE -// SCALAR("a value",plain) -// KEY -// SCALAR("a complex key",plain) -// VALUE -// SCALAR("another value",plain) -// KEY -// SCALAR("a mapping",plain) -// BLOCK-MAPPING-START -// KEY -// SCALAR("key 1",plain) -// VALUE -// SCALAR("value 1",plain) -// KEY -// SCALAR("key 2",plain) -// VALUE -// SCALAR("value 2",plain) -// BLOCK-END -// KEY -// SCALAR("a sequence",plain) -// VALUE -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-END -// BLOCK-END -// STREAM-END -// -// YAML does not always require to start a new block collection from a new -// line. If the current line contains only '-', '?', and ':' indicators, a new -// block collection may start at the current line. The following examples -// illustrate this case: -// -// 1. Collections in a sequence: -// -// - - item 1 -// - item 2 -// - key 1: value 1 -// key 2: value 2 -// - ? complex key -// : complex value -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-END -// BLOCK-ENTRY -// BLOCK-MAPPING-START -// KEY -// SCALAR("key 1",plain) -// VALUE -// SCALAR("value 1",plain) -// KEY -// SCALAR("key 2",plain) -// VALUE -// SCALAR("value 2",plain) -// BLOCK-END -// BLOCK-ENTRY -// BLOCK-MAPPING-START -// KEY -// SCALAR("complex key") -// VALUE -// SCALAR("complex value") -// BLOCK-END -// BLOCK-END -// STREAM-END -// -// 2. Collections in a mapping: -// -// ? a sequence -// : - item 1 -// - item 2 -// ? a mapping -// : key 1: value 1 -// key 2: value 2 -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-MAPPING-START -// KEY -// SCALAR("a sequence",plain) -// VALUE -// BLOCK-SEQUENCE-START -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-END -// KEY -// SCALAR("a mapping",plain) -// VALUE -// BLOCK-MAPPING-START -// KEY -// SCALAR("key 1",plain) -// VALUE -// SCALAR("value 1",plain) -// KEY -// SCALAR("key 2",plain) -// VALUE -// SCALAR("value 2",plain) -// BLOCK-END -// BLOCK-END -// STREAM-END -// -// YAML also permits non-indented sequences if they are included into a block -// mapping. In this case, the token BLOCK-SEQUENCE-START is not produced: -// -// key: -// - item 1 # BLOCK-SEQUENCE-START is NOT produced here. -// - item 2 -// -// Tokens: -// -// STREAM-START(utf-8) -// BLOCK-MAPPING-START -// KEY -// SCALAR("key",plain) -// VALUE -// BLOCK-ENTRY -// SCALAR("item 1",plain) -// BLOCK-ENTRY -// SCALAR("item 2",plain) -// BLOCK-END -// - -// Ensure that the buffer contains the required number of characters. -// Return true on success, false on failure (reader error or memory error). -func cache(parser *yaml_parser_t, length int) bool { - // [Go] This was inlined: !cache(A, B) -> unread < B && !update(A, B) - return parser.unread >= length || yaml_parser_update_buffer(parser, length) -} - -// Advance the buffer pointer. -func skip(parser *yaml_parser_t) { - parser.mark.index++ - parser.mark.column++ - parser.unread-- - parser.buffer_pos += width(parser.buffer[parser.buffer_pos]) -} - -func skip_line(parser *yaml_parser_t) { - if is_crlf(parser.buffer, parser.buffer_pos) { - parser.mark.index += 2 - parser.mark.column = 0 - parser.mark.line++ - parser.unread -= 2 - parser.buffer_pos += 2 - } else if is_break(parser.buffer, parser.buffer_pos) { - parser.mark.index++ - parser.mark.column = 0 - parser.mark.line++ - parser.unread-- - parser.buffer_pos += width(parser.buffer[parser.buffer_pos]) - } -} - -// Copy a character to a string buffer and advance pointers. -func read(parser *yaml_parser_t, s []byte) []byte { - w := width(parser.buffer[parser.buffer_pos]) - if w == 0 { - panic("invalid character sequence") - } - if len(s) == 0 { - s = make([]byte, 0, 32) - } - if w == 1 && len(s)+w <= cap(s) { - s = s[:len(s)+1] - s[len(s)-1] = parser.buffer[parser.buffer_pos] - parser.buffer_pos++ - } else { - s = append(s, parser.buffer[parser.buffer_pos:parser.buffer_pos+w]...) - parser.buffer_pos += w - } - parser.mark.index++ - parser.mark.column++ - parser.unread-- - return s -} - -// Copy a line break character to a string buffer and advance pointers. -func read_line(parser *yaml_parser_t, s []byte) []byte { - buf := parser.buffer - pos := parser.buffer_pos - switch { - case buf[pos] == '\r' && buf[pos+1] == '\n': - // CR LF . LF - s = append(s, '\n') - parser.buffer_pos += 2 - parser.mark.index++ - parser.unread-- - case buf[pos] == '\r' || buf[pos] == '\n': - // CR|LF . LF - s = append(s, '\n') - parser.buffer_pos += 1 - case buf[pos] == '\xC2' && buf[pos+1] == '\x85': - // NEL . LF - s = append(s, '\n') - parser.buffer_pos += 2 - case buf[pos] == '\xE2' && buf[pos+1] == '\x80' && (buf[pos+2] == '\xA8' || buf[pos+2] == '\xA9'): - // LS|PS . LS|PS - s = append(s, buf[parser.buffer_pos:pos+3]...) - parser.buffer_pos += 3 - default: - return s - } - parser.mark.index++ - parser.mark.column = 0 - parser.mark.line++ - parser.unread-- - return s -} - -// Get the next token. -func yaml_parser_scan(parser *yaml_parser_t, token *yaml_token_t) bool { - // Erase the token object. - *token = yaml_token_t{} // [Go] Is this necessary? - - // No tokens after STREAM-END or error. - if parser.stream_end_produced || parser.error != yaml_NO_ERROR { - return true - } - - // Ensure that the tokens queue contains enough tokens. - if !parser.token_available { - if !yaml_parser_fetch_more_tokens(parser) { - return false - } - } - - // Fetch the next token from the queue. - *token = parser.tokens[parser.tokens_head] - parser.tokens_head++ - parser.tokens_parsed++ - parser.token_available = false - - if token.typ == yaml_STREAM_END_TOKEN { - parser.stream_end_produced = true - } - return true -} - -// Set the scanner error and return false. -func yaml_parser_set_scanner_error(parser *yaml_parser_t, context string, context_mark yaml_mark_t, problem string) bool { - parser.error = yaml_SCANNER_ERROR - parser.context = context - parser.context_mark = context_mark - parser.problem = problem - parser.problem_mark = parser.mark - return false -} - -func yaml_parser_set_scanner_tag_error(parser *yaml_parser_t, directive bool, context_mark yaml_mark_t, problem string) bool { - context := "while parsing a tag" - if directive { - context = "while parsing a %TAG directive" - } - return yaml_parser_set_scanner_error(parser, context, context_mark, problem) -} - -func trace(args ...interface{}) func() { - pargs := append([]interface{}{"+++"}, args...) - fmt.Println(pargs...) - pargs = append([]interface{}{"---"}, args...) - return func() { fmt.Println(pargs...) } -} - -// Ensure that the tokens queue contains at least one token which can be -// returned to the Parser. -func yaml_parser_fetch_more_tokens(parser *yaml_parser_t) bool { - // While we need more tokens to fetch, do it. - for { - if parser.tokens_head != len(parser.tokens) { - // If queue is non-empty, check if any potential simple key may - // occupy the head position. - head_tok_idx, ok := parser.simple_keys_by_tok[parser.tokens_parsed] - if !ok { - break - } else if valid, ok := yaml_simple_key_is_valid(parser, &parser.simple_keys[head_tok_idx]); !ok { - return false - } else if !valid { - break - } - } - // Fetch the next token. - if !yaml_parser_fetch_next_token(parser) { - return false - } - } - - parser.token_available = true - return true -} - -// The dispatcher for token fetchers. -func yaml_parser_fetch_next_token(parser *yaml_parser_t) bool { - // Ensure that the buffer is initialized. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - // Check if we just started scanning. Fetch STREAM-START then. - if !parser.stream_start_produced { - return yaml_parser_fetch_stream_start(parser) - } - - // Eat whitespaces and comments until we reach the next token. - if !yaml_parser_scan_to_next_token(parser) { - return false - } - - // Check the indentation level against the current column. - if !yaml_parser_unroll_indent(parser, parser.mark.column) { - return false - } - - // Ensure that the buffer contains at least 4 characters. 4 is the length - // of the longest indicators ('--- ' and '... '). - if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { - return false - } - - // Is it the end of the stream? - if is_z(parser.buffer, parser.buffer_pos) { - return yaml_parser_fetch_stream_end(parser) - } - - // Is it a directive? - if parser.mark.column == 0 && parser.buffer[parser.buffer_pos] == '%' { - return yaml_parser_fetch_directive(parser) - } - - buf := parser.buffer - pos := parser.buffer_pos - - // Is it the document start indicator? - if parser.mark.column == 0 && buf[pos] == '-' && buf[pos+1] == '-' && buf[pos+2] == '-' && is_blankz(buf, pos+3) { - return yaml_parser_fetch_document_indicator(parser, yaml_DOCUMENT_START_TOKEN) - } - - // Is it the document end indicator? - if parser.mark.column == 0 && buf[pos] == '.' && buf[pos+1] == '.' && buf[pos+2] == '.' && is_blankz(buf, pos+3) { - return yaml_parser_fetch_document_indicator(parser, yaml_DOCUMENT_END_TOKEN) - } - - // Is it the flow sequence start indicator? - if buf[pos] == '[' { - return yaml_parser_fetch_flow_collection_start(parser, yaml_FLOW_SEQUENCE_START_TOKEN) - } - - // Is it the flow mapping start indicator? - if parser.buffer[parser.buffer_pos] == '{' { - return yaml_parser_fetch_flow_collection_start(parser, yaml_FLOW_MAPPING_START_TOKEN) - } - - // Is it the flow sequence end indicator? - if parser.buffer[parser.buffer_pos] == ']' { - return yaml_parser_fetch_flow_collection_end(parser, - yaml_FLOW_SEQUENCE_END_TOKEN) - } - - // Is it the flow mapping end indicator? - if parser.buffer[parser.buffer_pos] == '}' { - return yaml_parser_fetch_flow_collection_end(parser, - yaml_FLOW_MAPPING_END_TOKEN) - } - - // Is it the flow entry indicator? - if parser.buffer[parser.buffer_pos] == ',' { - return yaml_parser_fetch_flow_entry(parser) - } - - // Is it the block entry indicator? - if parser.buffer[parser.buffer_pos] == '-' && is_blankz(parser.buffer, parser.buffer_pos+1) { - return yaml_parser_fetch_block_entry(parser) - } - - // Is it the key indicator? - if parser.buffer[parser.buffer_pos] == '?' && (parser.flow_level > 0 || is_blankz(parser.buffer, parser.buffer_pos+1)) { - return yaml_parser_fetch_key(parser) - } - - // Is it the value indicator? - if parser.buffer[parser.buffer_pos] == ':' && (parser.flow_level > 0 || is_blankz(parser.buffer, parser.buffer_pos+1)) { - return yaml_parser_fetch_value(parser) - } - - // Is it an alias? - if parser.buffer[parser.buffer_pos] == '*' { - return yaml_parser_fetch_anchor(parser, yaml_ALIAS_TOKEN) - } - - // Is it an anchor? - if parser.buffer[parser.buffer_pos] == '&' { - return yaml_parser_fetch_anchor(parser, yaml_ANCHOR_TOKEN) - } - - // Is it a tag? - if parser.buffer[parser.buffer_pos] == '!' { - return yaml_parser_fetch_tag(parser) - } - - // Is it a literal scalar? - if parser.buffer[parser.buffer_pos] == '|' && parser.flow_level == 0 { - return yaml_parser_fetch_block_scalar(parser, true) - } - - // Is it a folded scalar? - if parser.buffer[parser.buffer_pos] == '>' && parser.flow_level == 0 { - return yaml_parser_fetch_block_scalar(parser, false) - } - - // Is it a single-quoted scalar? - if parser.buffer[parser.buffer_pos] == '\'' { - return yaml_parser_fetch_flow_scalar(parser, true) - } - - // Is it a double-quoted scalar? - if parser.buffer[parser.buffer_pos] == '"' { - return yaml_parser_fetch_flow_scalar(parser, false) - } - - // Is it a plain scalar? - // - // A plain scalar may start with any non-blank characters except - // - // '-', '?', ':', ',', '[', ']', '{', '}', - // '#', '&', '*', '!', '|', '>', '\'', '\"', - // '%', '@', '`'. - // - // In the block context (and, for the '-' indicator, in the flow context - // too), it may also start with the characters - // - // '-', '?', ':' - // - // if it is followed by a non-space character. - // - // The last rule is more restrictive than the specification requires. - // [Go] Make this logic more reasonable. - //switch parser.buffer[parser.buffer_pos] { - //case '-', '?', ':', ',', '?', '-', ',', ':', ']', '[', '}', '{', '&', '#', '!', '*', '>', '|', '"', '\'', '@', '%', '-', '`': - //} - if !(is_blankz(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == '-' || - parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == ':' || - parser.buffer[parser.buffer_pos] == ',' || parser.buffer[parser.buffer_pos] == '[' || - parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '{' || - parser.buffer[parser.buffer_pos] == '}' || parser.buffer[parser.buffer_pos] == '#' || - parser.buffer[parser.buffer_pos] == '&' || parser.buffer[parser.buffer_pos] == '*' || - parser.buffer[parser.buffer_pos] == '!' || parser.buffer[parser.buffer_pos] == '|' || - parser.buffer[parser.buffer_pos] == '>' || parser.buffer[parser.buffer_pos] == '\'' || - parser.buffer[parser.buffer_pos] == '"' || parser.buffer[parser.buffer_pos] == '%' || - parser.buffer[parser.buffer_pos] == '@' || parser.buffer[parser.buffer_pos] == '`') || - (parser.buffer[parser.buffer_pos] == '-' && !is_blank(parser.buffer, parser.buffer_pos+1)) || - (parser.flow_level == 0 && - (parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == ':') && - !is_blankz(parser.buffer, parser.buffer_pos+1)) { - return yaml_parser_fetch_plain_scalar(parser) - } - - // If we don't determine the token type so far, it is an error. - return yaml_parser_set_scanner_error(parser, - "while scanning for the next token", parser.mark, - "found character that cannot start any token") -} - -func yaml_simple_key_is_valid(parser *yaml_parser_t, simple_key *yaml_simple_key_t) (valid, ok bool) { - if !simple_key.possible { - return false, true - } - - // The 1.2 specification says: - // - // "If the ? indicator is omitted, parsing needs to see past the - // implicit key to recognize it as such. To limit the amount of - // lookahead required, the “:” indicator must appear at most 1024 - // Unicode characters beyond the start of the key. In addition, the key - // is restricted to a single line." - // - if simple_key.mark.line < parser.mark.line || simple_key.mark.index+1024 < parser.mark.index { - // Check if the potential simple key to be removed is required. - if simple_key.required { - return false, yaml_parser_set_scanner_error(parser, - "while scanning a simple key", simple_key.mark, - "could not find expected ':'") - } - simple_key.possible = false - return false, true - } - return true, true -} - -// Check if a simple key may start at the current position and add it if -// needed. -func yaml_parser_save_simple_key(parser *yaml_parser_t) bool { - // A simple key is required at the current position if the scanner is in - // the block context and the current column coincides with the indentation - // level. - - required := parser.flow_level == 0 && parser.indent == parser.mark.column - - // - // If the current position may start a simple key, save it. - // - if parser.simple_key_allowed { - simple_key := yaml_simple_key_t{ - possible: true, - required: required, - token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head), - mark: parser.mark, - } - - if !yaml_parser_remove_simple_key(parser) { - return false - } - parser.simple_keys[len(parser.simple_keys)-1] = simple_key - parser.simple_keys_by_tok[simple_key.token_number] = len(parser.simple_keys) - 1 - } - return true -} - -// Remove a potential simple key at the current flow level. -func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool { - i := len(parser.simple_keys) - 1 - if parser.simple_keys[i].possible { - // If the key is required, it is an error. - if parser.simple_keys[i].required { - return yaml_parser_set_scanner_error(parser, - "while scanning a simple key", parser.simple_keys[i].mark, - "could not find expected ':'") - } - // Remove the key from the stack. - parser.simple_keys[i].possible = false - delete(parser.simple_keys_by_tok, parser.simple_keys[i].token_number) - } - return true -} - -// max_flow_level limits the flow_level -const max_flow_level = 10000 - -// Increase the flow level and resize the simple key list if needed. -func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { - // Reset the simple key on the next level. - parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{ - possible: false, - required: false, - token_number: parser.tokens_parsed + (len(parser.tokens) - parser.tokens_head), - mark: parser.mark, - }) - - // Increase the flow level. - parser.flow_level++ - if parser.flow_level > max_flow_level { - return yaml_parser_set_scanner_error(parser, - "while increasing flow level", parser.simple_keys[len(parser.simple_keys)-1].mark, - fmt.Sprintf("exceeded max depth of %d", max_flow_level)) - } - return true -} - -// Decrease the flow level. -func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool { - if parser.flow_level > 0 { - parser.flow_level-- - last := len(parser.simple_keys) - 1 - delete(parser.simple_keys_by_tok, parser.simple_keys[last].token_number) - parser.simple_keys = parser.simple_keys[:last] - } - return true -} - -// max_indents limits the indents stack size -const max_indents = 10000 - -// Push the current indentation level to the stack and set the new level -// the current column is greater than the indentation level. In this case, -// append or insert the specified token into the token queue. -func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml_token_type_t, mark yaml_mark_t) bool { - // In the flow context, do nothing. - if parser.flow_level > 0 { - return true - } - - if parser.indent < column { - // Push the current indentation level to the stack and set the new - // indentation level. - parser.indents = append(parser.indents, parser.indent) - parser.indent = column - if len(parser.indents) > max_indents { - return yaml_parser_set_scanner_error(parser, - "while increasing indent level", parser.simple_keys[len(parser.simple_keys)-1].mark, - fmt.Sprintf("exceeded max depth of %d", max_indents)) - } - - // Create a token and insert it into the queue. - token := yaml_token_t{ - typ: typ, - start_mark: mark, - end_mark: mark, - } - if number > -1 { - number -= parser.tokens_parsed - } - yaml_insert_token(parser, number, &token) - } - return true -} - -// Pop indentation levels from the indents stack until the current level -// becomes less or equal to the column. For each indentation level, append -// the BLOCK-END token. -func yaml_parser_unroll_indent(parser *yaml_parser_t, column int) bool { - // In the flow context, do nothing. - if parser.flow_level > 0 { - return true - } - - // Loop through the indentation levels in the stack. - for parser.indent > column { - // Create a token and append it to the queue. - token := yaml_token_t{ - typ: yaml_BLOCK_END_TOKEN, - start_mark: parser.mark, - end_mark: parser.mark, - } - yaml_insert_token(parser, -1, &token) - - // Pop the indentation level. - parser.indent = parser.indents[len(parser.indents)-1] - parser.indents = parser.indents[:len(parser.indents)-1] - } - return true -} - -// Initialize the scanner and produce the STREAM-START token. -func yaml_parser_fetch_stream_start(parser *yaml_parser_t) bool { - - // Set the initial indentation. - parser.indent = -1 - - // Initialize the simple key stack. - parser.simple_keys = append(parser.simple_keys, yaml_simple_key_t{}) - - parser.simple_keys_by_tok = make(map[int]int) - - // A simple key is allowed at the beginning of the stream. - parser.simple_key_allowed = true - - // We have started. - parser.stream_start_produced = true - - // Create the STREAM-START token and append it to the queue. - token := yaml_token_t{ - typ: yaml_STREAM_START_TOKEN, - start_mark: parser.mark, - end_mark: parser.mark, - encoding: parser.encoding, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the STREAM-END token and shut down the scanner. -func yaml_parser_fetch_stream_end(parser *yaml_parser_t) bool { - - // Force new line. - if parser.mark.column != 0 { - parser.mark.column = 0 - parser.mark.line++ - } - - // Reset the indentation level. - if !yaml_parser_unroll_indent(parser, -1) { - return false - } - - // Reset simple keys. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - parser.simple_key_allowed = false - - // Create the STREAM-END token and append it to the queue. - token := yaml_token_t{ - typ: yaml_STREAM_END_TOKEN, - start_mark: parser.mark, - end_mark: parser.mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce a VERSION-DIRECTIVE or TAG-DIRECTIVE token. -func yaml_parser_fetch_directive(parser *yaml_parser_t) bool { - // Reset the indentation level. - if !yaml_parser_unroll_indent(parser, -1) { - return false - } - - // Reset simple keys. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - parser.simple_key_allowed = false - - // Create the YAML-DIRECTIVE or TAG-DIRECTIVE token. - token := yaml_token_t{} - if !yaml_parser_scan_directive(parser, &token) { - return false - } - // Append the token to the queue. - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the DOCUMENT-START or DOCUMENT-END token. -func yaml_parser_fetch_document_indicator(parser *yaml_parser_t, typ yaml_token_type_t) bool { - // Reset the indentation level. - if !yaml_parser_unroll_indent(parser, -1) { - return false - } - - // Reset simple keys. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - parser.simple_key_allowed = false - - // Consume the token. - start_mark := parser.mark - - skip(parser) - skip(parser) - skip(parser) - - end_mark := parser.mark - - // Create the DOCUMENT-START or DOCUMENT-END token. - token := yaml_token_t{ - typ: typ, - start_mark: start_mark, - end_mark: end_mark, - } - // Append the token to the queue. - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the FLOW-SEQUENCE-START or FLOW-MAPPING-START token. -func yaml_parser_fetch_flow_collection_start(parser *yaml_parser_t, typ yaml_token_type_t) bool { - // The indicators '[' and '{' may start a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // Increase the flow level. - if !yaml_parser_increase_flow_level(parser) { - return false - } - - // A simple key may follow the indicators '[' and '{'. - parser.simple_key_allowed = true - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the FLOW-SEQUENCE-START of FLOW-MAPPING-START token. - token := yaml_token_t{ - typ: typ, - start_mark: start_mark, - end_mark: end_mark, - } - // Append the token to the queue. - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the FLOW-SEQUENCE-END or FLOW-MAPPING-END token. -func yaml_parser_fetch_flow_collection_end(parser *yaml_parser_t, typ yaml_token_type_t) bool { - // Reset any potential simple key on the current flow level. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // Decrease the flow level. - if !yaml_parser_decrease_flow_level(parser) { - return false - } - - // No simple keys after the indicators ']' and '}'. - parser.simple_key_allowed = false - - // Consume the token. - - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the FLOW-SEQUENCE-END of FLOW-MAPPING-END token. - token := yaml_token_t{ - typ: typ, - start_mark: start_mark, - end_mark: end_mark, - } - // Append the token to the queue. - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the FLOW-ENTRY token. -func yaml_parser_fetch_flow_entry(parser *yaml_parser_t) bool { - // Reset any potential simple keys on the current flow level. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // Simple keys are allowed after ','. - parser.simple_key_allowed = true - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the FLOW-ENTRY token and append it to the queue. - token := yaml_token_t{ - typ: yaml_FLOW_ENTRY_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the BLOCK-ENTRY token. -func yaml_parser_fetch_block_entry(parser *yaml_parser_t) bool { - // Check if the scanner is in the block context. - if parser.flow_level == 0 { - // Check if we are allowed to start a new entry. - if !parser.simple_key_allowed { - return yaml_parser_set_scanner_error(parser, "", parser.mark, - "block sequence entries are not allowed in this context") - } - // Add the BLOCK-SEQUENCE-START token if needed. - if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_SEQUENCE_START_TOKEN, parser.mark) { - return false - } - } else { - // It is an error for the '-' indicator to occur in the flow context, - // but we let the Parser detect and report about it because the Parser - // is able to point to the context. - } - - // Reset any potential simple keys on the current flow level. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // Simple keys are allowed after '-'. - parser.simple_key_allowed = true - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the BLOCK-ENTRY token and append it to the queue. - token := yaml_token_t{ - typ: yaml_BLOCK_ENTRY_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the KEY token. -func yaml_parser_fetch_key(parser *yaml_parser_t) bool { - - // In the block context, additional checks are required. - if parser.flow_level == 0 { - // Check if we are allowed to start a new key (not nessesary simple). - if !parser.simple_key_allowed { - return yaml_parser_set_scanner_error(parser, "", parser.mark, - "mapping keys are not allowed in this context") - } - // Add the BLOCK-MAPPING-START token if needed. - if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_MAPPING_START_TOKEN, parser.mark) { - return false - } - } - - // Reset any potential simple keys on the current flow level. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // Simple keys are allowed after '?' in the block context. - parser.simple_key_allowed = parser.flow_level == 0 - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the KEY token and append it to the queue. - token := yaml_token_t{ - typ: yaml_KEY_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the VALUE token. -func yaml_parser_fetch_value(parser *yaml_parser_t) bool { - - simple_key := &parser.simple_keys[len(parser.simple_keys)-1] - - // Have we found a simple key? - if valid, ok := yaml_simple_key_is_valid(parser, simple_key); !ok { - return false - - } else if valid { - - // Create the KEY token and insert it into the queue. - token := yaml_token_t{ - typ: yaml_KEY_TOKEN, - start_mark: simple_key.mark, - end_mark: simple_key.mark, - } - yaml_insert_token(parser, simple_key.token_number-parser.tokens_parsed, &token) - - // In the block context, we may need to add the BLOCK-MAPPING-START token. - if !yaml_parser_roll_indent(parser, simple_key.mark.column, - simple_key.token_number, - yaml_BLOCK_MAPPING_START_TOKEN, simple_key.mark) { - return false - } - - // Remove the simple key. - simple_key.possible = false - delete(parser.simple_keys_by_tok, simple_key.token_number) - - // A simple key cannot follow another simple key. - parser.simple_key_allowed = false - - } else { - // The ':' indicator follows a complex key. - - // In the block context, extra checks are required. - if parser.flow_level == 0 { - - // Check if we are allowed to start a complex value. - if !parser.simple_key_allowed { - return yaml_parser_set_scanner_error(parser, "", parser.mark, - "mapping values are not allowed in this context") - } - - // Add the BLOCK-MAPPING-START token if needed. - if !yaml_parser_roll_indent(parser, parser.mark.column, -1, yaml_BLOCK_MAPPING_START_TOKEN, parser.mark) { - return false - } - } - - // Simple keys after ':' are allowed in the block context. - parser.simple_key_allowed = parser.flow_level == 0 - } - - // Consume the token. - start_mark := parser.mark - skip(parser) - end_mark := parser.mark - - // Create the VALUE token and append it to the queue. - token := yaml_token_t{ - typ: yaml_VALUE_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the ALIAS or ANCHOR token. -func yaml_parser_fetch_anchor(parser *yaml_parser_t, typ yaml_token_type_t) bool { - // An anchor or an alias could be a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // A simple key cannot follow an anchor or an alias. - parser.simple_key_allowed = false - - // Create the ALIAS or ANCHOR token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_anchor(parser, &token, typ) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the TAG token. -func yaml_parser_fetch_tag(parser *yaml_parser_t) bool { - // A tag could be a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // A simple key cannot follow a tag. - parser.simple_key_allowed = false - - // Create the TAG token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_tag(parser, &token) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the SCALAR(...,literal) or SCALAR(...,folded) tokens. -func yaml_parser_fetch_block_scalar(parser *yaml_parser_t, literal bool) bool { - // Remove any potential simple keys. - if !yaml_parser_remove_simple_key(parser) { - return false - } - - // A simple key may follow a block scalar. - parser.simple_key_allowed = true - - // Create the SCALAR token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_block_scalar(parser, &token, literal) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the SCALAR(...,single-quoted) or SCALAR(...,double-quoted) tokens. -func yaml_parser_fetch_flow_scalar(parser *yaml_parser_t, single bool) bool { - // A plain scalar could be a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // A simple key cannot follow a flow scalar. - parser.simple_key_allowed = false - - // Create the SCALAR token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_flow_scalar(parser, &token, single) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Produce the SCALAR(...,plain) token. -func yaml_parser_fetch_plain_scalar(parser *yaml_parser_t) bool { - // A plain scalar could be a simple key. - if !yaml_parser_save_simple_key(parser) { - return false - } - - // A simple key cannot follow a flow scalar. - parser.simple_key_allowed = false - - // Create the SCALAR token and append it to the queue. - var token yaml_token_t - if !yaml_parser_scan_plain_scalar(parser, &token) { - return false - } - yaml_insert_token(parser, -1, &token) - return true -} - -// Eat whitespaces and comments until the next token is found. -func yaml_parser_scan_to_next_token(parser *yaml_parser_t) bool { - - // Until the next token is not found. - for { - // Allow the BOM mark to start a line. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if parser.mark.column == 0 && is_bom(parser.buffer, parser.buffer_pos) { - skip(parser) - } - - // Eat whitespaces. - // Tabs are allowed: - // - in the flow context - // - in the block context, but not at the beginning of the line or - // after '-', '?', or ':' (complex value). - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for parser.buffer[parser.buffer_pos] == ' ' || ((parser.flow_level > 0 || !parser.simple_key_allowed) && parser.buffer[parser.buffer_pos] == '\t') { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Eat a comment until a line break. - if parser.buffer[parser.buffer_pos] == '#' { - for !is_breakz(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - } - - // If it is a line break, eat it. - if is_break(parser.buffer, parser.buffer_pos) { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - skip_line(parser) - - // In the block context, a new line may start a simple key. - if parser.flow_level == 0 { - parser.simple_key_allowed = true - } - } else { - break // We have found a token. - } - } - - return true -} - -// Scan a YAML-DIRECTIVE or TAG-DIRECTIVE token. -// -// Scope: -// %YAML 1.1 # a comment \n -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -// %TAG !yaml! tag:yaml.org,2002: \n -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -// -func yaml_parser_scan_directive(parser *yaml_parser_t, token *yaml_token_t) bool { - // Eat '%'. - start_mark := parser.mark - skip(parser) - - // Scan the directive name. - var name []byte - if !yaml_parser_scan_directive_name(parser, start_mark, &name) { - return false - } - - // Is it a YAML directive? - if bytes.Equal(name, []byte("YAML")) { - // Scan the VERSION directive value. - var major, minor int8 - if !yaml_parser_scan_version_directive_value(parser, start_mark, &major, &minor) { - return false - } - end_mark := parser.mark - - // Create a VERSION-DIRECTIVE token. - *token = yaml_token_t{ - typ: yaml_VERSION_DIRECTIVE_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - major: major, - minor: minor, - } - - // Is it a TAG directive? - } else if bytes.Equal(name, []byte("TAG")) { - // Scan the TAG directive value. - var handle, prefix []byte - if !yaml_parser_scan_tag_directive_value(parser, start_mark, &handle, &prefix) { - return false - } - end_mark := parser.mark - - // Create a TAG-DIRECTIVE token. - *token = yaml_token_t{ - typ: yaml_TAG_DIRECTIVE_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: handle, - prefix: prefix, - } - - // Unknown directive. - } else { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "found unknown directive name") - return false - } - - // Eat the rest of the line including any comments. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - if parser.buffer[parser.buffer_pos] == '#' { - for !is_breakz(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - } - - // Check if we are at the end of the line. - if !is_breakz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "did not find expected comment or line break") - return false - } - - // Eat a line break. - if is_break(parser.buffer, parser.buffer_pos) { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - skip_line(parser) - } - - return true -} - -// Scan the directive name. -// -// Scope: -// %YAML 1.1 # a comment \n -// ^^^^ -// %TAG !yaml! tag:yaml.org,2002: \n -// ^^^ -// -func yaml_parser_scan_directive_name(parser *yaml_parser_t, start_mark yaml_mark_t, name *[]byte) bool { - // Consume the directive name. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - var s []byte - for is_alpha(parser.buffer, parser.buffer_pos) { - s = read(parser, s) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Check if the name is empty. - if len(s) == 0 { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "could not find expected directive name") - return false - } - - // Check for an blank character after the name. - if !is_blankz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "found unexpected non-alphabetical character") - return false - } - *name = s - return true -} - -// Scan the value of VERSION-DIRECTIVE. -// -// Scope: -// %YAML 1.1 # a comment \n -// ^^^^^^ -func yaml_parser_scan_version_directive_value(parser *yaml_parser_t, start_mark yaml_mark_t, major, minor *int8) bool { - // Eat whitespaces. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Consume the major version number. - if !yaml_parser_scan_version_directive_number(parser, start_mark, major) { - return false - } - - // Eat '.'. - if parser.buffer[parser.buffer_pos] != '.' { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "did not find expected digit or '.' character") - } - - skip(parser) - - // Consume the minor version number. - if !yaml_parser_scan_version_directive_number(parser, start_mark, minor) { - return false - } - return true -} - -const max_number_length = 2 - -// Scan the version number of VERSION-DIRECTIVE. -// -// Scope: -// %YAML 1.1 # a comment \n -// ^ -// %YAML 1.1 # a comment \n -// ^ -func yaml_parser_scan_version_directive_number(parser *yaml_parser_t, start_mark yaml_mark_t, number *int8) bool { - - // Repeat while the next character is digit. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - var value, length int8 - for is_digit(parser.buffer, parser.buffer_pos) { - // Check if the number is too long. - length++ - if length > max_number_length { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "found extremely long version number") - } - value = value*10 + int8(as_digit(parser.buffer, parser.buffer_pos)) - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Check if the number was present. - if length == 0 { - return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", - start_mark, "did not find expected version number") - } - *number = value - return true -} - -// Scan the value of a TAG-DIRECTIVE token. -// -// Scope: -// %TAG !yaml! tag:yaml.org,2002: \n -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -// -func yaml_parser_scan_tag_directive_value(parser *yaml_parser_t, start_mark yaml_mark_t, handle, prefix *[]byte) bool { - var handle_value, prefix_value []byte - - // Eat whitespaces. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Scan a handle. - if !yaml_parser_scan_tag_handle(parser, true, start_mark, &handle_value) { - return false - } - - // Expect a whitespace. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if !is_blank(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", - start_mark, "did not find expected whitespace") - return false - } - - // Eat whitespaces. - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Scan a prefix. - if !yaml_parser_scan_tag_uri(parser, true, nil, start_mark, &prefix_value) { - return false - } - - // Expect a whitespace or line break. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if !is_blankz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", - start_mark, "did not find expected whitespace or line break") - return false - } - - *handle = handle_value - *prefix = prefix_value - return true -} - -func yaml_parser_scan_anchor(parser *yaml_parser_t, token *yaml_token_t, typ yaml_token_type_t) bool { - var s []byte - - // Eat the indicator character. - start_mark := parser.mark - skip(parser) - - // Consume the value. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for is_alpha(parser.buffer, parser.buffer_pos) { - s = read(parser, s) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - end_mark := parser.mark - - /* - * Check if length of the anchor is greater than 0 and it is followed by - * a whitespace character or one of the indicators: - * - * '?', ':', ',', ']', '}', '%', '@', '`'. - */ - - if len(s) == 0 || - !(is_blankz(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == '?' || - parser.buffer[parser.buffer_pos] == ':' || parser.buffer[parser.buffer_pos] == ',' || - parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '}' || - parser.buffer[parser.buffer_pos] == '%' || parser.buffer[parser.buffer_pos] == '@' || - parser.buffer[parser.buffer_pos] == '`') { - context := "while scanning an alias" - if typ == yaml_ANCHOR_TOKEN { - context = "while scanning an anchor" - } - yaml_parser_set_scanner_error(parser, context, start_mark, - "did not find expected alphabetic or numeric character") - return false - } - - // Create a token. - *token = yaml_token_t{ - typ: typ, - start_mark: start_mark, - end_mark: end_mark, - value: s, - } - - return true -} - -/* - * Scan a TAG token. - */ - -func yaml_parser_scan_tag(parser *yaml_parser_t, token *yaml_token_t) bool { - var handle, suffix []byte - - start_mark := parser.mark - - // Check if the tag is in the canonical form. - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - - if parser.buffer[parser.buffer_pos+1] == '<' { - // Keep the handle as '' - - // Eat '!<' - skip(parser) - skip(parser) - - // Consume the tag value. - if !yaml_parser_scan_tag_uri(parser, false, nil, start_mark, &suffix) { - return false - } - - // Check for '>' and eat it. - if parser.buffer[parser.buffer_pos] != '>' { - yaml_parser_set_scanner_error(parser, "while scanning a tag", - start_mark, "did not find the expected '>'") - return false - } - - skip(parser) - } else { - // The tag has either the '!suffix' or the '!handle!suffix' form. - - // First, try to scan a handle. - if !yaml_parser_scan_tag_handle(parser, false, start_mark, &handle) { - return false - } - - // Check if it is, indeed, handle. - if handle[0] == '!' && len(handle) > 1 && handle[len(handle)-1] == '!' { - // Scan the suffix now. - if !yaml_parser_scan_tag_uri(parser, false, nil, start_mark, &suffix) { - return false - } - } else { - // It wasn't a handle after all. Scan the rest of the tag. - if !yaml_parser_scan_tag_uri(parser, false, handle, start_mark, &suffix) { - return false - } - - // Set the handle to '!'. - handle = []byte{'!'} - - // A special case: the '!' tag. Set the handle to '' and the - // suffix to '!'. - if len(suffix) == 0 { - handle, suffix = suffix, handle - } - } - } - - // Check the character which ends the tag. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if !is_blankz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a tag", - start_mark, "did not find expected whitespace or line break") - return false - } - - end_mark := parser.mark - - // Create a token. - *token = yaml_token_t{ - typ: yaml_TAG_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: handle, - suffix: suffix, - } - return true -} - -// Scan a tag handle. -func yaml_parser_scan_tag_handle(parser *yaml_parser_t, directive bool, start_mark yaml_mark_t, handle *[]byte) bool { - // Check the initial '!' character. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if parser.buffer[parser.buffer_pos] != '!' { - yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "did not find expected '!'") - return false - } - - var s []byte - - // Copy the '!' character. - s = read(parser, s) - - // Copy all subsequent alphabetical and numerical characters. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - for is_alpha(parser.buffer, parser.buffer_pos) { - s = read(parser, s) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Check if the trailing character is '!' and copy it. - if parser.buffer[parser.buffer_pos] == '!' { - s = read(parser, s) - } else { - // It's either the '!' tag or not really a tag handle. If it's a %TAG - // directive, it's an error. If it's a tag token, it must be a part of URI. - if directive && string(s) != "!" { - yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "did not find expected '!'") - return false - } - } - - *handle = s - return true -} - -// Scan a tag. -func yaml_parser_scan_tag_uri(parser *yaml_parser_t, directive bool, head []byte, start_mark yaml_mark_t, uri *[]byte) bool { - //size_t length = head ? strlen((char *)head) : 0 - var s []byte - hasTag := len(head) > 0 - - // Copy the head if needed. - // - // Note that we don't copy the leading '!' character. - if len(head) > 1 { - s = append(s, head[1:]...) - } - - // Scan the tag. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - // The set of characters that may appear in URI is as follows: - // - // '0'-'9', 'A'-'Z', 'a'-'z', '_', '-', ';', '/', '?', ':', '@', '&', - // '=', '+', '$', ',', '.', '!', '~', '*', '\'', '(', ')', '[', ']', - // '%'. - // [Go] Convert this into more reasonable logic. - for is_alpha(parser.buffer, parser.buffer_pos) || parser.buffer[parser.buffer_pos] == ';' || - parser.buffer[parser.buffer_pos] == '/' || parser.buffer[parser.buffer_pos] == '?' || - parser.buffer[parser.buffer_pos] == ':' || parser.buffer[parser.buffer_pos] == '@' || - parser.buffer[parser.buffer_pos] == '&' || parser.buffer[parser.buffer_pos] == '=' || - parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '$' || - parser.buffer[parser.buffer_pos] == ',' || parser.buffer[parser.buffer_pos] == '.' || - parser.buffer[parser.buffer_pos] == '!' || parser.buffer[parser.buffer_pos] == '~' || - parser.buffer[parser.buffer_pos] == '*' || parser.buffer[parser.buffer_pos] == '\'' || - parser.buffer[parser.buffer_pos] == '(' || parser.buffer[parser.buffer_pos] == ')' || - parser.buffer[parser.buffer_pos] == '[' || parser.buffer[parser.buffer_pos] == ']' || - parser.buffer[parser.buffer_pos] == '%' { - // Check if it is a URI-escape sequence. - if parser.buffer[parser.buffer_pos] == '%' { - if !yaml_parser_scan_uri_escapes(parser, directive, start_mark, &s) { - return false - } - } else { - s = read(parser, s) - } - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - hasTag = true - } - - if !hasTag { - yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "did not find expected tag URI") - return false - } - *uri = s - return true -} - -// Decode an URI-escape sequence corresponding to a single UTF-8 character. -func yaml_parser_scan_uri_escapes(parser *yaml_parser_t, directive bool, start_mark yaml_mark_t, s *[]byte) bool { - - // Decode the required number of characters. - w := 1024 - for w > 0 { - // Check for a URI-escaped octet. - if parser.unread < 3 && !yaml_parser_update_buffer(parser, 3) { - return false - } - - if !(parser.buffer[parser.buffer_pos] == '%' && - is_hex(parser.buffer, parser.buffer_pos+1) && - is_hex(parser.buffer, parser.buffer_pos+2)) { - return yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "did not find URI escaped octet") - } - - // Get the octet. - octet := byte((as_hex(parser.buffer, parser.buffer_pos+1) << 4) + as_hex(parser.buffer, parser.buffer_pos+2)) - - // If it is the leading octet, determine the length of the UTF-8 sequence. - if w == 1024 { - w = width(octet) - if w == 0 { - return yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "found an incorrect leading UTF-8 octet") - } - } else { - // Check if the trailing octet is correct. - if octet&0xC0 != 0x80 { - return yaml_parser_set_scanner_tag_error(parser, directive, - start_mark, "found an incorrect trailing UTF-8 octet") - } - } - - // Copy the octet and move the pointers. - *s = append(*s, octet) - skip(parser) - skip(parser) - skip(parser) - w-- - } - return true -} - -// Scan a block scalar. -func yaml_parser_scan_block_scalar(parser *yaml_parser_t, token *yaml_token_t, literal bool) bool { - // Eat the indicator '|' or '>'. - start_mark := parser.mark - skip(parser) - - // Scan the additional block scalar indicators. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - // Check for a chomping indicator. - var chomping, increment int - if parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '-' { - // Set the chomping method and eat the indicator. - if parser.buffer[parser.buffer_pos] == '+' { - chomping = +1 - } else { - chomping = -1 - } - skip(parser) - - // Check for an indentation indicator. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if is_digit(parser.buffer, parser.buffer_pos) { - // Check that the indentation is greater than 0. - if parser.buffer[parser.buffer_pos] == '0' { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an indentation indicator equal to 0") - return false - } - - // Get the indentation level and eat the indicator. - increment = as_digit(parser.buffer, parser.buffer_pos) - skip(parser) - } - - } else if is_digit(parser.buffer, parser.buffer_pos) { - // Do the same as above, but in the opposite order. - - if parser.buffer[parser.buffer_pos] == '0' { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an indentation indicator equal to 0") - return false - } - increment = as_digit(parser.buffer, parser.buffer_pos) - skip(parser) - - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - if parser.buffer[parser.buffer_pos] == '+' || parser.buffer[parser.buffer_pos] == '-' { - if parser.buffer[parser.buffer_pos] == '+' { - chomping = +1 - } else { - chomping = -1 - } - skip(parser) - } - } - - // Eat whitespaces and comments to the end of the line. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - for is_blank(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - if parser.buffer[parser.buffer_pos] == '#' { - for !is_breakz(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - } - - // Check if we are at the end of the line. - if !is_breakz(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "did not find expected comment or line break") - return false - } - - // Eat a line break. - if is_break(parser.buffer, parser.buffer_pos) { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - skip_line(parser) - } - - end_mark := parser.mark - - // Set the indentation level if it was specified. - var indent int - if increment > 0 { - if parser.indent >= 0 { - indent = parser.indent + increment - } else { - indent = increment - } - } - - // Scan the leading line breaks and determine the indentation level if needed. - var s, leading_break, trailing_breaks []byte - if !yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, start_mark, &end_mark) { - return false - } - - // Scan the block scalar content. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - var leading_blank, trailing_blank bool - for parser.mark.column == indent && !is_z(parser.buffer, parser.buffer_pos) { - // We are at the beginning of a non-empty line. - - // Is it a trailing whitespace? - trailing_blank = is_blank(parser.buffer, parser.buffer_pos) - - // Check if we need to fold the leading line break. - if !literal && !leading_blank && !trailing_blank && len(leading_break) > 0 && leading_break[0] == '\n' { - // Do we need to join the lines by space? - if len(trailing_breaks) == 0 { - s = append(s, ' ') - } - } else { - s = append(s, leading_break...) - } - leading_break = leading_break[:0] - - // Append the remaining line breaks. - s = append(s, trailing_breaks...) - trailing_breaks = trailing_breaks[:0] - - // Is it a leading whitespace? - leading_blank = is_blank(parser.buffer, parser.buffer_pos) - - // Consume the current line. - for !is_breakz(parser.buffer, parser.buffer_pos) { - s = read(parser, s) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Consume the line break. - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - - leading_break = read_line(parser, leading_break) - - // Eat the following indentation spaces and line breaks. - if !yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, start_mark, &end_mark) { - return false - } - } - - // Chomp the tail. - if chomping != -1 { - s = append(s, leading_break...) - } - if chomping == 1 { - s = append(s, trailing_breaks...) - } - - // Create a token. - *token = yaml_token_t{ - typ: yaml_SCALAR_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: s, - style: yaml_LITERAL_SCALAR_STYLE, - } - if !literal { - token.style = yaml_FOLDED_SCALAR_STYLE - } - return true -} - -// Scan indentation spaces and line breaks for a block scalar. Determine the -// indentation level if needed. -func yaml_parser_scan_block_scalar_breaks(parser *yaml_parser_t, indent *int, breaks *[]byte, start_mark yaml_mark_t, end_mark *yaml_mark_t) bool { - *end_mark = parser.mark - - // Eat the indentation spaces and line breaks. - max_indent := 0 - for { - // Eat the indentation spaces. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - for (*indent == 0 || parser.mark.column < *indent) && is_space(parser.buffer, parser.buffer_pos) { - skip(parser) - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - if parser.mark.column > max_indent { - max_indent = parser.mark.column - } - - // Check for a tab character messing the indentation. - if (*indent == 0 || parser.mark.column < *indent) && is_tab(parser.buffer, parser.buffer_pos) { - return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found a tab character where an indentation space is expected") - } - - // Have we found a non-empty line? - if !is_break(parser.buffer, parser.buffer_pos) { - break - } - - // Consume the line break. - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - // [Go] Should really be returning breaks instead. - *breaks = read_line(parser, *breaks) - *end_mark = parser.mark - } - - // Determine the indentation level if needed. - if *indent == 0 { - *indent = max_indent - if *indent < parser.indent+1 { - *indent = parser.indent + 1 - } - if *indent < 1 { - *indent = 1 - } - } - return true -} - -// Scan a quoted scalar. -func yaml_parser_scan_flow_scalar(parser *yaml_parser_t, token *yaml_token_t, single bool) bool { - // Eat the left quote. - start_mark := parser.mark - skip(parser) - - // Consume the content of the quoted scalar. - var s, leading_break, trailing_breaks, whitespaces []byte - for { - // Check that there are no document indicators at the beginning of the line. - if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { - return false - } - - if parser.mark.column == 0 && - ((parser.buffer[parser.buffer_pos+0] == '-' && - parser.buffer[parser.buffer_pos+1] == '-' && - parser.buffer[parser.buffer_pos+2] == '-') || - (parser.buffer[parser.buffer_pos+0] == '.' && - parser.buffer[parser.buffer_pos+1] == '.' && - parser.buffer[parser.buffer_pos+2] == '.')) && - is_blankz(parser.buffer, parser.buffer_pos+3) { - yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", - start_mark, "found unexpected document indicator") - return false - } - - // Check for EOF. - if is_z(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", - start_mark, "found unexpected end of stream") - return false - } - - // Consume non-blank characters. - leading_blanks := false - for !is_blankz(parser.buffer, parser.buffer_pos) { - if single && parser.buffer[parser.buffer_pos] == '\'' && parser.buffer[parser.buffer_pos+1] == '\'' { - // Is is an escaped single quote. - s = append(s, '\'') - skip(parser) - skip(parser) - - } else if single && parser.buffer[parser.buffer_pos] == '\'' { - // It is a right single quote. - break - } else if !single && parser.buffer[parser.buffer_pos] == '"' { - // It is a right double quote. - break - - } else if !single && parser.buffer[parser.buffer_pos] == '\\' && is_break(parser.buffer, parser.buffer_pos+1) { - // It is an escaped line break. - if parser.unread < 3 && !yaml_parser_update_buffer(parser, 3) { - return false - } - skip(parser) - skip_line(parser) - leading_blanks = true - break - - } else if !single && parser.buffer[parser.buffer_pos] == '\\' { - // It is an escape sequence. - code_length := 0 - - // Check the escape character. - switch parser.buffer[parser.buffer_pos+1] { - case '0': - s = append(s, 0) - case 'a': - s = append(s, '\x07') - case 'b': - s = append(s, '\x08') - case 't', '\t': - s = append(s, '\x09') - case 'n': - s = append(s, '\x0A') - case 'v': - s = append(s, '\x0B') - case 'f': - s = append(s, '\x0C') - case 'r': - s = append(s, '\x0D') - case 'e': - s = append(s, '\x1B') - case ' ': - s = append(s, '\x20') - case '"': - s = append(s, '"') - case '\'': - s = append(s, '\'') - case '\\': - s = append(s, '\\') - case 'N': // NEL (#x85) - s = append(s, '\xC2') - s = append(s, '\x85') - case '_': // #xA0 - s = append(s, '\xC2') - s = append(s, '\xA0') - case 'L': // LS (#x2028) - s = append(s, '\xE2') - s = append(s, '\x80') - s = append(s, '\xA8') - case 'P': // PS (#x2029) - s = append(s, '\xE2') - s = append(s, '\x80') - s = append(s, '\xA9') - case 'x': - code_length = 2 - case 'u': - code_length = 4 - case 'U': - code_length = 8 - default: - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "found unknown escape character") - return false - } - - skip(parser) - skip(parser) - - // Consume an arbitrary escape code. - if code_length > 0 { - var value int - - // Scan the character value. - if parser.unread < code_length && !yaml_parser_update_buffer(parser, code_length) { - return false - } - for k := 0; k < code_length; k++ { - if !is_hex(parser.buffer, parser.buffer_pos+k) { - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "did not find expected hexdecimal number") - return false - } - value = (value << 4) + as_hex(parser.buffer, parser.buffer_pos+k) - } - - // Check the value and write the character. - if (value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF { - yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", - start_mark, "found invalid Unicode character escape code") - return false - } - if value <= 0x7F { - s = append(s, byte(value)) - } else if value <= 0x7FF { - s = append(s, byte(0xC0+(value>>6))) - s = append(s, byte(0x80+(value&0x3F))) - } else if value <= 0xFFFF { - s = append(s, byte(0xE0+(value>>12))) - s = append(s, byte(0x80+((value>>6)&0x3F))) - s = append(s, byte(0x80+(value&0x3F))) - } else { - s = append(s, byte(0xF0+(value>>18))) - s = append(s, byte(0x80+((value>>12)&0x3F))) - s = append(s, byte(0x80+((value>>6)&0x3F))) - s = append(s, byte(0x80+(value&0x3F))) - } - - // Advance the pointer. - for k := 0; k < code_length; k++ { - skip(parser) - } - } - } else { - // It is a non-escaped non-blank character. - s = read(parser, s) - } - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - } - - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - // Check if we are at the end of the scalar. - if single { - if parser.buffer[parser.buffer_pos] == '\'' { - break - } - } else { - if parser.buffer[parser.buffer_pos] == '"' { - break - } - } - - // Consume blank characters. - for is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos) { - if is_blank(parser.buffer, parser.buffer_pos) { - // Consume a space or a tab character. - if !leading_blanks { - whitespaces = read(parser, whitespaces) - } else { - skip(parser) - } - } else { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - - // Check if it is a first line break. - if !leading_blanks { - whitespaces = whitespaces[:0] - leading_break = read_line(parser, leading_break) - leading_blanks = true - } else { - trailing_breaks = read_line(parser, trailing_breaks) - } - } - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Join the whitespaces or fold line breaks. - if leading_blanks { - // Do we need to fold line breaks? - if len(leading_break) > 0 && leading_break[0] == '\n' { - if len(trailing_breaks) == 0 { - s = append(s, ' ') - } else { - s = append(s, trailing_breaks...) - } - } else { - s = append(s, leading_break...) - s = append(s, trailing_breaks...) - } - trailing_breaks = trailing_breaks[:0] - leading_break = leading_break[:0] - } else { - s = append(s, whitespaces...) - whitespaces = whitespaces[:0] - } - } - - // Eat the right quote. - skip(parser) - end_mark := parser.mark - - // Create a token. - *token = yaml_token_t{ - typ: yaml_SCALAR_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: s, - style: yaml_SINGLE_QUOTED_SCALAR_STYLE, - } - if !single { - token.style = yaml_DOUBLE_QUOTED_SCALAR_STYLE - } - return true -} - -// Scan a plain scalar. -func yaml_parser_scan_plain_scalar(parser *yaml_parser_t, token *yaml_token_t) bool { - - var s, leading_break, trailing_breaks, whitespaces []byte - var leading_blanks bool - var indent = parser.indent + 1 - - start_mark := parser.mark - end_mark := parser.mark - - // Consume the content of the plain scalar. - for { - // Check for a document indicator. - if parser.unread < 4 && !yaml_parser_update_buffer(parser, 4) { - return false - } - if parser.mark.column == 0 && - ((parser.buffer[parser.buffer_pos+0] == '-' && - parser.buffer[parser.buffer_pos+1] == '-' && - parser.buffer[parser.buffer_pos+2] == '-') || - (parser.buffer[parser.buffer_pos+0] == '.' && - parser.buffer[parser.buffer_pos+1] == '.' && - parser.buffer[parser.buffer_pos+2] == '.')) && - is_blankz(parser.buffer, parser.buffer_pos+3) { - break - } - - // Check for a comment. - if parser.buffer[parser.buffer_pos] == '#' { - break - } - - // Consume non-blank characters. - for !is_blankz(parser.buffer, parser.buffer_pos) { - - // Check for indicators that may end a plain scalar. - if (parser.buffer[parser.buffer_pos] == ':' && is_blankz(parser.buffer, parser.buffer_pos+1)) || - (parser.flow_level > 0 && - (parser.buffer[parser.buffer_pos] == ',' || - parser.buffer[parser.buffer_pos] == '?' || parser.buffer[parser.buffer_pos] == '[' || - parser.buffer[parser.buffer_pos] == ']' || parser.buffer[parser.buffer_pos] == '{' || - parser.buffer[parser.buffer_pos] == '}')) { - break - } - - // Check if we need to join whitespaces and breaks. - if leading_blanks || len(whitespaces) > 0 { - if leading_blanks { - // Do we need to fold line breaks? - if leading_break[0] == '\n' { - if len(trailing_breaks) == 0 { - s = append(s, ' ') - } else { - s = append(s, trailing_breaks...) - } - } else { - s = append(s, leading_break...) - s = append(s, trailing_breaks...) - } - trailing_breaks = trailing_breaks[:0] - leading_break = leading_break[:0] - leading_blanks = false - } else { - s = append(s, whitespaces...) - whitespaces = whitespaces[:0] - } - } - - // Copy the character. - s = read(parser, s) - - end_mark = parser.mark - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - } - - // Is it the end? - if !(is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos)) { - break - } - - // Consume blank characters. - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - - for is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos) { - if is_blank(parser.buffer, parser.buffer_pos) { - - // Check for tab characters that abuse indentation. - if leading_blanks && parser.mark.column < indent && is_tab(parser.buffer, parser.buffer_pos) { - yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", - start_mark, "found a tab character that violates indentation") - return false - } - - // Consume a space or a tab character. - if !leading_blanks { - whitespaces = read(parser, whitespaces) - } else { - skip(parser) - } - } else { - if parser.unread < 2 && !yaml_parser_update_buffer(parser, 2) { - return false - } - - // Check if it is a first line break. - if !leading_blanks { - whitespaces = whitespaces[:0] - leading_break = read_line(parser, leading_break) - leading_blanks = true - } else { - trailing_breaks = read_line(parser, trailing_breaks) - } - } - if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) { - return false - } - } - - // Check indentation level. - if parser.flow_level == 0 && parser.mark.column < indent { - break - } - } - - // Create a token. - *token = yaml_token_t{ - typ: yaml_SCALAR_TOKEN, - start_mark: start_mark, - end_mark: end_mark, - value: s, - style: yaml_PLAIN_SCALAR_STYLE, - } - - // Note that we change the 'simple_key_allowed' flag. - if leading_blanks { - parser.simple_key_allowed = true - } - return true -} diff --git a/vendor/gopkg.in/yaml.v2/sorter.go b/vendor/gopkg.in/yaml.v2/sorter.go deleted file mode 100644 index 4c45e66..0000000 --- a/vendor/gopkg.in/yaml.v2/sorter.go +++ /dev/null @@ -1,113 +0,0 @@ -package yaml - -import ( - "reflect" - "unicode" -) - -type keyList []reflect.Value - -func (l keyList) Len() int { return len(l) } -func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } -func (l keyList) Less(i, j int) bool { - a := l[i] - b := l[j] - ak := a.Kind() - bk := b.Kind() - for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { - a = a.Elem() - ak = a.Kind() - } - for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { - b = b.Elem() - bk = b.Kind() - } - af, aok := keyFloat(a) - bf, bok := keyFloat(b) - if aok && bok { - if af != bf { - return af < bf - } - if ak != bk { - return ak < bk - } - return numLess(a, b) - } - if ak != reflect.String || bk != reflect.String { - return ak < bk - } - ar, br := []rune(a.String()), []rune(b.String()) - for i := 0; i < len(ar) && i < len(br); i++ { - if ar[i] == br[i] { - continue - } - al := unicode.IsLetter(ar[i]) - bl := unicode.IsLetter(br[i]) - if al && bl { - return ar[i] < br[i] - } - if al || bl { - return bl - } - var ai, bi int - var an, bn int64 - if ar[i] == '0' || br[i] == '0' { - for j := i-1; j >= 0 && unicode.IsDigit(ar[j]); j-- { - if ar[j] != '0' { - an = 1 - bn = 1 - break - } - } - } - for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { - an = an*10 + int64(ar[ai]-'0') - } - for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { - bn = bn*10 + int64(br[bi]-'0') - } - if an != bn { - return an < bn - } - if ai != bi { - return ai < bi - } - return ar[i] < br[i] - } - return len(ar) < len(br) -} - -// keyFloat returns a float value for v if it is a number/bool -// and whether it is a number/bool or not. -func keyFloat(v reflect.Value) (f float64, ok bool) { - switch v.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return float64(v.Int()), true - case reflect.Float32, reflect.Float64: - return v.Float(), true - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return float64(v.Uint()), true - case reflect.Bool: - if v.Bool() { - return 1, true - } - return 0, true - } - return 0, false -} - -// numLess returns whether a < b. -// a and b must necessarily have the same kind. -func numLess(a, b reflect.Value) bool { - switch a.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return a.Int() < b.Int() - case reflect.Float32, reflect.Float64: - return a.Float() < b.Float() - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return a.Uint() < b.Uint() - case reflect.Bool: - return !a.Bool() && b.Bool() - } - panic("not a number") -} diff --git a/vendor/gopkg.in/yaml.v2/writerc.go b/vendor/gopkg.in/yaml.v2/writerc.go deleted file mode 100644 index a2dde60..0000000 --- a/vendor/gopkg.in/yaml.v2/writerc.go +++ /dev/null @@ -1,26 +0,0 @@ -package yaml - -// Set the writer error and return false. -func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { - emitter.error = yaml_WRITER_ERROR - emitter.problem = problem - return false -} - -// Flush the output buffer. -func yaml_emitter_flush(emitter *yaml_emitter_t) bool { - if emitter.write_handler == nil { - panic("write handler not set") - } - - // Check if the buffer is empty. - if emitter.buffer_pos == 0 { - return true - } - - if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { - return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) - } - emitter.buffer_pos = 0 - return true -} diff --git a/vendor/gopkg.in/yaml.v2/yaml.go b/vendor/gopkg.in/yaml.v2/yaml.go deleted file mode 100644 index 3081388..0000000 --- a/vendor/gopkg.in/yaml.v2/yaml.go +++ /dev/null @@ -1,478 +0,0 @@ -// Package yaml implements YAML support for the Go language. -// -// Source code and other details for the project are available at GitHub: -// -// https://github.com/go-yaml/yaml -// -package yaml - -import ( - "errors" - "fmt" - "io" - "reflect" - "strings" - "sync" -) - -// MapSlice encodes and decodes as a YAML map. -// The order of keys is preserved when encoding and decoding. -type MapSlice []MapItem - -// MapItem is an item in a MapSlice. -type MapItem struct { - Key, Value interface{} -} - -// The Unmarshaler interface may be implemented by types to customize their -// behavior when being unmarshaled from a YAML document. The UnmarshalYAML -// method receives a function that may be called to unmarshal the original -// YAML value into a field or variable. It is safe to call the unmarshal -// function parameter more than once if necessary. -type Unmarshaler interface { - UnmarshalYAML(unmarshal func(interface{}) error) error -} - -// The Marshaler interface may be implemented by types to customize their -// behavior when being marshaled into a YAML document. The returned value -// is marshaled in place of the original value implementing Marshaler. -// -// If an error is returned by MarshalYAML, the marshaling procedure stops -// and returns with the provided error. -type Marshaler interface { - MarshalYAML() (interface{}, error) -} - -// Unmarshal decodes the first document found within the in byte slice -// and assigns decoded values into the out value. -// -// Maps and pointers (to a struct, string, int, etc) are accepted as out -// values. If an internal pointer within a struct is not initialized, -// the yaml package will initialize it if necessary for unmarshalling -// the provided data. The out parameter must not be nil. -// -// The type of the decoded values should be compatible with the respective -// values in out. If one or more values cannot be decoded due to a type -// mismatches, decoding continues partially until the end of the YAML -// content, and a *yaml.TypeError is returned with details for all -// missed values. -// -// Struct fields are only unmarshalled if they are exported (have an -// upper case first letter), and are unmarshalled using the field name -// lowercased as the default key. Custom keys may be defined via the -// "yaml" name in the field tag: the content preceding the first comma -// is used as the key, and the following comma-separated options are -// used to tweak the marshalling process (see Marshal). -// Conflicting names result in a runtime error. -// -// For example: -// -// type T struct { -// F int `yaml:"a,omitempty"` -// B int -// } -// var t T -// yaml.Unmarshal([]byte("a: 1\nb: 2"), &t) -// -// See the documentation of Marshal for the format of tags and a list of -// supported tag options. -// -func Unmarshal(in []byte, out interface{}) (err error) { - return unmarshal(in, out, false) -} - -// UnmarshalStrict is like Unmarshal except that any fields that are found -// in the data that do not have corresponding struct members, or mapping -// keys that are duplicates, will result in -// an error. -func UnmarshalStrict(in []byte, out interface{}) (err error) { - return unmarshal(in, out, true) -} - -// A Decoder reads and decodes YAML values from an input stream. -type Decoder struct { - strict bool - parser *parser -} - -// NewDecoder returns a new decoder that reads from r. -// -// The decoder introduces its own buffering and may read -// data from r beyond the YAML values requested. -func NewDecoder(r io.Reader) *Decoder { - return &Decoder{ - parser: newParserFromReader(r), - } -} - -// SetStrict sets whether strict decoding behaviour is enabled when -// decoding items in the data (see UnmarshalStrict). By default, decoding is not strict. -func (dec *Decoder) SetStrict(strict bool) { - dec.strict = strict -} - -// Decode reads the next YAML-encoded value from its input -// and stores it in the value pointed to by v. -// -// See the documentation for Unmarshal for details about the -// conversion of YAML into a Go value. -func (dec *Decoder) Decode(v interface{}) (err error) { - d := newDecoder(dec.strict) - defer handleErr(&err) - node := dec.parser.parse() - if node == nil { - return io.EOF - } - out := reflect.ValueOf(v) - if out.Kind() == reflect.Ptr && !out.IsNil() { - out = out.Elem() - } - d.unmarshal(node, out) - if len(d.terrors) > 0 { - return &TypeError{d.terrors} - } - return nil -} - -func unmarshal(in []byte, out interface{}, strict bool) (err error) { - defer handleErr(&err) - d := newDecoder(strict) - p := newParser(in) - defer p.destroy() - node := p.parse() - if node != nil { - v := reflect.ValueOf(out) - if v.Kind() == reflect.Ptr && !v.IsNil() { - v = v.Elem() - } - d.unmarshal(node, v) - } - if len(d.terrors) > 0 { - return &TypeError{d.terrors} - } - return nil -} - -// Marshal serializes the value provided into a YAML document. The structure -// of the generated document will reflect the structure of the value itself. -// Maps and pointers (to struct, string, int, etc) are accepted as the in value. -// -// Struct fields are only marshalled if they are exported (have an upper case -// first letter), and are marshalled using the field name lowercased as the -// default key. Custom keys may be defined via the "yaml" name in the field -// tag: the content preceding the first comma is used as the key, and the -// following comma-separated options are used to tweak the marshalling process. -// Conflicting names result in a runtime error. -// -// The field tag format accepted is: -// -// `(...) yaml:"[][,[,]]" (...)` -// -// The following flags are currently supported: -// -// omitempty Only include the field if it's not set to the zero -// value for the type or to empty slices or maps. -// Zero valued structs will be omitted if all their public -// fields are zero, unless they implement an IsZero -// method (see the IsZeroer interface type), in which -// case the field will be excluded if IsZero returns true. -// -// flow Marshal using a flow style (useful for structs, -// sequences and maps). -// -// inline Inline the field, which must be a struct or a map, -// causing all of its fields or keys to be processed as if -// they were part of the outer struct. For maps, keys must -// not conflict with the yaml keys of other struct fields. -// -// In addition, if the key is "-", the field is ignored. -// -// For example: -// -// type T struct { -// F int `yaml:"a,omitempty"` -// B int -// } -// yaml.Marshal(&T{B: 2}) // Returns "b: 2\n" -// yaml.Marshal(&T{F: 1}} // Returns "a: 1\nb: 0\n" -// -func Marshal(in interface{}) (out []byte, err error) { - defer handleErr(&err) - e := newEncoder() - defer e.destroy() - e.marshalDoc("", reflect.ValueOf(in)) - e.finish() - out = e.out - return -} - -// An Encoder writes YAML values to an output stream. -type Encoder struct { - encoder *encoder -} - -// NewEncoder returns a new encoder that writes to w. -// The Encoder should be closed after use to flush all data -// to w. -func NewEncoder(w io.Writer) *Encoder { - return &Encoder{ - encoder: newEncoderWithWriter(w), - } -} - -// Encode writes the YAML encoding of v to the stream. -// If multiple items are encoded to the stream, the -// second and subsequent document will be preceded -// with a "---" document separator, but the first will not. -// -// See the documentation for Marshal for details about the conversion of Go -// values to YAML. -func (e *Encoder) Encode(v interface{}) (err error) { - defer handleErr(&err) - e.encoder.marshalDoc("", reflect.ValueOf(v)) - return nil -} - -// Close closes the encoder by writing any remaining data. -// It does not write a stream terminating string "...". -func (e *Encoder) Close() (err error) { - defer handleErr(&err) - e.encoder.finish() - return nil -} - -func handleErr(err *error) { - if v := recover(); v != nil { - if e, ok := v.(yamlError); ok { - *err = e.err - } else { - panic(v) - } - } -} - -type yamlError struct { - err error -} - -func fail(err error) { - panic(yamlError{err}) -} - -func failf(format string, args ...interface{}) { - panic(yamlError{fmt.Errorf("yaml: "+format, args...)}) -} - -// A TypeError is returned by Unmarshal when one or more fields in -// the YAML document cannot be properly decoded into the requested -// types. When this error is returned, the value is still -// unmarshaled partially. -type TypeError struct { - Errors []string -} - -func (e *TypeError) Error() string { - return fmt.Sprintf("yaml: unmarshal errors:\n %s", strings.Join(e.Errors, "\n ")) -} - -// -------------------------------------------------------------------------- -// Maintain a mapping of keys to structure field indexes - -// The code in this section was copied from mgo/bson. - -// structInfo holds details for the serialization of fields of -// a given struct. -type structInfo struct { - FieldsMap map[string]fieldInfo - FieldsList []fieldInfo - - // InlineMap is the number of the field in the struct that - // contains an ,inline map, or -1 if there's none. - InlineMap int -} - -type fieldInfo struct { - Key string - Num int - OmitEmpty bool - Flow bool - // Id holds the unique field identifier, so we can cheaply - // check for field duplicates without maintaining an extra map. - Id int - - // Inline holds the field index if the field is part of an inlined struct. - Inline []int -} - -var structMap = make(map[reflect.Type]*structInfo) -var fieldMapMutex sync.RWMutex - -func getStructInfo(st reflect.Type) (*structInfo, error) { - fieldMapMutex.RLock() - sinfo, found := structMap[st] - fieldMapMutex.RUnlock() - if found { - return sinfo, nil - } - - n := st.NumField() - fieldsMap := make(map[string]fieldInfo) - fieldsList := make([]fieldInfo, 0, n) - inlineMap := -1 - for i := 0; i != n; i++ { - field := st.Field(i) - if field.PkgPath != "" && !field.Anonymous { - continue // Private field - } - - info := fieldInfo{Num: i} - - tag := field.Tag.Get("yaml") - if tag == "" && strings.Index(string(field.Tag), ":") < 0 { - tag = string(field.Tag) - } - if tag == "-" { - continue - } - - inline := false - fields := strings.Split(tag, ",") - if len(fields) > 1 { - for _, flag := range fields[1:] { - switch flag { - case "omitempty": - info.OmitEmpty = true - case "flow": - info.Flow = true - case "inline": - inline = true - default: - return nil, errors.New(fmt.Sprintf("Unsupported flag %q in tag %q of type %s", flag, tag, st)) - } - } - tag = fields[0] - } - - if inline { - switch field.Type.Kind() { - case reflect.Map: - if inlineMap >= 0 { - return nil, errors.New("Multiple ,inline maps in struct " + st.String()) - } - if field.Type.Key() != reflect.TypeOf("") { - return nil, errors.New("Option ,inline needs a map with string keys in struct " + st.String()) - } - inlineMap = info.Num - case reflect.Struct: - sinfo, err := getStructInfo(field.Type) - if err != nil { - return nil, err - } - for _, finfo := range sinfo.FieldsList { - if _, found := fieldsMap[finfo.Key]; found { - msg := "Duplicated key '" + finfo.Key + "' in struct " + st.String() - return nil, errors.New(msg) - } - if finfo.Inline == nil { - finfo.Inline = []int{i, finfo.Num} - } else { - finfo.Inline = append([]int{i}, finfo.Inline...) - } - finfo.Id = len(fieldsList) - fieldsMap[finfo.Key] = finfo - fieldsList = append(fieldsList, finfo) - } - default: - //return nil, errors.New("Option ,inline needs a struct value or map field") - return nil, errors.New("Option ,inline needs a struct value field") - } - continue - } - - if tag != "" { - info.Key = tag - } else { - info.Key = strings.ToLower(field.Name) - } - - if _, found = fieldsMap[info.Key]; found { - msg := "Duplicated key '" + info.Key + "' in struct " + st.String() - return nil, errors.New(msg) - } - - info.Id = len(fieldsList) - fieldsList = append(fieldsList, info) - fieldsMap[info.Key] = info - } - - sinfo = &structInfo{ - FieldsMap: fieldsMap, - FieldsList: fieldsList, - InlineMap: inlineMap, - } - - fieldMapMutex.Lock() - structMap[st] = sinfo - fieldMapMutex.Unlock() - return sinfo, nil -} - -// IsZeroer is used to check whether an object is zero to -// determine whether it should be omitted when marshaling -// with the omitempty flag. One notable implementation -// is time.Time. -type IsZeroer interface { - IsZero() bool -} - -func isZero(v reflect.Value) bool { - kind := v.Kind() - if z, ok := v.Interface().(IsZeroer); ok { - if (kind == reflect.Ptr || kind == reflect.Interface) && v.IsNil() { - return true - } - return z.IsZero() - } - switch kind { - case reflect.String: - return len(v.String()) == 0 - case reflect.Interface, reflect.Ptr: - return v.IsNil() - case reflect.Slice: - return v.Len() == 0 - case reflect.Map: - return v.Len() == 0 - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return v.Int() == 0 - case reflect.Float32, reflect.Float64: - return v.Float() == 0 - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return v.Uint() == 0 - case reflect.Bool: - return !v.Bool() - case reflect.Struct: - vt := v.Type() - for i := v.NumField() - 1; i >= 0; i-- { - if vt.Field(i).PkgPath != "" { - continue // Private field - } - if !isZero(v.Field(i)) { - return false - } - } - return true - } - return false -} - -// FutureLineWrap globally disables line wrapping when encoding long strings. -// This is a temporary and thus deprecated method introduced to faciliate -// migration towards v3, which offers more control of line lengths on -// individual encodings, and has a default matching the behavior introduced -// by this function. -// -// The default formatting of v2 was erroneously changed in v2.3.0 and reverted -// in v2.4.0, at which point this function was introduced to help migration. -func FutureLineWrap() { - disableLineWrapping = true -} diff --git a/vendor/gopkg.in/yaml.v2/yamlh.go b/vendor/gopkg.in/yaml.v2/yamlh.go deleted file mode 100644 index f6a9c8e..0000000 --- a/vendor/gopkg.in/yaml.v2/yamlh.go +++ /dev/null @@ -1,739 +0,0 @@ -package yaml - -import ( - "fmt" - "io" -) - -// The version directive data. -type yaml_version_directive_t struct { - major int8 // The major version number. - minor int8 // The minor version number. -} - -// The tag directive data. -type yaml_tag_directive_t struct { - handle []byte // The tag handle. - prefix []byte // The tag prefix. -} - -type yaml_encoding_t int - -// The stream encoding. -const ( - // Let the parser choose the encoding. - yaml_ANY_ENCODING yaml_encoding_t = iota - - yaml_UTF8_ENCODING // The default UTF-8 encoding. - yaml_UTF16LE_ENCODING // The UTF-16-LE encoding with BOM. - yaml_UTF16BE_ENCODING // The UTF-16-BE encoding with BOM. -) - -type yaml_break_t int - -// Line break types. -const ( - // Let the parser choose the break type. - yaml_ANY_BREAK yaml_break_t = iota - - yaml_CR_BREAK // Use CR for line breaks (Mac style). - yaml_LN_BREAK // Use LN for line breaks (Unix style). - yaml_CRLN_BREAK // Use CR LN for line breaks (DOS style). -) - -type yaml_error_type_t int - -// Many bad things could happen with the parser and emitter. -const ( - // No error is produced. - yaml_NO_ERROR yaml_error_type_t = iota - - yaml_MEMORY_ERROR // Cannot allocate or reallocate a block of memory. - yaml_READER_ERROR // Cannot read or decode the input stream. - yaml_SCANNER_ERROR // Cannot scan the input stream. - yaml_PARSER_ERROR // Cannot parse the input stream. - yaml_COMPOSER_ERROR // Cannot compose a YAML document. - yaml_WRITER_ERROR // Cannot write to the output stream. - yaml_EMITTER_ERROR // Cannot emit a YAML stream. -) - -// The pointer position. -type yaml_mark_t struct { - index int // The position index. - line int // The position line. - column int // The position column. -} - -// Node Styles - -type yaml_style_t int8 - -type yaml_scalar_style_t yaml_style_t - -// Scalar styles. -const ( - // Let the emitter choose the style. - yaml_ANY_SCALAR_STYLE yaml_scalar_style_t = iota - - yaml_PLAIN_SCALAR_STYLE // The plain scalar style. - yaml_SINGLE_QUOTED_SCALAR_STYLE // The single-quoted scalar style. - yaml_DOUBLE_QUOTED_SCALAR_STYLE // The double-quoted scalar style. - yaml_LITERAL_SCALAR_STYLE // The literal scalar style. - yaml_FOLDED_SCALAR_STYLE // The folded scalar style. -) - -type yaml_sequence_style_t yaml_style_t - -// Sequence styles. -const ( - // Let the emitter choose the style. - yaml_ANY_SEQUENCE_STYLE yaml_sequence_style_t = iota - - yaml_BLOCK_SEQUENCE_STYLE // The block sequence style. - yaml_FLOW_SEQUENCE_STYLE // The flow sequence style. -) - -type yaml_mapping_style_t yaml_style_t - -// Mapping styles. -const ( - // Let the emitter choose the style. - yaml_ANY_MAPPING_STYLE yaml_mapping_style_t = iota - - yaml_BLOCK_MAPPING_STYLE // The block mapping style. - yaml_FLOW_MAPPING_STYLE // The flow mapping style. -) - -// Tokens - -type yaml_token_type_t int - -// Token types. -const ( - // An empty token. - yaml_NO_TOKEN yaml_token_type_t = iota - - yaml_STREAM_START_TOKEN // A STREAM-START token. - yaml_STREAM_END_TOKEN // A STREAM-END token. - - yaml_VERSION_DIRECTIVE_TOKEN // A VERSION-DIRECTIVE token. - yaml_TAG_DIRECTIVE_TOKEN // A TAG-DIRECTIVE token. - yaml_DOCUMENT_START_TOKEN // A DOCUMENT-START token. - yaml_DOCUMENT_END_TOKEN // A DOCUMENT-END token. - - yaml_BLOCK_SEQUENCE_START_TOKEN // A BLOCK-SEQUENCE-START token. - yaml_BLOCK_MAPPING_START_TOKEN // A BLOCK-SEQUENCE-END token. - yaml_BLOCK_END_TOKEN // A BLOCK-END token. - - yaml_FLOW_SEQUENCE_START_TOKEN // A FLOW-SEQUENCE-START token. - yaml_FLOW_SEQUENCE_END_TOKEN // A FLOW-SEQUENCE-END token. - yaml_FLOW_MAPPING_START_TOKEN // A FLOW-MAPPING-START token. - yaml_FLOW_MAPPING_END_TOKEN // A FLOW-MAPPING-END token. - - yaml_BLOCK_ENTRY_TOKEN // A BLOCK-ENTRY token. - yaml_FLOW_ENTRY_TOKEN // A FLOW-ENTRY token. - yaml_KEY_TOKEN // A KEY token. - yaml_VALUE_TOKEN // A VALUE token. - - yaml_ALIAS_TOKEN // An ALIAS token. - yaml_ANCHOR_TOKEN // An ANCHOR token. - yaml_TAG_TOKEN // A TAG token. - yaml_SCALAR_TOKEN // A SCALAR token. -) - -func (tt yaml_token_type_t) String() string { - switch tt { - case yaml_NO_TOKEN: - return "yaml_NO_TOKEN" - case yaml_STREAM_START_TOKEN: - return "yaml_STREAM_START_TOKEN" - case yaml_STREAM_END_TOKEN: - return "yaml_STREAM_END_TOKEN" - case yaml_VERSION_DIRECTIVE_TOKEN: - return "yaml_VERSION_DIRECTIVE_TOKEN" - case yaml_TAG_DIRECTIVE_TOKEN: - return "yaml_TAG_DIRECTIVE_TOKEN" - case yaml_DOCUMENT_START_TOKEN: - return "yaml_DOCUMENT_START_TOKEN" - case yaml_DOCUMENT_END_TOKEN: - return "yaml_DOCUMENT_END_TOKEN" - case yaml_BLOCK_SEQUENCE_START_TOKEN: - return "yaml_BLOCK_SEQUENCE_START_TOKEN" - case yaml_BLOCK_MAPPING_START_TOKEN: - return "yaml_BLOCK_MAPPING_START_TOKEN" - case yaml_BLOCK_END_TOKEN: - return "yaml_BLOCK_END_TOKEN" - case yaml_FLOW_SEQUENCE_START_TOKEN: - return "yaml_FLOW_SEQUENCE_START_TOKEN" - case yaml_FLOW_SEQUENCE_END_TOKEN: - return "yaml_FLOW_SEQUENCE_END_TOKEN" - case yaml_FLOW_MAPPING_START_TOKEN: - return "yaml_FLOW_MAPPING_START_TOKEN" - case yaml_FLOW_MAPPING_END_TOKEN: - return "yaml_FLOW_MAPPING_END_TOKEN" - case yaml_BLOCK_ENTRY_TOKEN: - return "yaml_BLOCK_ENTRY_TOKEN" - case yaml_FLOW_ENTRY_TOKEN: - return "yaml_FLOW_ENTRY_TOKEN" - case yaml_KEY_TOKEN: - return "yaml_KEY_TOKEN" - case yaml_VALUE_TOKEN: - return "yaml_VALUE_TOKEN" - case yaml_ALIAS_TOKEN: - return "yaml_ALIAS_TOKEN" - case yaml_ANCHOR_TOKEN: - return "yaml_ANCHOR_TOKEN" - case yaml_TAG_TOKEN: - return "yaml_TAG_TOKEN" - case yaml_SCALAR_TOKEN: - return "yaml_SCALAR_TOKEN" - } - return "" -} - -// The token structure. -type yaml_token_t struct { - // The token type. - typ yaml_token_type_t - - // The start/end of the token. - start_mark, end_mark yaml_mark_t - - // The stream encoding (for yaml_STREAM_START_TOKEN). - encoding yaml_encoding_t - - // The alias/anchor/scalar value or tag/tag directive handle - // (for yaml_ALIAS_TOKEN, yaml_ANCHOR_TOKEN, yaml_SCALAR_TOKEN, yaml_TAG_TOKEN, yaml_TAG_DIRECTIVE_TOKEN). - value []byte - - // The tag suffix (for yaml_TAG_TOKEN). - suffix []byte - - // The tag directive prefix (for yaml_TAG_DIRECTIVE_TOKEN). - prefix []byte - - // The scalar style (for yaml_SCALAR_TOKEN). - style yaml_scalar_style_t - - // The version directive major/minor (for yaml_VERSION_DIRECTIVE_TOKEN). - major, minor int8 -} - -// Events - -type yaml_event_type_t int8 - -// Event types. -const ( - // An empty event. - yaml_NO_EVENT yaml_event_type_t = iota - - yaml_STREAM_START_EVENT // A STREAM-START event. - yaml_STREAM_END_EVENT // A STREAM-END event. - yaml_DOCUMENT_START_EVENT // A DOCUMENT-START event. - yaml_DOCUMENT_END_EVENT // A DOCUMENT-END event. - yaml_ALIAS_EVENT // An ALIAS event. - yaml_SCALAR_EVENT // A SCALAR event. - yaml_SEQUENCE_START_EVENT // A SEQUENCE-START event. - yaml_SEQUENCE_END_EVENT // A SEQUENCE-END event. - yaml_MAPPING_START_EVENT // A MAPPING-START event. - yaml_MAPPING_END_EVENT // A MAPPING-END event. -) - -var eventStrings = []string{ - yaml_NO_EVENT: "none", - yaml_STREAM_START_EVENT: "stream start", - yaml_STREAM_END_EVENT: "stream end", - yaml_DOCUMENT_START_EVENT: "document start", - yaml_DOCUMENT_END_EVENT: "document end", - yaml_ALIAS_EVENT: "alias", - yaml_SCALAR_EVENT: "scalar", - yaml_SEQUENCE_START_EVENT: "sequence start", - yaml_SEQUENCE_END_EVENT: "sequence end", - yaml_MAPPING_START_EVENT: "mapping start", - yaml_MAPPING_END_EVENT: "mapping end", -} - -func (e yaml_event_type_t) String() string { - if e < 0 || int(e) >= len(eventStrings) { - return fmt.Sprintf("unknown event %d", e) - } - return eventStrings[e] -} - -// The event structure. -type yaml_event_t struct { - - // The event type. - typ yaml_event_type_t - - // The start and end of the event. - start_mark, end_mark yaml_mark_t - - // The document encoding (for yaml_STREAM_START_EVENT). - encoding yaml_encoding_t - - // The version directive (for yaml_DOCUMENT_START_EVENT). - version_directive *yaml_version_directive_t - - // The list of tag directives (for yaml_DOCUMENT_START_EVENT). - tag_directives []yaml_tag_directive_t - - // The anchor (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_ALIAS_EVENT). - anchor []byte - - // The tag (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). - tag []byte - - // The scalar value (for yaml_SCALAR_EVENT). - value []byte - - // Is the document start/end indicator implicit, or the tag optional? - // (for yaml_DOCUMENT_START_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_SCALAR_EVENT). - implicit bool - - // Is the tag optional for any non-plain style? (for yaml_SCALAR_EVENT). - quoted_implicit bool - - // The style (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT). - style yaml_style_t -} - -func (e *yaml_event_t) scalar_style() yaml_scalar_style_t { return yaml_scalar_style_t(e.style) } -func (e *yaml_event_t) sequence_style() yaml_sequence_style_t { return yaml_sequence_style_t(e.style) } -func (e *yaml_event_t) mapping_style() yaml_mapping_style_t { return yaml_mapping_style_t(e.style) } - -// Nodes - -const ( - yaml_NULL_TAG = "tag:yaml.org,2002:null" // The tag !!null with the only possible value: null. - yaml_BOOL_TAG = "tag:yaml.org,2002:bool" // The tag !!bool with the values: true and false. - yaml_STR_TAG = "tag:yaml.org,2002:str" // The tag !!str for string values. - yaml_INT_TAG = "tag:yaml.org,2002:int" // The tag !!int for integer values. - yaml_FLOAT_TAG = "tag:yaml.org,2002:float" // The tag !!float for float values. - yaml_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp" // The tag !!timestamp for date and time values. - - yaml_SEQ_TAG = "tag:yaml.org,2002:seq" // The tag !!seq is used to denote sequences. - yaml_MAP_TAG = "tag:yaml.org,2002:map" // The tag !!map is used to denote mapping. - - // Not in original libyaml. - yaml_BINARY_TAG = "tag:yaml.org,2002:binary" - yaml_MERGE_TAG = "tag:yaml.org,2002:merge" - - yaml_DEFAULT_SCALAR_TAG = yaml_STR_TAG // The default scalar tag is !!str. - yaml_DEFAULT_SEQUENCE_TAG = yaml_SEQ_TAG // The default sequence tag is !!seq. - yaml_DEFAULT_MAPPING_TAG = yaml_MAP_TAG // The default mapping tag is !!map. -) - -type yaml_node_type_t int - -// Node types. -const ( - // An empty node. - yaml_NO_NODE yaml_node_type_t = iota - - yaml_SCALAR_NODE // A scalar node. - yaml_SEQUENCE_NODE // A sequence node. - yaml_MAPPING_NODE // A mapping node. -) - -// An element of a sequence node. -type yaml_node_item_t int - -// An element of a mapping node. -type yaml_node_pair_t struct { - key int // The key of the element. - value int // The value of the element. -} - -// The node structure. -type yaml_node_t struct { - typ yaml_node_type_t // The node type. - tag []byte // The node tag. - - // The node data. - - // The scalar parameters (for yaml_SCALAR_NODE). - scalar struct { - value []byte // The scalar value. - length int // The length of the scalar value. - style yaml_scalar_style_t // The scalar style. - } - - // The sequence parameters (for YAML_SEQUENCE_NODE). - sequence struct { - items_data []yaml_node_item_t // The stack of sequence items. - style yaml_sequence_style_t // The sequence style. - } - - // The mapping parameters (for yaml_MAPPING_NODE). - mapping struct { - pairs_data []yaml_node_pair_t // The stack of mapping pairs (key, value). - pairs_start *yaml_node_pair_t // The beginning of the stack. - pairs_end *yaml_node_pair_t // The end of the stack. - pairs_top *yaml_node_pair_t // The top of the stack. - style yaml_mapping_style_t // The mapping style. - } - - start_mark yaml_mark_t // The beginning of the node. - end_mark yaml_mark_t // The end of the node. - -} - -// The document structure. -type yaml_document_t struct { - - // The document nodes. - nodes []yaml_node_t - - // The version directive. - version_directive *yaml_version_directive_t - - // The list of tag directives. - tag_directives_data []yaml_tag_directive_t - tag_directives_start int // The beginning of the tag directives list. - tag_directives_end int // The end of the tag directives list. - - start_implicit int // Is the document start indicator implicit? - end_implicit int // Is the document end indicator implicit? - - // The start/end of the document. - start_mark, end_mark yaml_mark_t -} - -// The prototype of a read handler. -// -// The read handler is called when the parser needs to read more bytes from the -// source. The handler should write not more than size bytes to the buffer. -// The number of written bytes should be set to the size_read variable. -// -// [in,out] data A pointer to an application data specified by -// yaml_parser_set_input(). -// [out] buffer The buffer to write the data from the source. -// [in] size The size of the buffer. -// [out] size_read The actual number of bytes read from the source. -// -// On success, the handler should return 1. If the handler failed, -// the returned value should be 0. On EOF, the handler should set the -// size_read to 0 and return 1. -type yaml_read_handler_t func(parser *yaml_parser_t, buffer []byte) (n int, err error) - -// This structure holds information about a potential simple key. -type yaml_simple_key_t struct { - possible bool // Is a simple key possible? - required bool // Is a simple key required? - token_number int // The number of the token. - mark yaml_mark_t // The position mark. -} - -// The states of the parser. -type yaml_parser_state_t int - -const ( - yaml_PARSE_STREAM_START_STATE yaml_parser_state_t = iota - - yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE // Expect the beginning of an implicit document. - yaml_PARSE_DOCUMENT_START_STATE // Expect DOCUMENT-START. - yaml_PARSE_DOCUMENT_CONTENT_STATE // Expect the content of a document. - yaml_PARSE_DOCUMENT_END_STATE // Expect DOCUMENT-END. - yaml_PARSE_BLOCK_NODE_STATE // Expect a block node. - yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE // Expect a block node or indentless sequence. - yaml_PARSE_FLOW_NODE_STATE // Expect a flow node. - yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a block sequence. - yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE // Expect an entry of a block sequence. - yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE // Expect an entry of an indentless sequence. - yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping. - yaml_PARSE_BLOCK_MAPPING_KEY_STATE // Expect a block mapping key. - yaml_PARSE_BLOCK_MAPPING_VALUE_STATE // Expect a block mapping value. - yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a flow sequence. - yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE // Expect an entry of a flow sequence. - yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE // Expect a key of an ordered mapping. - yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE // Expect a value of an ordered mapping. - yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE // Expect the and of an ordered mapping entry. - yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping. - yaml_PARSE_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping. - yaml_PARSE_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping. - yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE // Expect an empty value of a flow mapping. - yaml_PARSE_END_STATE // Expect nothing. -) - -func (ps yaml_parser_state_t) String() string { - switch ps { - case yaml_PARSE_STREAM_START_STATE: - return "yaml_PARSE_STREAM_START_STATE" - case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE: - return "yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE" - case yaml_PARSE_DOCUMENT_START_STATE: - return "yaml_PARSE_DOCUMENT_START_STATE" - case yaml_PARSE_DOCUMENT_CONTENT_STATE: - return "yaml_PARSE_DOCUMENT_CONTENT_STATE" - case yaml_PARSE_DOCUMENT_END_STATE: - return "yaml_PARSE_DOCUMENT_END_STATE" - case yaml_PARSE_BLOCK_NODE_STATE: - return "yaml_PARSE_BLOCK_NODE_STATE" - case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE: - return "yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE" - case yaml_PARSE_FLOW_NODE_STATE: - return "yaml_PARSE_FLOW_NODE_STATE" - case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE: - return "yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE" - case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE: - return "yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE" - case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE: - return "yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE" - case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE: - return "yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE" - case yaml_PARSE_BLOCK_MAPPING_KEY_STATE: - return "yaml_PARSE_BLOCK_MAPPING_KEY_STATE" - case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE: - return "yaml_PARSE_BLOCK_MAPPING_VALUE_STATE" - case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE" - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE" - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE" - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE" - case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE: - return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE" - case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE: - return "yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE" - case yaml_PARSE_FLOW_MAPPING_KEY_STATE: - return "yaml_PARSE_FLOW_MAPPING_KEY_STATE" - case yaml_PARSE_FLOW_MAPPING_VALUE_STATE: - return "yaml_PARSE_FLOW_MAPPING_VALUE_STATE" - case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE: - return "yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE" - case yaml_PARSE_END_STATE: - return "yaml_PARSE_END_STATE" - } - return "" -} - -// This structure holds aliases data. -type yaml_alias_data_t struct { - anchor []byte // The anchor. - index int // The node id. - mark yaml_mark_t // The anchor mark. -} - -// The parser structure. -// -// All members are internal. Manage the structure using the -// yaml_parser_ family of functions. -type yaml_parser_t struct { - - // Error handling - - error yaml_error_type_t // Error type. - - problem string // Error description. - - // The byte about which the problem occurred. - problem_offset int - problem_value int - problem_mark yaml_mark_t - - // The error context. - context string - context_mark yaml_mark_t - - // Reader stuff - - read_handler yaml_read_handler_t // Read handler. - - input_reader io.Reader // File input data. - input []byte // String input data. - input_pos int - - eof bool // EOF flag - - buffer []byte // The working buffer. - buffer_pos int // The current position of the buffer. - - unread int // The number of unread characters in the buffer. - - raw_buffer []byte // The raw buffer. - raw_buffer_pos int // The current position of the buffer. - - encoding yaml_encoding_t // The input encoding. - - offset int // The offset of the current position (in bytes). - mark yaml_mark_t // The mark of the current position. - - // Scanner stuff - - stream_start_produced bool // Have we started to scan the input stream? - stream_end_produced bool // Have we reached the end of the input stream? - - flow_level int // The number of unclosed '[' and '{' indicators. - - tokens []yaml_token_t // The tokens queue. - tokens_head int // The head of the tokens queue. - tokens_parsed int // The number of tokens fetched from the queue. - token_available bool // Does the tokens queue contain a token ready for dequeueing. - - indent int // The current indentation level. - indents []int // The indentation levels stack. - - simple_key_allowed bool // May a simple key occur at the current position? - simple_keys []yaml_simple_key_t // The stack of simple keys. - simple_keys_by_tok map[int]int // possible simple_key indexes indexed by token_number - - // Parser stuff - - state yaml_parser_state_t // The current parser state. - states []yaml_parser_state_t // The parser states stack. - marks []yaml_mark_t // The stack of marks. - tag_directives []yaml_tag_directive_t // The list of TAG directives. - - // Dumper stuff - - aliases []yaml_alias_data_t // The alias data. - - document *yaml_document_t // The currently parsed document. -} - -// Emitter Definitions - -// The prototype of a write handler. -// -// The write handler is called when the emitter needs to flush the accumulated -// characters to the output. The handler should write @a size bytes of the -// @a buffer to the output. -// -// @param[in,out] data A pointer to an application data specified by -// yaml_emitter_set_output(). -// @param[in] buffer The buffer with bytes to be written. -// @param[in] size The size of the buffer. -// -// @returns On success, the handler should return @c 1. If the handler failed, -// the returned value should be @c 0. -// -type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error - -type yaml_emitter_state_t int - -// The emitter states. -const ( - // Expect STREAM-START. - yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota - - yaml_EMIT_FIRST_DOCUMENT_START_STATE // Expect the first DOCUMENT-START or STREAM-END. - yaml_EMIT_DOCUMENT_START_STATE // Expect DOCUMENT-START or STREAM-END. - yaml_EMIT_DOCUMENT_CONTENT_STATE // Expect the content of a document. - yaml_EMIT_DOCUMENT_END_STATE // Expect DOCUMENT-END. - yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a flow sequence. - yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE // Expect an item of a flow sequence. - yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping. - yaml_EMIT_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping. - yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a flow mapping. - yaml_EMIT_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping. - yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a block sequence. - yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE // Expect an item of a block sequence. - yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping. - yaml_EMIT_BLOCK_MAPPING_KEY_STATE // Expect the key of a block mapping. - yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a block mapping. - yaml_EMIT_BLOCK_MAPPING_VALUE_STATE // Expect a value of a block mapping. - yaml_EMIT_END_STATE // Expect nothing. -) - -// The emitter structure. -// -// All members are internal. Manage the structure using the @c yaml_emitter_ -// family of functions. -type yaml_emitter_t struct { - - // Error handling - - error yaml_error_type_t // Error type. - problem string // Error description. - - // Writer stuff - - write_handler yaml_write_handler_t // Write handler. - - output_buffer *[]byte // String output data. - output_writer io.Writer // File output data. - - buffer []byte // The working buffer. - buffer_pos int // The current position of the buffer. - - raw_buffer []byte // The raw buffer. - raw_buffer_pos int // The current position of the buffer. - - encoding yaml_encoding_t // The stream encoding. - - // Emitter stuff - - canonical bool // If the output is in the canonical style? - best_indent int // The number of indentation spaces. - best_width int // The preferred width of the output lines. - unicode bool // Allow unescaped non-ASCII characters? - line_break yaml_break_t // The preferred line break. - - state yaml_emitter_state_t // The current emitter state. - states []yaml_emitter_state_t // The stack of states. - - events []yaml_event_t // The event queue. - events_head int // The head of the event queue. - - indents []int // The stack of indentation levels. - - tag_directives []yaml_tag_directive_t // The list of tag directives. - - indent int // The current indentation level. - - flow_level int // The current flow level. - - root_context bool // Is it the document root context? - sequence_context bool // Is it a sequence context? - mapping_context bool // Is it a mapping context? - simple_key_context bool // Is it a simple mapping key context? - - line int // The current line. - column int // The current column. - whitespace bool // If the last character was a whitespace? - indention bool // If the last character was an indentation character (' ', '-', '?', ':')? - open_ended bool // If an explicit document end is required? - - // Anchor analysis. - anchor_data struct { - anchor []byte // The anchor value. - alias bool // Is it an alias? - } - - // Tag analysis. - tag_data struct { - handle []byte // The tag handle. - suffix []byte // The tag suffix. - } - - // Scalar analysis. - scalar_data struct { - value []byte // The scalar value. - multiline bool // Does the scalar contain line breaks? - flow_plain_allowed bool // Can the scalar be expessed in the flow plain style? - block_plain_allowed bool // Can the scalar be expressed in the block plain style? - single_quoted_allowed bool // Can the scalar be expressed in the single quoted style? - block_allowed bool // Can the scalar be expressed in the literal or folded styles? - style yaml_scalar_style_t // The output style. - } - - // Dumper stuff - - opened bool // If the stream was already opened? - closed bool // If the stream was already closed? - - // The information associated with the document nodes. - anchors *struct { - references int // The number of references. - anchor int // The anchor id. - serialized bool // If the node has been emitted? - } - - last_anchor_id int // The last assigned anchor id. - - document *yaml_document_t // The currently emitted document. -} diff --git a/vendor/gopkg.in/yaml.v2/yamlprivateh.go b/vendor/gopkg.in/yaml.v2/yamlprivateh.go deleted file mode 100644 index 8110ce3..0000000 --- a/vendor/gopkg.in/yaml.v2/yamlprivateh.go +++ /dev/null @@ -1,173 +0,0 @@ -package yaml - -const ( - // The size of the input raw buffer. - input_raw_buffer_size = 512 - - // The size of the input buffer. - // It should be possible to decode the whole raw buffer. - input_buffer_size = input_raw_buffer_size * 3 - - // The size of the output buffer. - output_buffer_size = 128 - - // The size of the output raw buffer. - // It should be possible to encode the whole output buffer. - output_raw_buffer_size = (output_buffer_size*2 + 2) - - // The size of other stacks and queues. - initial_stack_size = 16 - initial_queue_size = 16 - initial_string_size = 16 -) - -// Check if the character at the specified position is an alphabetical -// character, a digit, '_', or '-'. -func is_alpha(b []byte, i int) bool { - return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'Z' || b[i] >= 'a' && b[i] <= 'z' || b[i] == '_' || b[i] == '-' -} - -// Check if the character at the specified position is a digit. -func is_digit(b []byte, i int) bool { - return b[i] >= '0' && b[i] <= '9' -} - -// Get the value of a digit. -func as_digit(b []byte, i int) int { - return int(b[i]) - '0' -} - -// Check if the character at the specified position is a hex-digit. -func is_hex(b []byte, i int) bool { - return b[i] >= '0' && b[i] <= '9' || b[i] >= 'A' && b[i] <= 'F' || b[i] >= 'a' && b[i] <= 'f' -} - -// Get the value of a hex-digit. -func as_hex(b []byte, i int) int { - bi := b[i] - if bi >= 'A' && bi <= 'F' { - return int(bi) - 'A' + 10 - } - if bi >= 'a' && bi <= 'f' { - return int(bi) - 'a' + 10 - } - return int(bi) - '0' -} - -// Check if the character is ASCII. -func is_ascii(b []byte, i int) bool { - return b[i] <= 0x7F -} - -// Check if the character at the start of the buffer can be printed unescaped. -func is_printable(b []byte, i int) bool { - return ((b[i] == 0x0A) || // . == #x0A - (b[i] >= 0x20 && b[i] <= 0x7E) || // #x20 <= . <= #x7E - (b[i] == 0xC2 && b[i+1] >= 0xA0) || // #0xA0 <= . <= #xD7FF - (b[i] > 0xC2 && b[i] < 0xED) || - (b[i] == 0xED && b[i+1] < 0xA0) || - (b[i] == 0xEE) || - (b[i] == 0xEF && // #xE000 <= . <= #xFFFD - !(b[i+1] == 0xBB && b[i+2] == 0xBF) && // && . != #xFEFF - !(b[i+1] == 0xBF && (b[i+2] == 0xBE || b[i+2] == 0xBF)))) -} - -// Check if the character at the specified position is NUL. -func is_z(b []byte, i int) bool { - return b[i] == 0x00 -} - -// Check if the beginning of the buffer is a BOM. -func is_bom(b []byte, i int) bool { - return b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF -} - -// Check if the character at the specified position is space. -func is_space(b []byte, i int) bool { - return b[i] == ' ' -} - -// Check if the character at the specified position is tab. -func is_tab(b []byte, i int) bool { - return b[i] == '\t' -} - -// Check if the character at the specified position is blank (space or tab). -func is_blank(b []byte, i int) bool { - //return is_space(b, i) || is_tab(b, i) - return b[i] == ' ' || b[i] == '\t' -} - -// Check if the character at the specified position is a line break. -func is_break(b []byte, i int) bool { - return (b[i] == '\r' || // CR (#xD) - b[i] == '\n' || // LF (#xA) - b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9) // PS (#x2029) -} - -func is_crlf(b []byte, i int) bool { - return b[i] == '\r' && b[i+1] == '\n' -} - -// Check if the character is a line break or NUL. -func is_breakz(b []byte, i int) bool { - //return is_break(b, i) || is_z(b, i) - return ( // is_break: - b[i] == '\r' || // CR (#xD) - b[i] == '\n' || // LF (#xA) - b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) - // is_z: - b[i] == 0) -} - -// Check if the character is a line break, space, or NUL. -func is_spacez(b []byte, i int) bool { - //return is_space(b, i) || is_breakz(b, i) - return ( // is_space: - b[i] == ' ' || - // is_breakz: - b[i] == '\r' || // CR (#xD) - b[i] == '\n' || // LF (#xA) - b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) - b[i] == 0) -} - -// Check if the character is a line break, space, tab, or NUL. -func is_blankz(b []byte, i int) bool { - //return is_blank(b, i) || is_breakz(b, i) - return ( // is_blank: - b[i] == ' ' || b[i] == '\t' || - // is_breakz: - b[i] == '\r' || // CR (#xD) - b[i] == '\n' || // LF (#xA) - b[i] == 0xC2 && b[i+1] == 0x85 || // NEL (#x85) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA8 || // LS (#x2028) - b[i] == 0xE2 && b[i+1] == 0x80 && b[i+2] == 0xA9 || // PS (#x2029) - b[i] == 0) -} - -// Determine the width of the character. -func width(b byte) int { - // Don't replace these by a switch without first - // confirming that it is being inlined. - if b&0x80 == 0x00 { - return 1 - } - if b&0xE0 == 0xC0 { - return 2 - } - if b&0xF0 == 0xE0 { - return 3 - } - if b&0xF8 == 0xF0 { - return 4 - } - return 0 - -} diff --git a/vendor/local/args/.gitignore b/vendor/local/args/.gitignore deleted file mode 100644 index e53b20b..0000000 --- a/vendor/local/args/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -.*.go -vendor -*.swp -*.swo -testdata -fireflyiii -*.db -*.ldb -*.log -*.bak -CURRENT -LOCK -LOG -MANIFEST-* diff --git a/vendor/local/args/arg.go b/vendor/local/args/arg.go deleted file mode 100644 index 753a8fe..0000000 --- a/vendor/local/args/arg.go +++ /dev/null @@ -1,222 +0,0 @@ -package args - -import ( - "fmt" - "math" - "strconv" - "strings" - "time" -) - -type Arg struct { - Env string - Flag string - Help string - Default interface{} - Value interface{} - ArgType Type -} - -func NewArg(argType Type, key, help string, def interface{}) *Arg { - return &Arg{ - Env: strings.ToUpper(key), - Flag: strings.ToLower(key), - Help: help, - Default: def, - Value: def, - ArgType: argType, - } -} - -func (a *Arg) String() string { - return fmt.Sprintf("[%s $%s/-%s, %v from %v, help %v]", - a.ArgType, - a.Env, - a.Flag, - a.Value, - a.Default, - a.Help, - ) -} - -func (a *Arg) Get() interface{} { - return a.Value -} - -func (a *Arg) GetInt() int { - if a.ArgType != INT { - return -1 - } - if _, ok := a.Value.(int); !ok { - return -1 - } - return a.Value.(int) -} - -func (a *Arg) GetString() string { - if a.ArgType != STRING { - return "" - } - if _, ok := a.Value.(string); !ok { - return "" - } - return a.Value.(string) -} - -func (a *Arg) GetBool() bool { - if a.ArgType != BOOL { - return false - } - if _, ok := a.Value.(bool); !ok { - return false - } - return a.Value.(bool) -} - -func (a *Arg) GetDuration() time.Duration { - if a.ArgType != DURATION { - return time.Duration(-1) - } - if _, ok := a.Value.(time.Duration); !ok { - return time.Duration(-1) - } - return a.Value.(time.Duration) -} - -func (a *Arg) GetTime() time.Time { - if a.ArgType != TIME { - return time.Date(1995, 1, 1, 0, 0, 0, 0, time.UTC) - } - if _, ok := a.Value.(time.Time); !ok { - return time.Date(1995, 1, 1, 0, 0, 0, 0, time.UTC) - } - return a.Value.(time.Time) -} - -func (a *Arg) GetFloat() float32 { - if a.ArgType != FLOAT { - return float32(-1) - } - if _, ok := a.Value.(float32); !ok { - return float32(-1) - } - return a.Value.(float32) -} - -func (a *Arg) Set(value interface{}) error { - err := fmt.Errorf("incompatible set of type %T for arg $%v/-%v type %v", value, a.Env, a.Flag, a.ArgType) - switch a.ArgType { - case INT: - switch value.(type) { - case int: - a.Value = value.(int) - err = nil - case string: - s := value.(string) - var i int - if i, err = strconv.Atoi(s); err == nil { - a.Value = i - err = nil - } - case float64: - f := value.(float64) - if f-float64(int(f)) == 0 { - a.Value = int(f) - err = nil - } - } - case STRING: - i, ok := value.(string) - if ok { - a.Value = i - err = nil - } - case BOOL: - i, ok := value.(bool) - if ok { - a.Value = i - err = nil - } else if s, ok := value.(string); !ok { - } else if i, err = strconv.ParseBool(s); err == nil { - a.Value = i - err = nil - } - case DURATION: - i, ok := value.(time.Duration) - if ok { - a.Value = i - err = nil - } else if s, ok := value.(string); !ok { - } else if i, err = time.ParseDuration(s); err == nil { - a.Value = i - err = nil - } - case TIME: - if i, ok := value.(time.Duration); ok { - a.Value = time.Now().Add(i) - err = nil - } else if j, ok := value.(time.Time); ok { - a.Value = j - err = nil - } else if s, ok := value.(string); !ok { - } else if i, err = time.ParseDuration(s); err == nil { - a.Value = time.Now().Add(i) - err = nil - } else { - layouts := []string{ - "01-02-2006", - "01/02/2006", - "01-02-06", - "01/02/06", - "2006-01-02", - "2006/01/02", - "06-01-02", - "06/01/02", - "2006-01-02 15:04:05.999999999 -0700 MST", - "15:04:05.999999999 -0700 MST", - "15:04:05 -0700 MST", - "15:04 -0700 MST", - "15:04", - } - for k := range layouts { - if j, err = time.Parse(layouts[k], s); err == nil { - a.Value = j - err = nil - break - } - } - if err == nil && s != "" { - j, _ := a.Value.(time.Time) - if j.Year() < 1980 { - n := time.Now() - j = j.AddDate(n.Year()-j.Year(), int(n.Month()-j.Month()), n.Day()-j.Day()) - j = j.In(time.Local) - t := time.Date(2000, 02, 02, 12, 02, 02, 02, time.UTC) - l := t.Local() - tzDiff := int(math.Abs(float64(t.Hour() - l.Hour()))) - j = j.Add(time.Hour * time.Duration(tzDiff)) - } - a.Value = j - } - } - case FLOAT: - if i, ok := value.(float32); ok { - a.Value = i - err = nil - } else if j, ok := value.(float64); ok { - a.Value = float32(j) - err = nil - } else if k, ok := value.(int); ok { - a.Value = float32(k) - err = nil - } else if s, ok := value.(string); !ok { - } else if j, err = strconv.ParseFloat(s, 32); err == nil { - a.Value = float32(j) - err = nil - } else if k, err = strconv.Atoi(s); err == nil { - a.Value = float32(k) - err = nil - } - } - return err -} diff --git a/vendor/local/args/argset.go b/vendor/local/args/argset.go deleted file mode 100644 index 51f1e53..0000000 --- a/vendor/local/args/argset.go +++ /dev/null @@ -1,209 +0,0 @@ -package args - -import ( - "encoding/json" - "errors" - "flag" - "fmt" - "io/ioutil" - "os" - "strings" - "time" - - yaml "gopkg.in/yaml.v2" -) - -type ArgSet struct { - parsed bool - args []*Arg - configFiles []string -} - -func NewArgSet(configFiles ...string) *ArgSet { - return &ArgSet{ - args: []*Arg{}, - configFiles: configFiles, - } -} - -func (as *ArgSet) String() string { - s := "{" - for _, arg := range as.args { - if len(s) > 2 { - s += ", " - } - s += fmt.Sprintf("%s:%v", arg.Flag, arg.Value) - } - s += "}" - return s -} - -func (as *ArgSet) Append(argType Type, key, help string, def interface{}) { - as.args = append(as.args, NewArg(argType, key, help, def)) -} - -func (as *ArgSet) Get(key string) *Arg { - if !as.parsed { - return nil - } - for i := range as.args { - if as.args[i].Env == key || as.args[i].Flag == key { - return as.args[i] - } - } - return nil -} - -func (as *ArgSet) GetFloat(key string) float32 { - a := as.Get(key) - return a.GetFloat() -} - -func (as *ArgSet) GetInt(key string) int { - a := as.Get(key) - return a.GetInt() -} - -func (as *ArgSet) GetBool(key string) bool { - a := as.Get(key) - return a.GetBool() -} - -func (as *ArgSet) GetDuration(key string) time.Duration { - a := as.Get(key) - return a.GetDuration() -} - -func (as *ArgSet) GetString(key string) string { - a := as.Get(key) - return a.GetString() -} - -func (as *ArgSet) Parse() error { - if as.parsed { - return nil - } - defer func() { - as.parsed = true - }() - - if err := as.setValueFromDefaults(); err != nil { - return err - } - if err := as.setValueFromFiles(); err != nil { - return err - } - if err := as.setValueFromEnv(); err != nil { - return err - } - if err := as.setValueFromFlags(); err != nil { - return err - } - - return nil -} - -func (as *ArgSet) setValueFromDefaults() error { - for i := range as.args { - if err := as.args[i].Set(as.args[i].Default); err != nil { - return err - } - } - return nil -} - -func (as *ArgSet) setValueFromEnv() error { - for i := range as.args { - key := as.args[i].Env - key = strings.ReplaceAll(key, "-", "_") - if v, ok := os.LookupEnv(key); ok { - if err := as.args[i].Set(v); err != nil { - return err - } - } - } - return nil -} - -func (as *ArgSet) setValueFromFlags() error { - var err error - fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) - for i := range as.args { - arg := as.args[i] - switch arg.ArgType { - case INT: - arg.Default = fs.Int(arg.Flag, arg.Value.(int), arg.Help) - case STRING: - arg.Default = fs.String(arg.Flag, arg.Value.(string), arg.Help) - case BOOL: - arg.Default = fs.Bool(arg.Flag, arg.Value.(bool), arg.Help) - case DURATION: - arg.Default = fs.Duration(arg.Flag, arg.Value.(time.Duration), arg.Help) - case TIME: - arg.Default = fs.String(arg.Flag, arg.Value.(time.Time).Format("2006-01-02"), arg.Help) - case FLOAT: - arg.Default = fs.Float64(arg.Flag, float64(arg.Value.(float32)), arg.Help) - default: - return errors.New("unknown type, cannot set from flag") - } - } - if err := fs.Parse(os.Args[1:]); err != nil { - return err - } - for i := range as.args { - arg := as.args[i] - switch arg.ArgType { - case INT: - arg.Value = *arg.Default.(*int) - case STRING: - arg.Value = *arg.Default.(*string) - case BOOL: - arg.Value = *arg.Default.(*bool) - case DURATION: - arg.Value = *arg.Default.(*time.Duration) - case TIME: - arg.Value = *arg.Default.(*string) - err = arg.Set(arg.Value) - case FLOAT: - arg.Value = *arg.Default.(*float64) - err = arg.Set(arg.Value) - } - } - return err -} - -func (as *ArgSet) setValueFromFiles() error { - for _, file := range as.configFiles { - if err := as.setValueFromFile(file); err != nil { - return err - } - } - return nil -} - -func (as *ArgSet) setValueFromFile(path string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - var config map[string]interface{} - if strings.HasSuffix(path, ".json") { - err = json.Unmarshal(b, &config) - } else if strings.HasSuffix(path, ".yaml") { - err = yaml.Unmarshal(b, &config) - } else { - err = fmt.Errorf("unknown config file suffix: %s", path) - } - if err != nil { - return err - } - for i := range as.args { - key := as.args[i].Flag - if v, ok := config[key]; ok { - if err := as.args[i].Set(v); err != nil { - return err - } - } - } - return nil -} diff --git a/vendor/local/args/type.go b/vendor/local/args/type.go deleted file mode 100644 index d019eab..0000000 --- a/vendor/local/args/type.go +++ /dev/null @@ -1,36 +0,0 @@ -package args - -import ( - "fmt" - "time" -) - -type Type int - -const ( - INT = Type(iota) - STRING = Type(iota) - BOOL = Type(iota) - DURATION = Type(iota) - TIME = Type(iota) - FLOAT = Type(iota) -) - -func (t Type) String() string { - var i interface{} = nil - switch t { - case INT: - i = 1 - case STRING: - i = "" - case BOOL: - i = false - case DURATION: - i = time.Duration(0) - case TIME: - i = time.Time{} - case FLOAT: - i = float32(0) - } - return fmt.Sprintf("%T", i) -} diff --git a/vendor/modules.txt b/vendor/modules.txt deleted file mode 100644 index 0107464..0000000 --- a/vendor/modules.txt +++ /dev/null @@ -1,25 +0,0 @@ -# github.com/bytbox/go-pop3 v0.0.0-20120201222208-3046caf0763e -## explicit -github.com/bytbox/go-pop3 -# github.com/emersion/go-imap v1.2.0 -## explicit; go 1.13 -github.com/emersion/go-imap -github.com/emersion/go-imap/client -github.com/emersion/go-imap/commands -github.com/emersion/go-imap/responses -github.com/emersion/go-imap/utf7 -# github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 -## explicit; go 1.12 -github.com/emersion/go-sasl -# golang.org/x/text v0.3.7 -## explicit; go 1.17 -golang.org/x/text/encoding -golang.org/x/text/encoding/internal/identifier -golang.org/x/text/transform -# gopkg.in/yaml.v2 v2.4.0 -## explicit; go 1.15 -gopkg.in/yaml.v2 -# local/args v0.0.0-00010101000000-000000000000 => ../../args -## explicit; go 1.16 -local/args -# local/args => ../../args