Depenancy upgrades and movign to dep. (#8630)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
bf24f51c4e
Коммит
6e2cb00008
22
vendor/github.com/mattermost/rsc/.gitignore
сгенерированный
поставляемый
22
vendor/github.com/mattermost/rsc/.gitignore
сгенерированный
поставляемый
@@ -1,22 +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
|
||||
4
vendor/github.com/mattermost/rsc/README.md
сгенерированный
поставляемый
4
vendor/github.com/mattermost/rsc/README.md
сгенерированный
поставляемый
@@ -1,4 +0,0 @@
|
||||
rsc
|
||||
===
|
||||
|
||||
fork of Russ Cox's code.google.com/p/rsc
|
||||
39
vendor/github.com/mattermost/rsc/app/app.go
сгенерированный
поставляемый
39
vendor/github.com/mattermost/rsc/app/app.go
сгенерированный
поставляемый
@@ -1,39 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"appengine"
|
||||
"appengine/memcache"
|
||||
|
||||
_ "github.com/mattermost/rsc/appfs/server"
|
||||
_ "github.com/mattermost/rsc/blog/post"
|
||||
)
|
||||
|
||||
func init() {
|
||||
http.HandleFunc("/admin/", Admin)
|
||||
}
|
||||
|
||||
func Admin(w http.ResponseWriter, req *http.Request) {
|
||||
c := appengine.NewContext(req)
|
||||
switch req.FormValue("op") {
|
||||
default:
|
||||
fmt.Fprintf(w, "unknown op %s\n", req.FormValue("op"))
|
||||
case "memcache-get":
|
||||
key := req.FormValue("key")
|
||||
item, err := memcache.Get(c, key)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "ERROR: %s\n", err)
|
||||
return
|
||||
}
|
||||
w.Write(item.Value)
|
||||
case "memcache-delete":
|
||||
key := req.FormValue("key")
|
||||
if err := memcache.Delete(c, key); err != nil {
|
||||
fmt.Fprintf(w, "ERROR: %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "deleted %s\n", key)
|
||||
}
|
||||
}
|
||||
23
vendor/github.com/mattermost/rsc/app/app.yaml
сгенерированный
поставляемый
23
vendor/github.com/mattermost/rsc/app/app.yaml
сгенерированный
поставляемый
@@ -1,23 +0,0 @@
|
||||
# mkapp
|
||||
# ~/pub/go_appengine/dev_appserver.py --high_replication tmp
|
||||
# ~/pub/go_appengine/appcfg.py update tmp
|
||||
|
||||
application: rsc-swtch-app
|
||||
runtime: go
|
||||
version: test
|
||||
api_version: go1
|
||||
|
||||
handlers:
|
||||
- url: /\.appfs.*
|
||||
script: _go_app
|
||||
secure: always
|
||||
- url: /draft(/.*)?
|
||||
script: _go_app
|
||||
login: required
|
||||
- url: /admin(/.*)?
|
||||
script: _go_app
|
||||
login: admin
|
||||
|
||||
# MUST BE LAST
|
||||
- url: /.*
|
||||
script: _go_app
|
||||
16
vendor/github.com/mattermost/rsc/app/index.yaml
сгенерированный
поставляемый
16
vendor/github.com/mattermost/rsc/app/index.yaml
сгенерированный
поставляемый
@@ -1,16 +0,0 @@
|
||||
indexes:
|
||||
|
||||
# AUTOGENERATED
|
||||
|
||||
# This index.yaml is automatically updated whenever the dev_appserver
|
||||
# detects that a new type of query is run. If you want to manage the
|
||||
# index.yaml file manually, remove the above marker line (the line
|
||||
# saying "# AUTOGENERATED"). If you want to manage some indexes
|
||||
# manually, move them above the marker line. The index.yaml file is
|
||||
# automatically uploaded to the admin console when you next deploy
|
||||
# your application using appcfg.py.
|
||||
|
||||
- kind: FileInfo
|
||||
ancestor: yes
|
||||
properties:
|
||||
- name: Path
|
||||
156
vendor/github.com/mattermost/rsc/appfs/appfile/main.go
сгенерированный
поставляемый
156
vendor/github.com/mattermost/rsc/appfs/appfile/main.go
сгенерированный
поставляемый
@@ -1,156 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// appfile is a command-line interface to an appfs file system.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/rsc/appfs/client"
|
||||
"github.com/mattermost/rsc/keychain"
|
||||
)
|
||||
|
||||
var c client.Client
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&c.Host, "h", "localhost:8080", "app serving host")
|
||||
flag.StringVar(&c.User, "u", "", "user name")
|
||||
flag.StringVar(&c.Password, "p", "", "password")
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: appfile [-h host] cmd args...\n")
|
||||
fmt.Fprintf(os.Stderr, "\n")
|
||||
fmt.Fprintf(os.Stderr, "Commands are:\n")
|
||||
for _, c := range cmd {
|
||||
fmt.Fprintf(os.Stderr, "\t%s\n", c.name)
|
||||
}
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
if len(args) == 0 {
|
||||
usage()
|
||||
}
|
||||
|
||||
if c.Password == "" {
|
||||
var err error
|
||||
c.User, c.Password, err = keychain.UserPasswd(c.Host, "")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "unable to obtain user and password: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
name, args := args[0], args[1:]
|
||||
for _, c := range cmd {
|
||||
if name == c.name {
|
||||
switch c.arg {
|
||||
case 0, 1:
|
||||
if len(args) != c.arg {
|
||||
if c.arg == 0 {
|
||||
fmt.Fprintf(os.Stderr, "%s takes no arguments\n", name)
|
||||
os.Exit(2)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "%s requires 1 argument\n", name)
|
||||
os.Exit(2)
|
||||
}
|
||||
case 2:
|
||||
if len(args) == 0 {
|
||||
fmt.Fprintf(os.Stderr, "%s requires at least 1 argument\n", name)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
c.fn(args)
|
||||
return
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "unknown command %s\n", name)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
var cmd = []struct {
|
||||
name string
|
||||
fn func([]string)
|
||||
arg int
|
||||
}{
|
||||
{"mkdir", mkdir, 2},
|
||||
{"write", write, 1},
|
||||
{"read", read, 2},
|
||||
{"mkfs", mkfs, 0},
|
||||
{"stat", stat, 2},
|
||||
}
|
||||
|
||||
func mkdir(args []string) {
|
||||
for _, name := range args {
|
||||
if err := c.Create(name, true); err != nil {
|
||||
log.Printf("mkdir %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func write(args []string) {
|
||||
name := args[0]
|
||||
data, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Printf("reading stdin: %v", err)
|
||||
return
|
||||
}
|
||||
c.Create(name, false)
|
||||
if err := c.Write(name, data); err != nil {
|
||||
log.Printf("write %s: %v", name, err)
|
||||
}
|
||||
}
|
||||
|
||||
func read(args []string) {
|
||||
for _, name := range args {
|
||||
fi, err := c.Stat(name)
|
||||
if err != nil {
|
||||
log.Printf("stat %s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
if fi.IsDir {
|
||||
dirs, err := c.ReadDir(name)
|
||||
if err != nil {
|
||||
log.Printf("read %s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
for _, fi := range dirs {
|
||||
fmt.Printf("%+v\n", *fi)
|
||||
}
|
||||
} else {
|
||||
data, err := c.Read(name)
|
||||
if err != nil {
|
||||
log.Printf("read %s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
os.Stdout.Write(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mkfs([]string) {
|
||||
if err := c.Mkfs(); err != nil {
|
||||
log.Printf("mkfs: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func stat(args []string) {
|
||||
for _, name := range args {
|
||||
fi, err := c.Stat(name)
|
||||
if err != nil {
|
||||
log.Printf("stat %s: %v", name, err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("%+v\n", *fi)
|
||||
}
|
||||
}
|
||||
287
vendor/github.com/mattermost/rsc/appfs/appmount/main.go
сгенерированный
поставляемый
287
vendor/github.com/mattermost/rsc/appfs/appmount/main.go
сгенерированный
поставляемый
@@ -1,287 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// appmount mounts an appfs file system.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
"sync"
|
||||
"runtime"
|
||||
|
||||
"github.com/mattermost/rsc/appfs/client"
|
||||
"github.com/mattermost/rsc/appfs/proto"
|
||||
"github.com/mattermost/rsc/fuse"
|
||||
"github.com/mattermost/rsc/keychain"
|
||||
)
|
||||
|
||||
var usageMessage = `usage: appmount [-h host] [-u user] [-p password] /mnt
|
||||
|
||||
Appmount mounts the appfs file system on the named mount point.
|
||||
|
||||
The default host is localhost:8080.
|
||||
`
|
||||
|
||||
// Shared between master and slave.
|
||||
var z struct {
|
||||
Client client.Client
|
||||
Debug *bool
|
||||
Mtpt string
|
||||
}
|
||||
|
||||
var fc *fuse.Conn
|
||||
var cl = &z.Client
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&cl.Host, "h", "localhost:8080", "app serving host")
|
||||
flag.StringVar(&cl.User, "u", "", "user name")
|
||||
flag.StringVar(&cl.Password, "p", "", "password")
|
||||
z.Debug = flag.Bool("debug", false, "")
|
||||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Fprint(os.Stderr, usageMessage)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
|
||||
if len(os.Args) == 2 && os.Args[1] == "MOUNTSLAVE" {
|
||||
mountslave()
|
||||
return
|
||||
}
|
||||
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
if len(args) == 0 {
|
||||
usage()
|
||||
}
|
||||
z.Mtpt = args[0]
|
||||
|
||||
if cl.Password == "" {
|
||||
var err error
|
||||
cl.User, cl.Password, err = keychain.UserPasswd(cl.Host, "")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "unable to obtain user and password: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := cl.Stat("/"); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Run in child so that we can exit once child is running.
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
enc := gob.NewEncoder(&buf)
|
||||
enc.Encode(&z)
|
||||
|
||||
cmd := exec.Command(os.Args[0], "MOUNTSLAVE")
|
||||
cmd.Stdin = &buf
|
||||
cmd.Stdout = w
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.Fatalf("mount process: %v", err)
|
||||
}
|
||||
w.Close()
|
||||
|
||||
ok := make([]byte, 10)
|
||||
n, _ := r.Read(ok)
|
||||
if n != 2 || string(ok[0:2]) != "OK" {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "mounted on %s\n", z.Mtpt)
|
||||
}
|
||||
|
||||
func mountslave() {
|
||||
stdout, _ := syscall.Dup(1)
|
||||
syscall.Dup2(2, 1)
|
||||
|
||||
r := gob.NewDecoder(os.Stdin)
|
||||
if err := r.Decode(&z); err != nil {
|
||||
log.Fatalf("gob decode: %v", err)
|
||||
}
|
||||
|
||||
fc, err := fuse.Mount(z.Mtpt)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer exec.Command("umount", z.Mtpt).Run()
|
||||
|
||||
if *z.Debug {
|
||||
fuse.Debugf = log.Printf
|
||||
}
|
||||
|
||||
syscall.Write(stdout, []byte("OK"))
|
||||
syscall.Close(stdout)
|
||||
fc.Serve(FS{})
|
||||
}
|
||||
|
||||
type FS struct{}
|
||||
|
||||
func (FS) Root() (fuse.Node, fuse.Error) {
|
||||
return file("/")
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Name string
|
||||
FileInfo *proto.FileInfo
|
||||
Data []byte
|
||||
}
|
||||
|
||||
type statEntry struct {
|
||||
fi *proto.FileInfo
|
||||
err error
|
||||
t time.Time
|
||||
}
|
||||
|
||||
var statCache struct {
|
||||
mu sync.Mutex
|
||||
m map[string] statEntry
|
||||
}
|
||||
|
||||
func stat(name string) (*proto.FileInfo, error) {
|
||||
if runtime.GOOS == "darwin" && strings.Contains(name, "/._") {
|
||||
// Mac resource forks
|
||||
return nil, fmt.Errorf("file not found")
|
||||
}
|
||||
statCache.mu.Lock()
|
||||
e, ok := statCache.m[name]
|
||||
statCache.mu.Unlock()
|
||||
if ok && time.Since(e.t) < 2*time.Minute {
|
||||
return e.fi, e.err
|
||||
}
|
||||
fi, err := cl.Stat(name)
|
||||
saveStat(name, fi, err)
|
||||
return fi, err
|
||||
}
|
||||
|
||||
func saveStat(name string, fi *proto.FileInfo, err error) {
|
||||
if *z.Debug {
|
||||
if fi != nil {
|
||||
fmt.Fprintf(os.Stderr, "savestat %s %+v\n", name, *fi)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "savestat %s %v\n", name, err)
|
||||
}
|
||||
}
|
||||
statCache.mu.Lock()
|
||||
if statCache.m == nil {
|
||||
statCache.m = make(map[string]statEntry)
|
||||
}
|
||||
statCache.m[name] = statEntry{fi, err, time.Now()}
|
||||
statCache.mu.Unlock()
|
||||
}
|
||||
|
||||
func delStat(name string) {
|
||||
statCache.mu.Lock()
|
||||
if statCache.m != nil {
|
||||
delete(statCache.m, name)
|
||||
}
|
||||
statCache.mu.Unlock()
|
||||
}
|
||||
|
||||
func file(name string) (fuse.Node, fuse.Error) {
|
||||
fi, err := stat(name)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "no such entity") {
|
||||
return nil, fuse.ENOENT
|
||||
}
|
||||
if *z.Debug {
|
||||
log.Printf("stat %s: %v", name, err)
|
||||
}
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
return &File{name, fi, nil}, nil
|
||||
}
|
||||
|
||||
func (f *File) Attr() (attr fuse.Attr) {
|
||||
fi := f.FileInfo
|
||||
attr.Mode = 0666
|
||||
if fi.IsDir {
|
||||
attr.Mode |= 0111 | os.ModeDir
|
||||
}
|
||||
attr.Mtime = fi.ModTime
|
||||
attr.Size = uint64(fi.Size)
|
||||
return
|
||||
}
|
||||
|
||||
func (f *File) Lookup(name string, intr fuse.Intr) (fuse.Node, fuse.Error) {
|
||||
return file(path.Join(f.Name, name))
|
||||
}
|
||||
|
||||
func (f *File) ReadAll(intr fuse.Intr) ([]byte, fuse.Error) {
|
||||
data, err := cl.Read(f.Name)
|
||||
if err != nil {
|
||||
log.Printf("read %s: %v", f.Name, err)
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (f *File) ReadDir(intr fuse.Intr) ([]fuse.Dirent, fuse.Error) {
|
||||
fis, err := cl.ReadDir(f.Name)
|
||||
if err != nil {
|
||||
log.Printf("read %s: %v", f.Name, err)
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
var dirs []fuse.Dirent
|
||||
for _, fi := range fis {
|
||||
saveStat(path.Join(f.Name, fi.Name), fi, nil)
|
||||
dirs = append(dirs, fuse.Dirent{Name: fi.Name})
|
||||
}
|
||||
return dirs, nil
|
||||
}
|
||||
|
||||
func (f *File) WriteAll(data []byte, intr fuse.Intr) fuse.Error {
|
||||
defer delStat(f.Name)
|
||||
if err := cl.Write(f.Name[1:], data); err != nil {
|
||||
log.Printf("write %s: %v", f.Name, err)
|
||||
return fuse.EIO
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) Mkdir(req *fuse.MkdirRequest, intr fuse.Intr) (fuse.Node, fuse.Error) {
|
||||
defer delStat(f.Name)
|
||||
p := path.Join(f.Name, req.Name)
|
||||
if err := cl.Create(p[1:], true); err != nil {
|
||||
log.Printf("mkdir %s: %v", p, err)
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
delStat(p)
|
||||
return file(p)
|
||||
}
|
||||
|
||||
func (f *File) Create(req *fuse.CreateRequest, resp *fuse.CreateResponse, intr fuse.Intr) (fuse.Node, fuse.Handle, fuse.Error) {
|
||||
defer delStat(f.Name)
|
||||
p := path.Join(f.Name, req.Name)
|
||||
if err := cl.Create(p[1:], false); err != nil {
|
||||
log.Printf("create %s: %v", p, err)
|
||||
return nil, nil, fuse.EIO
|
||||
}
|
||||
delStat(p)
|
||||
n, err := file(p)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return n, n, nil
|
||||
}
|
||||
150
vendor/github.com/mattermost/rsc/appfs/client/client.go
сгенерированный
поставляемый
150
vendor/github.com/mattermost/rsc/appfs/client/client.go
сгенерированный
поставляемый
@@ -1,150 +0,0 @@
|
||||
// Copyright 2012 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 client implements a basic appfs client.
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/rsc/appfs/proto"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
Host string
|
||||
User string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (c *Client) url(op, path string) string {
|
||||
scheme := "https"
|
||||
if strings.HasPrefix(c.Host, "localhost:") {
|
||||
scheme = "http"
|
||||
}
|
||||
if strings.HasSuffix(op, "/") && strings.HasPrefix(path, "/") {
|
||||
path = path[1:]
|
||||
}
|
||||
return scheme + "://"+ c.User + ":" + c.Password + "@" + c.Host + op + path
|
||||
}
|
||||
|
||||
func (c *Client) do(u string) error {
|
||||
_, err := c.get(u)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) get(u string) ([]byte, error) {
|
||||
tries := 0
|
||||
for {
|
||||
r, err := http.Get(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != 200 {
|
||||
if r.StatusCode == 500 {
|
||||
if tries++; tries < 3 {
|
||||
fmt.Printf("%s %s; sleeping\n", r.Status, data)
|
||||
time.Sleep(5*time.Second)
|
||||
continue
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("%s %s", r.Status, data)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (c *Client) post(u string, data []byte) ([]byte, error) {
|
||||
tries := 0
|
||||
for {
|
||||
r, err := http.Post(u, proto.PostContentType, bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
rdata, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.StatusCode != 200 {
|
||||
if r.StatusCode == 500 {
|
||||
if tries++; tries < 3 {
|
||||
fmt.Printf("%s %s; sleeping\n", r.Status, rdata)
|
||||
time.Sleep(5*time.Second)
|
||||
continue
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("%s %s", r.Status, rdata)
|
||||
}
|
||||
return rdata, nil
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func (c *Client) Create(path string, isdir bool) error {
|
||||
u := c.url(proto.CreateURL, path)
|
||||
if isdir {
|
||||
u += "?dir=1"
|
||||
}
|
||||
return c.do(u)
|
||||
}
|
||||
|
||||
func (c *Client) Read(path string) ([]byte, error) {
|
||||
return c.get(c.url(proto.ReadURL, path))
|
||||
}
|
||||
|
||||
func (c *Client) Write(path string, data []byte) error {
|
||||
u := c.url(proto.WriteURL, path)
|
||||
_, err := c.post(u, data)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) Mkfs() error {
|
||||
return c.do(c.url(proto.MkfsURL, ""))
|
||||
}
|
||||
|
||||
func (c *Client) Stat(path string) (*proto.FileInfo, error) {
|
||||
data, err := c.get(c.url(proto.StatURL, path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var fi proto.FileInfo
|
||||
if err := json.Unmarshal(data, &fi); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fi, nil
|
||||
}
|
||||
|
||||
func (c *Client) ReadDir(path string) ([]*proto.FileInfo, error) {
|
||||
data, err := c.Read(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dec := json.NewDecoder(bytes.NewBuffer(data))
|
||||
var out []*proto.FileInfo
|
||||
for {
|
||||
var fi proto.FileInfo
|
||||
err := dec.Decode(&fi)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
out = append(out, &fi)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
273
vendor/github.com/mattermost/rsc/appfs/fs/fs.go
сгенерированный
поставляемый
273
vendor/github.com/mattermost/rsc/appfs/fs/fs.go
сгенерированный
поставляемый
@@ -1,273 +0,0 @@
|
||||
// Copyright 2012 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 fs is an indirection layer, allowing code to use a
|
||||
// file system without knowing whether it is the host file system
|
||||
// (running without App Engine) or the datastore-based app
|
||||
// file system (running on App Engine).
|
||||
//
|
||||
// When compiled locally, fs refers to files in the local file system,
|
||||
// and the cache saves nothing.
|
||||
//
|
||||
// When compiled for App Engine, fs uses the appfs file system
|
||||
// and the memcache-based cache.
|
||||
package fs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/rsc/appfs/proto"
|
||||
)
|
||||
|
||||
type AppEngine interface {
|
||||
NewContext(req *http.Request) interface{}
|
||||
CacheRead(ctxt interface{}, name, path string) (key interface{}, data []byte, found bool)
|
||||
CacheWrite(ctxt, key interface{}, data []byte)
|
||||
Read(ctxt interface{}, path string) ([]byte, *proto.FileInfo, error)
|
||||
Write(ctxt interface{}, path string, data []byte) error
|
||||
Remove(ctxt interface{}, path string) error
|
||||
Mkdir(ctxt interface{}, path string) error
|
||||
ReadDir(ctxt interface{}, path string) ([]proto.FileInfo, error)
|
||||
Criticalf(ctxt interface{}, format string, args ...interface{})
|
||||
User(ctxt interface{}) string
|
||||
}
|
||||
|
||||
var ae AppEngine
|
||||
|
||||
func Register(impl AppEngine) {
|
||||
ae = impl
|
||||
}
|
||||
|
||||
// Root is the root of the local file system. It has no effect on App Engine.
|
||||
var Root = "."
|
||||
|
||||
// A Context is an opaque context that is needed to perform file system
|
||||
// operations. Each context is associated with a single HTTP request.
|
||||
type Context struct {
|
||||
context
|
||||
ae interface{}
|
||||
}
|
||||
|
||||
// NewContext returns a context associated with the given HTTP request.
|
||||
func NewContext(req *http.Request) *Context {
|
||||
if ae != nil {
|
||||
ctxt := ae.NewContext(req)
|
||||
return &Context{ae: ctxt}
|
||||
}
|
||||
return newContext(req)
|
||||
}
|
||||
|
||||
// A CacheKey is an opaque cache key that can be used to store new entries
|
||||
// in the cache. To ensure that the cache remains consistent with the underlying
|
||||
// file system, the correct procedure is:
|
||||
//
|
||||
// 1. Use CacheRead (or CacheLoad) to attempt to load the entry. If it succeeds, use it.
|
||||
// If not, continue, saving the CacheKey.
|
||||
//
|
||||
// 2. Read from the file system and construct the entry that would have
|
||||
// been in the cache. In order to be consistent, all the file system reads
|
||||
// should only refer to parts of the file system in the tree rooted at the path
|
||||
// passed to CacheRead.
|
||||
//
|
||||
// 3. Save the entry using CacheWrite (or CacheStore), using the key that was
|
||||
// created by the CacheRead (or CacheLoad) executed before reading from the
|
||||
// file system.
|
||||
//
|
||||
type CacheKey struct {
|
||||
cacheKey
|
||||
ae interface{}
|
||||
}
|
||||
|
||||
// CacheRead reads from cache the entry with the given name and path.
|
||||
// The path specifies the scope of information stored in the cache entry.
|
||||
// An entry is invalidated by a write to any location in the file tree rooted at path.
|
||||
// The name is an uninterpreted identifier to distinguish the cache entry
|
||||
// from other entries using the same path.
|
||||
//
|
||||
// If it finds a cache entry, CacheRead returns the data and found=true.
|
||||
// If it does not find a cache entry, CacheRead returns data=nil and found=false.
|
||||
// Either way, CacheRead returns an appropriate cache key for storing to the
|
||||
// cache entry using CacheWrite.
|
||||
func (c *Context) CacheRead(name, path string) (ckey CacheKey, data []byte, found bool) {
|
||||
if ae != nil {
|
||||
key, data, found := ae.CacheRead(c.ae, name, path)
|
||||
return CacheKey{ae: key}, data, found
|
||||
}
|
||||
return c.cacheRead(ckey, path)
|
||||
}
|
||||
|
||||
// CacheLoad uses CacheRead to load gob-encoded data and decodes it into value.
|
||||
func (c *Context) CacheLoad(name, path string, value interface{}) (ckey CacheKey, found bool) {
|
||||
ckey, data, found := c.CacheRead(name, path)
|
||||
if found {
|
||||
if err := gob.NewDecoder(bytes.NewBuffer(data)).Decode(value); err != nil {
|
||||
c.Criticalf("gob Decode: %v", err)
|
||||
found = false
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CacheWrite writes an entry to the cache with the given key, path, and data.
|
||||
// The cache entry will be invalidated the next time the file tree rooted at path is
|
||||
// modified in anyway.
|
||||
func (c *Context) CacheWrite(ckey CacheKey, data []byte) {
|
||||
if ae != nil {
|
||||
ae.CacheWrite(c.ae, ckey.ae, data)
|
||||
return
|
||||
}
|
||||
c.cacheWrite(ckey, data)
|
||||
}
|
||||
|
||||
// CacheStore uses CacheWrite to save the gob-encoded form of value.
|
||||
func (c *Context) CacheStore(ckey CacheKey, value interface{}) {
|
||||
var buf bytes.Buffer
|
||||
if err := gob.NewEncoder(&buf).Encode(value); err != nil {
|
||||
c.Criticalf("gob Encode: %v", err)
|
||||
return
|
||||
}
|
||||
c.CacheWrite(ckey, buf.Bytes())
|
||||
}
|
||||
|
||||
// Read returns the data associated with the file named by path.
|
||||
// It is a copy and can be modified without affecting the file.
|
||||
func (c *Context) Read(path string) ([]byte, *proto.FileInfo, error) {
|
||||
if ae != nil {
|
||||
return ae.Read(c.ae, path)
|
||||
}
|
||||
return c.read(path)
|
||||
}
|
||||
|
||||
// Write replaces the data associated with the file named by path.
|
||||
func (c *Context) Write(path string, data []byte) error {
|
||||
if ae != nil {
|
||||
return ae.Write(c.ae, path, data)
|
||||
}
|
||||
return c.write(path, data)
|
||||
}
|
||||
|
||||
// Remove removes the file named by path.
|
||||
func (c *Context) Remove(path string) error {
|
||||
if ae != nil {
|
||||
return ae.Remove(c.ae, path)
|
||||
}
|
||||
return c.remove(path)
|
||||
}
|
||||
|
||||
// Mkdir creates a directory with the given path.
|
||||
// If the path already exists and is a directory, Mkdir returns no error.
|
||||
func (c *Context) Mkdir(path string) error {
|
||||
if ae != nil {
|
||||
return ae.Mkdir(c.ae, path)
|
||||
}
|
||||
return c.mkdir(path)
|
||||
}
|
||||
|
||||
// ReadDir returns the contents of the directory named by the path.
|
||||
func (c *Context) ReadDir(path string) ([]proto.FileInfo, error) {
|
||||
if ae != nil {
|
||||
return ae.ReadDir(c.ae, path)
|
||||
}
|
||||
return c.readdir(path)
|
||||
}
|
||||
|
||||
// ServeFile serves the named file as the response to the HTTP request.
|
||||
func (c *Context) ServeFile(w http.ResponseWriter, req *http.Request, name string) {
|
||||
root := &httpFS{c, name}
|
||||
http.FileServer(root).ServeHTTP(w, req)
|
||||
}
|
||||
|
||||
// Criticalf logs the message at critical priority.
|
||||
func (c *Context) Criticalf(format string, args ...interface{}) {
|
||||
if ae != nil {
|
||||
ae.Criticalf(c.ae, format, args...)
|
||||
}
|
||||
log.Printf(format, args...)
|
||||
}
|
||||
|
||||
// User returns the name of the user running the request.
|
||||
func (c *Context) User() string {
|
||||
if ae != nil {
|
||||
return ae.User(c.ae)
|
||||
}
|
||||
return os.Getenv("USER")
|
||||
}
|
||||
|
||||
type httpFS struct {
|
||||
c *Context
|
||||
name string
|
||||
}
|
||||
|
||||
type httpFile struct {
|
||||
data []byte
|
||||
fi *proto.FileInfo
|
||||
off int
|
||||
}
|
||||
|
||||
func (h *httpFS) Open(_ string) (http.File, error) {
|
||||
data, fi, err := h.c.Read(h.name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &httpFile{data, fi, 0}, nil
|
||||
}
|
||||
|
||||
func (f *httpFile) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type fileInfo struct {
|
||||
p *proto.FileInfo
|
||||
}
|
||||
|
||||
func (f *fileInfo) IsDir() bool { return f.p.IsDir }
|
||||
func (f *fileInfo) Name() string { return f.p.Name }
|
||||
func (f *fileInfo) ModTime() time.Time { return f.p.ModTime }
|
||||
func (f *fileInfo) Size() int64 { return f.p.Size }
|
||||
func (f *fileInfo) Sys() interface{} { return f.p }
|
||||
func (f *fileInfo) Mode() os.FileMode {
|
||||
if f.p.IsDir {
|
||||
return os.ModeDir | 0777
|
||||
}
|
||||
return 0666
|
||||
}
|
||||
|
||||
func (f *httpFile) Stat() (os.FileInfo, error) {
|
||||
return &fileInfo{f.fi}, nil
|
||||
}
|
||||
|
||||
func (f *httpFile) Readdir(count int) ([]os.FileInfo, error) {
|
||||
return nil, fmt.Errorf("no directory")
|
||||
}
|
||||
|
||||
func (f *httpFile) Read(data []byte) (int, error) {
|
||||
if f.off >= len(f.data) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
n := copy(data, f.data[f.off:])
|
||||
f.off += n
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (f *httpFile) Seek(offset int64, whence int) (int64, error) {
|
||||
off := int(offset)
|
||||
if int64(off) != offset {
|
||||
return 0, fmt.Errorf("invalid offset")
|
||||
}
|
||||
switch whence {
|
||||
case 1:
|
||||
off += f.off
|
||||
case 2:
|
||||
off += len(f.data)
|
||||
}
|
||||
f.off = off
|
||||
return int64(off), nil
|
||||
}
|
||||
82
vendor/github.com/mattermost/rsc/appfs/fs/local.go
сгенерированный
поставляемый
82
vendor/github.com/mattermost/rsc/appfs/fs/local.go
сгенерированный
поставляемый
@@ -1,82 +0,0 @@
|
||||
// Copyright 2012 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 fs
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mattermost/rsc/appfs/proto"
|
||||
)
|
||||
|
||||
type context struct{}
|
||||
|
||||
type cacheKey struct{}
|
||||
|
||||
func newContext(req *http.Request) *Context {
|
||||
return &Context{}
|
||||
}
|
||||
|
||||
func (*context) cacheRead(ckey CacheKey, path string) (CacheKey, []byte, bool) {
|
||||
return ckey, nil, false
|
||||
}
|
||||
|
||||
func (*context) cacheWrite(ckey CacheKey, data []byte) {
|
||||
}
|
||||
|
||||
func (*context) read(path string) ([]byte, *proto.FileInfo, error) {
|
||||
p := filepath.Join(Root, path)
|
||||
dir, err := os.Stat(p)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
fi := &proto.FileInfo{
|
||||
Name: dir.Name(),
|
||||
ModTime: dir.ModTime(),
|
||||
Size: dir.Size(),
|
||||
IsDir: dir.IsDir(),
|
||||
}
|
||||
data, err := ioutil.ReadFile(p)
|
||||
return data, fi, err
|
||||
}
|
||||
|
||||
func (*context) write(path string, data []byte) error {
|
||||
p := filepath.Join(Root, path)
|
||||
return ioutil.WriteFile(p, data, 0666)
|
||||
}
|
||||
|
||||
func (*context) remove(path string) error {
|
||||
p := filepath.Join(Root, path)
|
||||
return os.Remove(p)
|
||||
}
|
||||
|
||||
func (*context) mkdir(path string) error {
|
||||
p := filepath.Join(Root, path)
|
||||
fi, err := os.Stat(p)
|
||||
if err == nil && fi.IsDir() {
|
||||
return nil
|
||||
}
|
||||
return os.Mkdir(p, 0777)
|
||||
}
|
||||
|
||||
func (*context) readdir(path string) ([]proto.FileInfo, error) {
|
||||
p := filepath.Join(Root, path)
|
||||
dirs, err := ioutil.ReadDir(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []proto.FileInfo
|
||||
for _, dir := range dirs {
|
||||
out = append(out, proto.FileInfo{
|
||||
Name: dir.Name(),
|
||||
ModTime: dir.ModTime(),
|
||||
Size: dir.Size(),
|
||||
IsDir: dir.IsDir(),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
55
vendor/github.com/mattermost/rsc/appfs/proto/data.go
сгенерированный
поставляемый
55
vendor/github.com/mattermost/rsc/appfs/proto/data.go
сгенерированный
поставляемый
@@ -1,55 +0,0 @@
|
||||
// Copyright 2012 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 proto defines the protocol between appfs client and server.
|
||||
package proto
|
||||
|
||||
import "time"
|
||||
|
||||
// An Auth appears, JSON-encoded, as the X-Appfs-Auth header line,
|
||||
// to authenticate a request made to the file server.
|
||||
// The authentication scheme could be made more sophisticated, but since
|
||||
// we are already forcing the use of TLS, a plain password is fine for now.
|
||||
type Auth struct {
|
||||
Password string
|
||||
}
|
||||
|
||||
// GET /.appfs/stat/path returns the metadata for a file or directory,
|
||||
// a JSON-encoded FileInfo.
|
||||
const StatURL = "/.appfs/stat/"
|
||||
|
||||
// GET /.appfs/read/path returns the content of the file or directory.
|
||||
// The body of the response is the raw file or directory content.
|
||||
// The content of a directory is a sequence of JSON-encoded FileInfo.
|
||||
const ReadURL = "/.appfs/read/"
|
||||
|
||||
// POST to /.appfs/write/path writes new data to a file.
|
||||
// The X-Appfs-SHA1 header is the SHA1 hash of the data.
|
||||
// The body of the request is the raw file content.
|
||||
const WriteURL = "/.appfs/write/"
|
||||
|
||||
// POST to /.appfs/mount initializes the file system if it does not
|
||||
// yet exist in the datastore.
|
||||
const MkfsURL = "/.appfs/mkfs"
|
||||
|
||||
// POST to /.appfs/create/path creates a new file or directory.
|
||||
// The named path must not already exist; its parent must exist.
|
||||
// The query parameter dir=1 indicates that a directory should be created.
|
||||
const CreateURL = "/.appfs/create/"
|
||||
|
||||
// POST to /.appfs/remove/path removes the file or directory.
|
||||
// A directory must be empty to be removed.
|
||||
const RemoveURL = "/.appfs/remove/"
|
||||
|
||||
// A FileInfo is a directory entry.
|
||||
type FileInfo struct {
|
||||
Name string // final path element
|
||||
ModTime time.Time
|
||||
Size int64
|
||||
IsDir bool
|
||||
}
|
||||
|
||||
// PostContentType is the Content-Type for POSTed data.
|
||||
// There is no encoding or framing: it is just raw data bytes.
|
||||
const PostContentType = "x-appfs/raw"
|
||||
982
vendor/github.com/mattermost/rsc/appfs/server/app.go
сгенерированный
поставляемый
982
vendor/github.com/mattermost/rsc/appfs/server/app.go
сгенерированный
поставляемый
@@ -1,982 +0,0 @@
|
||||
// Copyright 2012 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 server implements an appfs server backed by the
|
||||
// App Engine datastore.
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"appengine"
|
||||
"appengine/datastore"
|
||||
"appengine/memcache"
|
||||
"appengine/user"
|
||||
|
||||
"github.com/mattermost/rsc/appfs/fs"
|
||||
"github.com/mattermost/rsc/appfs/proto"
|
||||
)
|
||||
|
||||
const pwFile = "/.password"
|
||||
var chatty = false
|
||||
|
||||
func init() {
|
||||
handle(proto.ReadURL, (*request).read)
|
||||
handle(proto.WriteURL, (*request).write)
|
||||
handle(proto.StatURL, (*request).stat)
|
||||
handle(proto.MkfsURL, (*request).mkfs)
|
||||
handle(proto.CreateURL, (*request).create)
|
||||
handle(proto.RemoveURL, (*request).remove)
|
||||
}
|
||||
|
||||
type request struct {
|
||||
w http.ResponseWriter
|
||||
req *http.Request
|
||||
c appengine.Context
|
||||
name string
|
||||
mname string
|
||||
key *datastore.Key
|
||||
}
|
||||
|
||||
func auth(r *request) bool {
|
||||
hdr := r.req.Header.Get("Authorization")
|
||||
if !strings.HasPrefix(hdr, "Basic ") {
|
||||
return false
|
||||
}
|
||||
data, err := base64.StdEncoding.DecodeString(hdr[6:])
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
i := bytes.IndexByte(data, ':')
|
||||
if i < 0 {
|
||||
return false
|
||||
}
|
||||
user, passwd := string(data[:i]), string(data[i+1:])
|
||||
|
||||
_, data, err = read(r.c, pwFile)
|
||||
if err != nil {
|
||||
r.c.Errorf("reading %s: %v", pwFile, err)
|
||||
if _, err := mkfs(r.c); err != nil {
|
||||
r.c.Errorf("creating fs: %v", err)
|
||||
}
|
||||
_, data, err = read(r.c, pwFile)
|
||||
if err != nil {
|
||||
r.c.Errorf("reading %s again: %v", pwFile, err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
lines := strings.Split(string(data), "\n")
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
f := strings.Fields(line)
|
||||
if len(f) < 3 {
|
||||
continue
|
||||
}
|
||||
if f[0] == user {
|
||||
return hash(f[1]+passwd) == f[2]
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func hash(s string) string {
|
||||
h := sha1.New()
|
||||
h.Write([]byte(s))
|
||||
return fmt.Sprintf("%x", h.Sum(nil))
|
||||
}
|
||||
|
||||
func handle(prefix string, f func(*request)) {
|
||||
http.HandleFunc(prefix, func(w http.ResponseWriter, req *http.Request) {
|
||||
c := appengine.NewContext(req)
|
||||
r := &request{
|
||||
w: w,
|
||||
req: req,
|
||||
c: c,
|
||||
}
|
||||
|
||||
if strings.HasSuffix(prefix, "/") {
|
||||
r.name, r.mname, r.key = mangle(c, req.URL.Path[len(prefix)-1:])
|
||||
} else {
|
||||
req.URL.Path = "/"
|
||||
}
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
fmt.Fprintf(w, "%s\n", err)
|
||||
}
|
||||
}()
|
||||
|
||||
if !auth(r) {
|
||||
w.Header().Set("WWW-Authenticate", "Basic realm=\"appfs\"")
|
||||
http.Error(w, "Need auth", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
f(r)
|
||||
})
|
||||
}
|
||||
|
||||
func mangle(c appengine.Context, name string) (string, string, *datastore.Key) {
|
||||
name = path.Clean("/" + name)
|
||||
n := strings.Count(name, "/")
|
||||
if name == "/" {
|
||||
n = 0
|
||||
}
|
||||
mname := fmt.Sprintf("%d%s", n, name)
|
||||
root := datastore.NewKey(c, "RootKey", "v2:", 0, nil)
|
||||
key := datastore.NewKey(c, "FileInfo", mname, 0, root)
|
||||
return name, mname, key
|
||||
}
|
||||
|
||||
type FileInfo struct {
|
||||
Path string // mangled path
|
||||
Name string
|
||||
Qid int64 // assigned unique id number
|
||||
Seq int64 // modification sequence number in file tree
|
||||
ModTime time.Time
|
||||
Size int64
|
||||
IsDir bool
|
||||
}
|
||||
|
||||
type FileData struct {
|
||||
Data []byte
|
||||
}
|
||||
|
||||
func stat(c appengine.Context, name string) (*FileInfo, error) {
|
||||
var fi FileInfo
|
||||
name, _, key := mangle(c, name)
|
||||
c.Infof("DATASTORE Stat %q", name)
|
||||
err := datastore.Get(c, key, &fi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fi, nil
|
||||
}
|
||||
|
||||
func (r *request) saveStat(fi *FileInfo) {
|
||||
jfi, err := json.Marshal(&fi)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
r.w.Header().Set("X-Appfs-Stat", string(jfi))
|
||||
}
|
||||
|
||||
func (r *request) tx(f func(c appengine.Context) error) {
|
||||
err := datastore.RunInTransaction(r.c, f, &datastore.TransactionOptions{XG: true})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *request) stat() {
|
||||
var fi *FileInfo
|
||||
r.tx(func(c appengine.Context) error {
|
||||
fi1, err := stat(c, r.name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fi = fi1
|
||||
return nil
|
||||
})
|
||||
|
||||
jfi, err := json.Marshal(&fi)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
r.w.Write(jfi)
|
||||
}
|
||||
|
||||
func read(c appengine.Context, name string) (fi *FileInfo, data []byte, err error) {
|
||||
name, _, _ = mangle(c, name)
|
||||
fi1, err := stat(c, name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if fi1.IsDir {
|
||||
dt, err := readdir(c, name)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
fi = fi1
|
||||
data = dt
|
||||
return fi, data, nil
|
||||
}
|
||||
|
||||
root := datastore.NewKey(c, "RootKey", "v2:", 0, nil)
|
||||
dkey := datastore.NewKey(c, "FileData", "", fi1.Qid, root)
|
||||
var fd FileData
|
||||
c.Infof("DATASTORE Read %q", name)
|
||||
if err := datastore.Get(c, dkey, &fd); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
fi = fi1
|
||||
data = fd.Data
|
||||
return fi, data, nil
|
||||
}
|
||||
|
||||
func (r *request) read() {
|
||||
var (
|
||||
fi *FileInfo
|
||||
data []byte
|
||||
)
|
||||
r.tx(func(c appengine.Context) error {
|
||||
var err error
|
||||
fi, data, err = read(r.c, r.name)
|
||||
return err
|
||||
})
|
||||
r.saveStat(fi)
|
||||
r.w.Write(data)
|
||||
}
|
||||
|
||||
func readdir(c appengine.Context, name string) ([]byte, error) {
|
||||
name, _, _ = mangle(c, name)
|
||||
var buf bytes.Buffer
|
||||
|
||||
n := strings.Count(name, "/")
|
||||
if name == "/" {
|
||||
name = ""
|
||||
n = 0
|
||||
}
|
||||
root := datastore.NewKey(c, "RootKey", "v2:", 0, nil)
|
||||
first := fmt.Sprintf("%d%s/", n+1, name)
|
||||
limit := fmt.Sprintf("%d%s0", n+1, name)
|
||||
c.Infof("DATASTORE ReadDir %q", name)
|
||||
q := datastore.NewQuery("FileInfo").
|
||||
Filter("Path >=", first).
|
||||
Filter("Path <", limit).
|
||||
Ancestor(root)
|
||||
enc := json.NewEncoder(&buf)
|
||||
it := q.Run(c)
|
||||
var fi FileInfo
|
||||
var pfi proto.FileInfo
|
||||
for {
|
||||
fi = FileInfo{}
|
||||
_, err := it.Next(&fi)
|
||||
if err != nil {
|
||||
if err == datastore.Done {
|
||||
break
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
pfi = proto.FileInfo{
|
||||
Name: fi.Name,
|
||||
ModTime: fi.ModTime,
|
||||
Size: fi.Size,
|
||||
IsDir: fi.IsDir,
|
||||
}
|
||||
if err := enc.Encode(&pfi); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func readdirRaw(c appengine.Context, name string) ([]proto.FileInfo, error) {
|
||||
name, _, _ = mangle(c, name)
|
||||
n := strings.Count(name, "/")
|
||||
if name == "/" {
|
||||
name = ""
|
||||
n = 0
|
||||
}
|
||||
root := datastore.NewKey(c, "RootKey", "v2:", 0, nil)
|
||||
first := fmt.Sprintf("%d%s/", n+1, name)
|
||||
limit := fmt.Sprintf("%d%s0", n+1, name)
|
||||
c.Infof("DATASTORE ReadDir %q", name)
|
||||
q := datastore.NewQuery("FileInfo").
|
||||
Filter("Path >=", first).
|
||||
Filter("Path <", limit).
|
||||
Ancestor(root)
|
||||
it := q.Run(c)
|
||||
var fi FileInfo
|
||||
var pfi proto.FileInfo
|
||||
var out []proto.FileInfo
|
||||
for {
|
||||
fi = FileInfo{}
|
||||
_, err := it.Next(&fi)
|
||||
if err != nil {
|
||||
if err == datastore.Done {
|
||||
break
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
pfi = proto.FileInfo{
|
||||
Name: fi.Name,
|
||||
ModTime: fi.ModTime,
|
||||
Size: fi.Size,
|
||||
IsDir: fi.IsDir,
|
||||
}
|
||||
out = append(out, pfi)
|
||||
}
|
||||
println("READDIR", name, len(out))
|
||||
return out, nil
|
||||
}
|
||||
|
||||
|
||||
var initPasswd = `# Password file
|
||||
# This file controls access to the server.
|
||||
# The format is lines of space-separated fields:
|
||||
# user salt pwhash
|
||||
# The pwhash is the SHA1 of the salt string concatenated with the password.
|
||||
|
||||
# user=dummy password=dummy (replace with your own entries)
|
||||
dummy 12345 faa863c7d3d41893f80165c704b714d5e31bdd3b
|
||||
`
|
||||
|
||||
func (r *request) mkfs() {
|
||||
var fi *FileInfo
|
||||
r.tx(func(c appengine.Context) error {
|
||||
var err error
|
||||
fi, err = mkfs(c)
|
||||
return err
|
||||
})
|
||||
r.saveStat(fi)
|
||||
}
|
||||
|
||||
func mkfs(c appengine.Context) (fi *FileInfo, err error) {
|
||||
fi1, err := stat(c, "/")
|
||||
if err == nil {
|
||||
return fi1, nil
|
||||
}
|
||||
|
||||
// Root needs to be created.
|
||||
// Probably root key does too.
|
||||
root := datastore.NewKey(c, "RootKey", "v2:", 0, nil)
|
||||
_, err = datastore.Put(c, root, &struct{}{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("mkfs put root: %s", err)
|
||||
}
|
||||
|
||||
// Entry for /.
|
||||
_, mpath, key := mangle(c, "/")
|
||||
fi3 := FileInfo{
|
||||
Path: mpath,
|
||||
Name: "/",
|
||||
Seq: 2, // 2, not 1, because we're going to write password file with #2
|
||||
Qid: 1,
|
||||
ModTime: time.Now(),
|
||||
Size: 0,
|
||||
IsDir: true,
|
||||
}
|
||||
_, err = datastore.Put(c, key, &fi3)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("mkfs put /: %s", err)
|
||||
}
|
||||
|
||||
/*
|
||||
* Would like to use this code but App Engine apparently
|
||||
* does not let Get observe the effect of a Put in the same
|
||||
* transaction. What planet does that make sense on?
|
||||
* Instead, we have to execute just the datastore writes that this
|
||||
* sequence would.
|
||||
*
|
||||
_, err = create(c, pwFile, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("mkfs create .password: %s", err)
|
||||
}
|
||||
_, err = write(c, pwFile, []byte(initPasswd))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("mkfs write .password: %s", err)
|
||||
}
|
||||
*
|
||||
*/
|
||||
|
||||
{
|
||||
name, mname, key := mangle(c, pwFile)
|
||||
|
||||
// Create data object.
|
||||
dataKey := int64(2)
|
||||
root := datastore.NewKey(c, "RootKey", "v2:", 0, nil)
|
||||
dkey := datastore.NewKey(c, "FileData", "", dataKey, root)
|
||||
_, err := datastore.Put(c, dkey, &FileData{[]byte(initPasswd)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create new directory entry.
|
||||
_, elem := path.Split(name)
|
||||
fi1 = &FileInfo{
|
||||
Path: mname,
|
||||
Name: elem,
|
||||
Qid: 2,
|
||||
Seq: 2,
|
||||
ModTime: time.Now(),
|
||||
Size: int64(len(initPasswd)),
|
||||
IsDir: false,
|
||||
}
|
||||
if _, err := datastore.Put(c, key, fi1); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &fi3, nil
|
||||
}
|
||||
|
||||
func (r *request) write() {
|
||||
data, err := ioutil.ReadAll(r.req.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var fi *FileInfo
|
||||
var seq int64
|
||||
r.tx(func(c appengine.Context) error {
|
||||
var err error
|
||||
fi, seq, err = write(r.c, r.name, data)
|
||||
return err
|
||||
})
|
||||
updateCacheTime(r.c, seq)
|
||||
r.saveStat(fi)
|
||||
}
|
||||
|
||||
func write(c appengine.Context, name string, data []byte) (*FileInfo, int64, error) {
|
||||
name, _, key := mangle(c, name)
|
||||
|
||||
// Check that file exists and is not a directory.
|
||||
fi1, err := stat(c, name)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if fi1.IsDir {
|
||||
return nil, 0, fmt.Errorf("cannot write to directory")
|
||||
}
|
||||
|
||||
// Fetch and increment root sequence number.
|
||||
rfi, err := stat(c, "/")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
rfi.Seq++
|
||||
|
||||
// Write data.
|
||||
root := datastore.NewKey(c, "RootKey", "v2:", 0, nil)
|
||||
dkey := datastore.NewKey(c, "FileData", "", fi1.Qid, root)
|
||||
fd := &FileData{data}
|
||||
if _, err := datastore.Put(c, dkey, fd); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Update directory entry.
|
||||
fi1.Seq = rfi.Seq
|
||||
fi1.Size = int64(len(data))
|
||||
fi1.ModTime = time.Now()
|
||||
if _, err := datastore.Put(c, key, fi1); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Update sequence numbers all the way to the root.
|
||||
if err := updateSeq(c, name, rfi.Seq, 1); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return fi1, rfi.Seq, nil
|
||||
}
|
||||
|
||||
func updateSeq(c appengine.Context, name string, seq int64, skip int) error {
|
||||
p := path.Clean(name)
|
||||
for i := 0; ; i++ {
|
||||
if i >= skip {
|
||||
_, _, key := mangle(c, p)
|
||||
var fi FileInfo
|
||||
if err := datastore.Get(c, key, &fi); err != nil {
|
||||
return err
|
||||
}
|
||||
fi.Seq = seq
|
||||
if _, err := datastore.Put(c, key, &fi); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if p == "/" {
|
||||
break
|
||||
}
|
||||
p, _ = path.Split(p)
|
||||
p = path.Clean(p)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *request) remove() {
|
||||
panic("remove not implemented")
|
||||
}
|
||||
|
||||
func (r *request) create() {
|
||||
var fi *FileInfo
|
||||
var seq int64
|
||||
isDir := r.req.FormValue("dir") == "1"
|
||||
r.tx(func(c appengine.Context) error {
|
||||
var err error
|
||||
fi, seq, err = create(r.c, r.name, isDir, nil)
|
||||
return err
|
||||
})
|
||||
updateCacheTime(r.c, seq)
|
||||
r.saveStat(fi)
|
||||
}
|
||||
|
||||
func create(c appengine.Context, name string, isDir bool, data []byte) (*FileInfo, int64, error) {
|
||||
name, mname, key := mangle(c, name)
|
||||
|
||||
// File must not exist.
|
||||
fi1, err := stat(c, name)
|
||||
if err == nil {
|
||||
return nil, 0, fmt.Errorf("file already exists")
|
||||
}
|
||||
if err != datastore.ErrNoSuchEntity {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Parent must exist and be a directory.
|
||||
p, _ := path.Split(name)
|
||||
fi2, err := stat(c, p)
|
||||
if err != nil {
|
||||
if err == datastore.ErrNoSuchEntity {
|
||||
return nil, 0, fmt.Errorf("parent directory %q does not exist", p)
|
||||
}
|
||||
return nil, 0, err
|
||||
}
|
||||
if !fi2.IsDir {
|
||||
return nil, 0, fmt.Errorf("parent %q is not a directory", p)
|
||||
}
|
||||
|
||||
// Fetch and increment root sequence number.
|
||||
rfi, err := stat(c, "/")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
rfi.Seq++
|
||||
|
||||
var dataKey int64
|
||||
// Create data object.
|
||||
if !isDir {
|
||||
dataKey = rfi.Seq
|
||||
root := datastore.NewKey(c, "RootKey", "v2:", 0, nil)
|
||||
dkey := datastore.NewKey(c, "FileData", "", dataKey, root)
|
||||
_, err := datastore.Put(c, dkey, &FileData{data})
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
// Create new directory entry.
|
||||
_, elem := path.Split(name)
|
||||
fi1 = &FileInfo{
|
||||
Path: mname,
|
||||
Name: elem,
|
||||
Qid: rfi.Seq,
|
||||
Seq: rfi.Seq,
|
||||
ModTime: time.Now(),
|
||||
Size: int64(len(data)),
|
||||
IsDir: isDir,
|
||||
}
|
||||
if _, err := datastore.Put(c, key, fi1); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Update sequence numbers all the way to root,
|
||||
// but skip entry we just wrote.
|
||||
if err := updateSeq(c, name, rfi.Seq, 1); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return fi1, rfi.Seq, nil
|
||||
}
|
||||
|
||||
// Implementation of fs.AppEngine.
|
||||
|
||||
func init() {
|
||||
fs.Register(ae{})
|
||||
}
|
||||
|
||||
type ae struct{}
|
||||
|
||||
func tx(c interface{}, f func(c appengine.Context) error) error {
|
||||
return datastore.RunInTransaction(c.(appengine.Context), f, &datastore.TransactionOptions{XG: true})
|
||||
}
|
||||
|
||||
func (ae) NewContext(req *http.Request) interface{} {
|
||||
return appengine.NewContext(req)
|
||||
}
|
||||
|
||||
func (ae) User(ctxt interface{}) string {
|
||||
c := ctxt.(appengine.Context)
|
||||
u := user.Current(c)
|
||||
if u == nil {
|
||||
return "?"
|
||||
}
|
||||
return u.String()
|
||||
}
|
||||
|
||||
type cacheKey struct {
|
||||
t int64
|
||||
name string
|
||||
}
|
||||
|
||||
func (ae) CacheRead(ctxt interface{}, name, path string) (key interface{}, data []byte, found bool) {
|
||||
c := ctxt.(appengine.Context)
|
||||
t, data, _, err := cacheRead(c, "cache", name, path)
|
||||
return &cacheKey{t, name}, data, err == nil
|
||||
}
|
||||
|
||||
func (ae) CacheWrite(ctxt, key interface{}, data []byte) {
|
||||
c := ctxt.(appengine.Context)
|
||||
k := key.(*cacheKey)
|
||||
cacheWrite(c, k.t, "cache", k.name, data)
|
||||
}
|
||||
|
||||
func (ae ae) Read(ctxt interface{}, name string) (data []byte, pfi *proto.FileInfo, err error) {
|
||||
c := ctxt.(appengine.Context)
|
||||
name = path.Clean("/"+name)
|
||||
if chatty {
|
||||
c.Infof("AE Read %s", name)
|
||||
}
|
||||
_, data, pfi, err = cacheRead(c, "data", name, name)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ae) Write(ctxt interface{}, path string, data []byte) error {
|
||||
var seq int64
|
||||
err := tx(ctxt, func(c appengine.Context) error {
|
||||
_, err := stat(c, path)
|
||||
if err != nil {
|
||||
_, seq, err = create(c, path, false, data)
|
||||
} else {
|
||||
_, seq, err = write(c, path, data)
|
||||
}
|
||||
return err
|
||||
})
|
||||
if seq != 0 {
|
||||
updateCacheTime(ctxt.(appengine.Context), seq)
|
||||
}
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Write %q: %v", path, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (ae) Remove(ctxt interface{}, path string) error {
|
||||
return fmt.Errorf("remove not implemented")
|
||||
}
|
||||
|
||||
func (ae) Mkdir(ctxt interface{}, path string) error {
|
||||
var seq int64
|
||||
err := tx(ctxt, func(c appengine.Context) error {
|
||||
var err error
|
||||
_, seq, err = create(c, path, true, nil)
|
||||
return err
|
||||
})
|
||||
if seq != 0 {
|
||||
updateCacheTime(ctxt.(appengine.Context), seq)
|
||||
}
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Mkdir %q: %v", path, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (ae) Criticalf(ctxt interface{}, format string, args ...interface{}) {
|
||||
ctxt.(appengine.Context).Criticalf(format, args...)
|
||||
}
|
||||
|
||||
type readDirCacheEntry struct {
|
||||
Dir []proto.FileInfo
|
||||
Error string
|
||||
}
|
||||
|
||||
func (ae) ReadDir(ctxt interface{}, name string) (dir []proto.FileInfo, err error) {
|
||||
c := ctxt.(appengine.Context)
|
||||
name = path.Clean("/"+name)
|
||||
t, data, _, err := cacheRead(c, "dir", name, name)
|
||||
if err == nil {
|
||||
var e readDirCacheEntry
|
||||
if err := json.Unmarshal(data, &e); err == nil {
|
||||
if chatty {
|
||||
c.Infof("cached ReadDir %q", name)
|
||||
}
|
||||
if e.Error != "" {
|
||||
return nil, errors.New(e.Error)
|
||||
}
|
||||
return e.Dir, nil
|
||||
}
|
||||
c.Criticalf("unmarshal cached dir %q: %v", name)
|
||||
}
|
||||
err = tx(ctxt, func(c appengine.Context) error {
|
||||
var err error
|
||||
dir, err = readdirRaw(c, name)
|
||||
return err
|
||||
})
|
||||
var e readDirCacheEntry
|
||||
e.Dir = dir
|
||||
if err != nil {
|
||||
err = fmt.Errorf("ReadDir %q: %v", name, err)
|
||||
e.Error = err.Error()
|
||||
}
|
||||
if data, err := json.Marshal(&e); err != nil {
|
||||
c.Criticalf("json marshal cached dir: %v", err)
|
||||
} else {
|
||||
c.Criticalf("caching dir %q@%d %d bytes", name, t, len(data))
|
||||
cacheWrite(c, t, "dir", name, data)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Caching of file system data.
|
||||
//
|
||||
// The cache stores entries under keys of the form time,space,name,
|
||||
// where time is the time at which the entry is valid for, space is a name
|
||||
// space identifier, and name is an arbitrary name.
|
||||
//
|
||||
// A key of the form t,mtime,path maps to an integer value giving the
|
||||
// modification time of the named path at root time t.
|
||||
// The special key 0,mtime,/ is an integer giving the current time at the root.
|
||||
//
|
||||
// A key of the form t,data,path maps to the content of path at time t.
|
||||
//
|
||||
// Thus, a read from path should first obtain the root time,
|
||||
// then obtain the modification time for the path at that root time
|
||||
// then obtain the data for that path.
|
||||
// t1 = get(0,mtime,/)
|
||||
// t2 = get(t1,mtime,path)
|
||||
// data = get(t2,data,path)
|
||||
//
|
||||
// The API allows clients to cache their own data too, with expiry tied to
|
||||
// the modification time of a particular path (file or directory). To look
|
||||
// up one of those, we use:
|
||||
// t1 = get(0,mtime,/)
|
||||
// t2 = get(t1,mtime,path)
|
||||
// data = get(t2,clientdata,name)
|
||||
//
|
||||
// To store data in the cache, the t1, t2 should be determined before reading
|
||||
// from datastore. Then the data should be saved under t2. This ensures
|
||||
// that if a datastore update happens after the read but before the cache write,
|
||||
// we'll be writing to an entry that will no longer be used (t2).
|
||||
|
||||
const rootMemcacheKey = "0,mtime,/"
|
||||
|
||||
func updateCacheTime(c appengine.Context, seq int64) {
|
||||
const key = rootMemcacheKey
|
||||
bseq := []byte(strconv.FormatInt(seq, 10))
|
||||
for tries := 0; tries < 10; tries++ {
|
||||
item, err := memcache.Get(c, key)
|
||||
if err != nil {
|
||||
c.Infof("memcache.Get %q: %v", key, err)
|
||||
err = memcache.Add(c, &memcache.Item{Key: key, Value: bseq})
|
||||
if err == nil {
|
||||
c.Infof("memcache.Add %q %q ok", key, bseq)
|
||||
return
|
||||
}
|
||||
c.Infof("memcache.Add %q %q: %v", key, bseq, err)
|
||||
}
|
||||
v, err := strconv.ParseInt(string(item.Value), 10, 64)
|
||||
if err != nil {
|
||||
c.Criticalf("memcache.Get %q = %q (%v)", key, item.Value, err)
|
||||
return
|
||||
}
|
||||
if v >= seq {
|
||||
return
|
||||
}
|
||||
item.Value = bseq
|
||||
err = memcache.CompareAndSwap(c, item)
|
||||
if err == nil {
|
||||
c.Infof("memcache.CAS %q %d->%d ok", key, v, seq)
|
||||
return
|
||||
}
|
||||
c.Infof("memcache.CAS %q %d->%d: %v", key, v, seq, err)
|
||||
}
|
||||
c.Criticalf("repeatedly failed to update root key")
|
||||
}
|
||||
|
||||
func cacheTime(c appengine.Context) (t int64, err error) {
|
||||
const key = rootMemcacheKey
|
||||
item, err := memcache.Get(c, key)
|
||||
if err == nil {
|
||||
v, err := strconv.ParseInt(string(item.Value), 10, 64)
|
||||
if err == nil {
|
||||
if chatty {
|
||||
c.Infof("cacheTime %q = %v", key, v)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
c.Criticalf("memcache.Get %q = %q (%v) - deleting", key, item.Value, err)
|
||||
memcache.Delete(c, key)
|
||||
}
|
||||
fi, err := stat(c, "/")
|
||||
if err != nil {
|
||||
c.Criticalf("stat /: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
updateCacheTime(c, fi.Seq)
|
||||
return fi.Seq, nil
|
||||
}
|
||||
|
||||
func cachePathTime(c appengine.Context, path string) (t int64, err error) {
|
||||
t, err = cacheTime(c)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%d,mtime,%s", t, path)
|
||||
item, err := memcache.Get(c, key)
|
||||
if err == nil {
|
||||
v, err := strconv.ParseInt(string(item.Value), 10, 64)
|
||||
if err == nil {
|
||||
if chatty {
|
||||
c.Infof("cachePathTime %q = %v", key, v)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
c.Criticalf("memcache.Get %q = %q (%v) - deleting", key, item.Value, err)
|
||||
memcache.Delete(c, key)
|
||||
}
|
||||
|
||||
var seq int64
|
||||
if fi, err := stat(c, path); err == nil {
|
||||
seq = fi.Seq
|
||||
}
|
||||
|
||||
c.Infof("cachePathTime save %q = %v", key, seq)
|
||||
item = &memcache.Item{Key: key, Value: []byte(strconv.FormatInt(seq, 10))}
|
||||
if err := memcache.Set(c, item); err != nil {
|
||||
c.Criticalf("memcache.Set %q %q: %v", key, item.Value, err)
|
||||
}
|
||||
return seq, nil
|
||||
}
|
||||
|
||||
type statCacheEntry struct {
|
||||
FileInfo *proto.FileInfo
|
||||
Error string
|
||||
}
|
||||
|
||||
func cacheRead(c appengine.Context, kind, name, path string) (mtime int64, data []byte, pfi *proto.FileInfo, err error) {
|
||||
for tries := 0; tries < 10; tries++ {
|
||||
t, err := cachePathTime(c, path)
|
||||
if err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%d,%s,%s", t, kind, name)
|
||||
item, err := memcache.Get(c, key)
|
||||
var data []byte
|
||||
if item != nil {
|
||||
data = item.Value
|
||||
}
|
||||
if err != nil {
|
||||
c.Infof("memcache miss %q %v", key, err)
|
||||
} else if chatty {
|
||||
c.Infof("memcache hit %q (%d bytes)", key, len(data))
|
||||
}
|
||||
if kind != "data" {
|
||||
// Not a file; whatever memcache says is all we have.
|
||||
return t, data, nil, err
|
||||
}
|
||||
|
||||
// Load stat from cache (includes negative entry).
|
||||
statkey := fmt.Sprintf("%d,stat,%s", t, name)
|
||||
var st statCacheEntry
|
||||
_, err = memcache.JSON.Get(c, statkey, &st)
|
||||
if err == nil {
|
||||
if st.Error != "" {
|
||||
if chatty {
|
||||
c.Infof("memcache hit stat error %q %q", statkey, st.Error)
|
||||
}
|
||||
err = errors.New(st.Error)
|
||||
} else {
|
||||
if chatty {
|
||||
c.Infof("memcache hit stat %q", statkey)
|
||||
}
|
||||
}
|
||||
if err != nil || data != nil {
|
||||
return t, data, st.FileInfo, err
|
||||
}
|
||||
}
|
||||
|
||||
// Need stat, or maybe stat+data.
|
||||
var fi *FileInfo
|
||||
if data != nil {
|
||||
c.Infof("stat %q", name)
|
||||
fi, err = stat(c, name)
|
||||
if err == nil && fi.Seq != t {
|
||||
c.Criticalf("loaded %s but found stat %d", key, fi.Seq)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
c.Infof("read %q", name)
|
||||
fi, data, err = read(c, name)
|
||||
if err == nil && fi.Seq != t {
|
||||
c.Infof("loaded %s but found read %d", key, fi.Seq)
|
||||
t = fi.Seq
|
||||
key = fmt.Sprintf("%d,data,%s", t, name)
|
||||
statkey = fmt.Sprintf("%d,stat,%s", t, name)
|
||||
}
|
||||
|
||||
// Save data to memcache.
|
||||
if err == nil {
|
||||
if true || chatty {
|
||||
c.Infof("save data in memcache %q", key)
|
||||
}
|
||||
item := &memcache.Item{Key: key, Value: data}
|
||||
if err := memcache.Set(c, item); err != nil {
|
||||
c.Criticalf("failed to cache %s: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cache stat, including error.
|
||||
st = statCacheEntry{}
|
||||
if fi != nil {
|
||||
st.FileInfo = &proto.FileInfo{
|
||||
Name: fi.Name,
|
||||
ModTime: fi.ModTime,
|
||||
Size: fi.Size,
|
||||
IsDir: fi.IsDir,
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
st.Error = err.Error()
|
||||
// If this is a deadline exceeded, do not cache.
|
||||
if strings.Contains(st.Error, "Canceled") || strings.Contains(st.Error, "Deadline") {
|
||||
return t, data, st.FileInfo, err
|
||||
}
|
||||
}
|
||||
if chatty {
|
||||
c.Infof("save stat in memcache %q", statkey)
|
||||
}
|
||||
if err := memcache.JSON.Set(c, &memcache.Item{Key: statkey, Object: &st}); err != nil {
|
||||
c.Criticalf("failed to cache %s: %v", statkey, err)
|
||||
}
|
||||
|
||||
// Done!
|
||||
return t, data, st.FileInfo, err
|
||||
}
|
||||
|
||||
c.Criticalf("failed repeatedly in cacheRead")
|
||||
return 0, nil, nil, errors.New("cacheRead loop failed")
|
||||
}
|
||||
|
||||
func cacheWrite(c appengine.Context, t int64, kind, name string, data []byte) error {
|
||||
mkey := fmt.Sprintf("%d,%s,%s", t, kind, name)
|
||||
if true || chatty {
|
||||
c.Infof("cacheWrite %s %d bytes", mkey, len(data))
|
||||
}
|
||||
err := memcache.Set(c, &memcache.Item{Key: mkey, Value: data})
|
||||
if err != nil {
|
||||
c.Criticalf("cacheWrite memcache.Set %q: %v", mkey, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
663
vendor/github.com/mattermost/rsc/arq/arq.go
сгенерированный
поставляемый
663
vendor/github.com/mattermost/rsc/arq/arq.go
сгенерированный
поставляемый
@@ -1,663 +0,0 @@
|
||||
// Copyright 2012 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 arq implements read-only access to Arq backups stored on S3.
|
||||
// Arq is a Mac backup tool (http://www.haystacksoftware.com/arq/)
|
||||
// but the package can read the backups regardless of operating system.
|
||||
package arq
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/rsc/plist"
|
||||
"launchpad.net/goamz/aws"
|
||||
"launchpad.net/goamz/s3"
|
||||
)
|
||||
|
||||
// A Conn represents a connection to an S3 server holding Arq backups.
|
||||
type Conn struct {
|
||||
b *s3.Bucket
|
||||
cache string
|
||||
altCache string
|
||||
}
|
||||
|
||||
// cachedir returns the canonical directory in which to cache data.
|
||||
func cachedir() string {
|
||||
if runtime.GOOS == "darwin" {
|
||||
return filepath.Join(os.Getenv("HOME"), "Library/Caches/arq-cache")
|
||||
}
|
||||
return filepath.Join(os.Getenv("HOME"), ".cache/arq-cache")
|
||||
}
|
||||
|
||||
// Dial establishes a connection to an S3 server holding Arq backups.
|
||||
func Dial(auth aws.Auth) (*Conn, error) {
|
||||
buck := fmt.Sprintf("%s-com-haystacksoftware-arq", strings.ToLower(auth.AccessKey))
|
||||
b := s3.New(auth, aws.USEast).Bucket(buck)
|
||||
c := &Conn{
|
||||
b: b,
|
||||
cache: filepath.Join(cachedir(), buck),
|
||||
}
|
||||
if runtime.GOOS == "darwin" {
|
||||
c.altCache = filepath.Join(os.Getenv("HOME"), "Library/Arq/Cache.noindex/"+buck)
|
||||
}
|
||||
|
||||
// Check that the bucket works by listing computers (relatively cheap).
|
||||
if _, err := c.list("", "/", 10); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create S3 lookaside cache directory.
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *Conn) list(prefix, delim string, max int) (*s3.ListResp, error) {
|
||||
resp, err := c.b.List(prefix, delim, "", max)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := resp
|
||||
for max == 0 && resp.IsTruncated {
|
||||
last := resp.Contents[len(resp.Contents)-1].Key
|
||||
resp, err = c.b.List(prefix, delim, last, max)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
ret.Contents = append(ret.Contents, resp.Contents...)
|
||||
ret.CommonPrefixes = append(ret.CommonPrefixes, resp.CommonPrefixes...)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (c *Conn) altCachePath(name string) string {
|
||||
if c.altCache == "" || !strings.Contains(name, "/packsets/") {
|
||||
return ""
|
||||
}
|
||||
i := strings.Index(name, "-trees/")
|
||||
if i < 0 {
|
||||
i = strings.Index(name, "-blobs/")
|
||||
if i < 0 {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
i += len("-trees/") + 2
|
||||
if i >= len(name) {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(c.altCache, name[:i]+"/"+name[i:])
|
||||
}
|
||||
|
||||
func (c *Conn) cget(name string) (data []byte, err error) {
|
||||
cache := filepath.Join(c.cache, name)
|
||||
f, err := os.Open(cache)
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
return ioutil.ReadAll(f)
|
||||
}
|
||||
if altCache := c.altCachePath(name); altCache != "" {
|
||||
f, err := os.Open(altCache)
|
||||
if err == nil {
|
||||
defer f.Close()
|
||||
return ioutil.ReadAll(f)
|
||||
}
|
||||
}
|
||||
|
||||
data, err = c.bget(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dir, _ := filepath.Split(cache)
|
||||
os.MkdirAll(dir, 0700)
|
||||
ioutil.WriteFile(cache, data, 0600)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (c *Conn) bget(name string) (data []byte, err error) {
|
||||
for i := 0; ; {
|
||||
data, err = c.b.Get(name)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if i++; i >= 5 {
|
||||
return nil, err
|
||||
}
|
||||
log.Print(err)
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (c *Conn) DeleteCache() {
|
||||
os.RemoveAll(c.cache)
|
||||
}
|
||||
|
||||
// Computers returns a list of the computers with backups available on the S3 server.
|
||||
func (c *Conn) Computers() ([]*Computer, error) {
|
||||
// Each backup is a top-level directory with a computerinfo file in it.
|
||||
list, err := c.list("", "/", 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []*Computer
|
||||
for _, p := range list.CommonPrefixes {
|
||||
data, err := c.bget(p + "computerinfo")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var info computerInfo
|
||||
if err := plist.Unmarshal(data, &info); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
comp := &Computer{
|
||||
Name: info.ComputerName,
|
||||
User: info.UserName,
|
||||
UUID: p[:len(p)-1],
|
||||
conn: c,
|
||||
index: map[score]ientry{},
|
||||
}
|
||||
|
||||
salt, err := c.cget(p + "salt")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
comp.crypto.salt = salt
|
||||
|
||||
out = append(out, comp)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// A Computer represents a computer with backups (Folders).
|
||||
type Computer struct {
|
||||
Name string // name of computer
|
||||
User string // name of user
|
||||
UUID string
|
||||
conn *Conn
|
||||
crypto cryptoState
|
||||
index map[score]ientry
|
||||
}
|
||||
|
||||
// Folders returns a list of the folders that have been backed up on the computer.
|
||||
func (c *Computer) Folders() ([]*Folder, error) {
|
||||
// Each folder is a file under computer/buckets/.
|
||||
list, err := c.conn.list(c.UUID+"/buckets/", "", 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []*Folder
|
||||
for _, obj := range list.Contents {
|
||||
data, err := c.conn.bget(obj.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var info folderInfo
|
||||
if err := plist.Unmarshal(data, &info); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, &Folder{
|
||||
Path: info.LocalPath,
|
||||
uuid: info.BucketUUID,
|
||||
comp: c,
|
||||
conn: c.conn,
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Unlock records the password to use when decrypting
|
||||
// backups from this computer. It must be called before calling Trees
|
||||
// in any folder obtained for this computer.
|
||||
func (c *Computer) Unlock(pw string) {
|
||||
c.crypto.unlock(pw)
|
||||
}
|
||||
|
||||
func (c *Computer) scget(sc score) ([]byte, error) {
|
||||
if c.crypto.c == nil {
|
||||
return nil, fmt.Errorf("computer not yet unlocked")
|
||||
}
|
||||
|
||||
var data []byte
|
||||
var err error
|
||||
ie, ok := c.index[sc]
|
||||
if ok {
|
||||
data, err = c.conn.cget(ie.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
//fmt.Printf("offset size %d %d\n", ie.Offset, ie.Size)
|
||||
if len(data) < int(ie.Offset+ie.Size) {
|
||||
return nil, fmt.Errorf("short pack block")
|
||||
}
|
||||
|
||||
data = data[ie.Offset:]
|
||||
if ie.Size < 1+8+1+8+8 {
|
||||
return nil, fmt.Errorf("short pack block")
|
||||
}
|
||||
|
||||
bo := binary.BigEndian
|
||||
|
||||
if data[0] != 1 {
|
||||
return nil, fmt.Errorf("missing mime type")
|
||||
}
|
||||
n := bo.Uint64(data[1:])
|
||||
if 1+8+n > uint64(len(data)) {
|
||||
return nil, fmt.Errorf("malformed mime type")
|
||||
}
|
||||
mimeType := data[1+8 : 1+8+n]
|
||||
data = data[1+8+n:]
|
||||
|
||||
n = bo.Uint64(data[1:])
|
||||
if 1+8+n > uint64(len(data)) {
|
||||
return nil, fmt.Errorf("malformed name")
|
||||
}
|
||||
name := data[1+8 : 1+8+n]
|
||||
data = data[1+8+n:]
|
||||
|
||||
_, _ = mimeType, name
|
||||
// fmt.Printf("%s %s\n", mimeType, name)
|
||||
|
||||
n = bo.Uint64(data[0:])
|
||||
if int64(n) != ie.Size {
|
||||
return nil, fmt.Errorf("unexpected data length %d %d", n, ie.Size)
|
||||
}
|
||||
if 8+n > uint64(len(data)) {
|
||||
return nil, fmt.Errorf("short data %d %d", 8+n, len(data))
|
||||
}
|
||||
|
||||
data = data[8 : 8+n]
|
||||
} else {
|
||||
data, err = c.conn.cget(c.UUID + "/objects/" + sc.String())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
data = c.crypto.decrypt(data)
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// A Folder represents a backed-up tree on a computer.
|
||||
type Folder struct {
|
||||
Path string // root of tree of last backup
|
||||
uuid string
|
||||
comp *Computer
|
||||
conn *Conn
|
||||
}
|
||||
|
||||
// Load loads xxx
|
||||
func (f *Folder) Load() error {
|
||||
if err := f.comp.loadPack(f.uuid, "-trees"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f.comp.loadPack(f.uuid, "-blobs"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Computer) loadPack(fold, suf string) error {
|
||||
list, err := c.conn.list(c.UUID+"/packsets/"+fold+suf+"/", "", 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, obj := range list.Contents {
|
||||
if !strings.HasSuffix(obj.Key, ".index") {
|
||||
continue
|
||||
}
|
||||
data, err := c.conn.cget(obj.Key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// fmt.Printf("pack %s\n", obj.Key)
|
||||
c.saveIndex(obj.Key[:len(obj.Key)-len(".index")]+".pack", data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Computer) saveIndex(file string, data []byte) error {
|
||||
const (
|
||||
headerSize = 4 + 4 + 4*256
|
||||
entrySize = 8 + 8 + 20 + 4
|
||||
trailerSize = 20
|
||||
)
|
||||
bo := binary.BigEndian
|
||||
if len(data) < headerSize+trailerSize {
|
||||
return fmt.Errorf("short index")
|
||||
}
|
||||
i := len(data) - trailerSize
|
||||
sum1 := sha(data[:i])
|
||||
sum2 := binaryScore(data[i:])
|
||||
if !sum1.Equal(sum2) {
|
||||
return fmt.Errorf("invalid sha index")
|
||||
}
|
||||
|
||||
obj := data[headerSize : len(data)-trailerSize]
|
||||
n := len(obj) / entrySize
|
||||
if n*entrySize != len(obj) {
|
||||
return fmt.Errorf("misaligned index %d %d", n*entrySize, len(obj))
|
||||
}
|
||||
nn := bo.Uint32(data[headerSize-4:])
|
||||
if int(nn) != n {
|
||||
return fmt.Errorf("inconsistent index %d %d\n", nn, n)
|
||||
}
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
e := obj[i*entrySize:]
|
||||
var ie ientry
|
||||
ie.File = file
|
||||
ie.Offset = int64(bo.Uint64(e[0:]))
|
||||
ie.Size = int64(bo.Uint64(e[8:]))
|
||||
ie.Score = binaryScore(e[16:])
|
||||
c.index[ie.Score] = ie
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Trees returns a list of the individual backup snapshots for the folder.
|
||||
// Note that different trees from the same Folder might have different Paths
|
||||
// if the folder was "relocated" using the Arq interface.
|
||||
func (f *Folder) Trees() ([]*Tree, error) {
|
||||
data, err := f.conn.bget(f.comp.UUID + "/bucketdata/" + f.uuid + "/refs/heads/master")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sc := hexScore(string(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var out []*Tree
|
||||
for {
|
||||
data, err = f.comp.scget(sc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var com commit
|
||||
if err := unpack(data, &com); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var info folderInfo
|
||||
if err := plist.Unmarshal(com.BucketXML, &info); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
t := &Tree{
|
||||
Time: com.CreateTime,
|
||||
Path: info.LocalPath,
|
||||
Score: com.Tree.Score,
|
||||
|
||||
commit: com,
|
||||
comp: f.comp,
|
||||
folder: f,
|
||||
info: info,
|
||||
}
|
||||
out = append(out, t)
|
||||
|
||||
if len(com.ParentCommits) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
sc = com.ParentCommits[0].Score
|
||||
}
|
||||
|
||||
for i, n := 0, len(out)-1; i < n-i; i++ {
|
||||
out[i], out[n-i] = out[n-i], out[i]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (f *Folder) Trees2() ([]*Tree, error) {
|
||||
list, err := f.conn.list(f.comp.UUID+"/bucketdata/"+f.uuid+"/refs/logs/master/", "", 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var out []*Tree
|
||||
for _, obj := range list.Contents {
|
||||
data, err := f.conn.cget(obj.Key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var l reflog
|
||||
if err := plist.Unmarshal(data, &l); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sc := hexScore(l.NewHeadSHA1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err = f.comp.scget(sc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var com commit
|
||||
if err := unpack(data, &com); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var info folderInfo
|
||||
if err := plist.Unmarshal(com.BucketXML, &info); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
t := &Tree{
|
||||
Time: com.CreateTime,
|
||||
Path: info.LocalPath,
|
||||
Score: com.Tree.Score,
|
||||
|
||||
commit: com,
|
||||
comp: f.comp,
|
||||
folder: f,
|
||||
info: info,
|
||||
}
|
||||
out = append(out, t)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// A Tree represents a single backed-up file tree snapshot.
|
||||
type Tree struct {
|
||||
Time time.Time // time back-up completed
|
||||
Path string // root of backed-up tree
|
||||
Score [20]byte
|
||||
|
||||
comp *Computer
|
||||
folder *Folder
|
||||
commit commit
|
||||
info folderInfo
|
||||
|
||||
raw tree
|
||||
haveRaw bool
|
||||
}
|
||||
|
||||
// Root returns the File for the tree's root directory.
|
||||
func (t *Tree) Root() (*File, error) {
|
||||
if !t.haveRaw {
|
||||
data, err := t.comp.scget(t.Score)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := unpack(data, &t.raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t.haveRaw = true
|
||||
}
|
||||
|
||||
dir := &File{
|
||||
t: t,
|
||||
dir: &t.raw,
|
||||
n: &nameNode{"/", node{IsTree: true}},
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
// A File represents a file or directory in a tree.
|
||||
type File struct {
|
||||
t *Tree
|
||||
n *nameNode
|
||||
dir *tree
|
||||
byName map[string]*nameNode
|
||||
}
|
||||
|
||||
func (f *File) loadDir() error {
|
||||
if f.dir == nil {
|
||||
data, err := f.t.comp.scget(f.n.Node.Blob[0].Score)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var dir tree
|
||||
if err := unpack(data, &dir); err != nil {
|
||||
return err
|
||||
}
|
||||
f.dir = &dir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *File) Lookup(name string) (*File, error) {
|
||||
if !f.n.Node.IsTree {
|
||||
return nil, fmt.Errorf("lookup in non-directory")
|
||||
}
|
||||
if f.byName == nil {
|
||||
if err := f.loadDir(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f.byName = map[string]*nameNode{}
|
||||
for _, n := range f.dir.Nodes {
|
||||
f.byName[n.Name] = n
|
||||
}
|
||||
}
|
||||
n := f.byName[name]
|
||||
if n == nil {
|
||||
return nil, fmt.Errorf("no entry %q", name)
|
||||
}
|
||||
return &File{t: f.t, n: n}, nil
|
||||
}
|
||||
|
||||
func (f *File) Stat() *Dirent {
|
||||
if f.n.Node.IsTree {
|
||||
if err := f.loadDir(); err == nil {
|
||||
return &Dirent{
|
||||
Name: f.n.Name,
|
||||
ModTime: f.dir.Mtime.Time(),
|
||||
Mode: fileMode(f.dir.Mode),
|
||||
Size: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
return &Dirent{
|
||||
Name: f.n.Name,
|
||||
ModTime: f.n.Node.Mtime.Time(),
|
||||
Mode: fileMode(f.n.Node.Mode),
|
||||
Size: int64(f.n.Node.UncompressedSize),
|
||||
}
|
||||
}
|
||||
|
||||
type Dirent struct {
|
||||
Name string
|
||||
ModTime time.Time
|
||||
Mode os.FileMode
|
||||
Size int64
|
||||
}
|
||||
|
||||
func (f *File) ReadDir() ([]Dirent, error) {
|
||||
if !f.n.Node.IsTree {
|
||||
return nil, fmt.Errorf("ReadDir in non-directory")
|
||||
}
|
||||
if err := f.loadDir(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []Dirent
|
||||
for _, n := range f.dir.Nodes {
|
||||
out = append(out, Dirent{
|
||||
Name: n.Name,
|
||||
ModTime: n.Node.Mtime.Time(),
|
||||
Mode: fileMode(n.Node.Mode),
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (f *File) Open() (io.ReadCloser, error) {
|
||||
return &fileReader{t: f.t, blob: f.n.Node.Blob, n: &f.n.Node}, nil
|
||||
}
|
||||
|
||||
type fileReader struct {
|
||||
t *Tree
|
||||
n *node
|
||||
blob []sscore
|
||||
cur io.Reader
|
||||
close []io.Closer
|
||||
}
|
||||
|
||||
func (f *fileReader) Read(b []byte) (int, error) {
|
||||
for {
|
||||
if f.cur != nil {
|
||||
n, err := f.cur.Read(b)
|
||||
if n > 0 || err != nil && err != io.EOF {
|
||||
return n, err
|
||||
}
|
||||
for _, cl := range f.close {
|
||||
cl.Close()
|
||||
}
|
||||
f.close = f.close[:0]
|
||||
f.cur = nil
|
||||
}
|
||||
|
||||
if len(f.blob) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
// TODO: Get a direct reader, not a []byte.
|
||||
data, err := f.t.comp.scget(f.blob[0].Score)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
rc := ioutil.NopCloser(bytes.NewBuffer(data))
|
||||
|
||||
if f.n.CompressData {
|
||||
gz, err := gzip.NewReader(rc)
|
||||
if err != nil {
|
||||
rc.Close()
|
||||
return 0, err
|
||||
}
|
||||
f.close = append(f.close, gz)
|
||||
f.cur = gz
|
||||
} else {
|
||||
f.cur = rc
|
||||
}
|
||||
f.close = append(f.close, rc)
|
||||
f.blob = f.blob[1:]
|
||||
}
|
||||
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
func (f *fileReader) Close() error {
|
||||
for _, cl := range f.close {
|
||||
cl.Close()
|
||||
}
|
||||
f.close = f.close[:0]
|
||||
f.cur = nil
|
||||
return nil
|
||||
}
|
||||
247
vendor/github.com/mattermost/rsc/arq/arqfs/main.go
сгенерированный
поставляемый
247
vendor/github.com/mattermost/rsc/arq/arqfs/main.go
сгенерированный
поставляемый
@@ -1,247 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
/*
|
||||
Arqfs implements a file system interface to a collection of Arq backups.
|
||||
|
||||
usage: arqfs [-m mtpt]
|
||||
|
||||
Arqfs mounts the Arq backups on the file system directory mtpt,
|
||||
(default /mnt/arq). The directory must exist and be writable by
|
||||
the current user.
|
||||
|
||||
Arq
|
||||
|
||||
Arq is an Amazon S3-based backup system for OS X and sold by
|
||||
Haystack Software (http://www.haystacksoftware.com/arq/).
|
||||
This software reads backups written by Arq.
|
||||
It is not affiliated with or connected to Haystack Software.
|
||||
|
||||
Passwords
|
||||
|
||||
Arqfs reads necessary passwords from the OS X keychain.
|
||||
It expects at least two entries:
|
||||
|
||||
The keychain entry for s3.amazonaws.com should list the Amazon S3 access ID
|
||||
as user name and the S3 secret key as password.
|
||||
|
||||
Each backup being accessed must have its own keychain entry for
|
||||
host arq.swtch.com, listing the backup UUID as user name and the encryption
|
||||
password as the password.
|
||||
|
||||
Arqfs will not prompt for passwords or create these entries itself: they must
|
||||
be created using the Keychain Access application.
|
||||
|
||||
FUSE
|
||||
|
||||
Arqfs creates a virtual file system using the FUSE file system layer.
|
||||
On OS X, it requires OSXFUSE (http://osxfuse.github.com/).
|
||||
|
||||
Cache
|
||||
|
||||
Reading the Arq backups efficiently requires caching directory tree information
|
||||
on local disk instead of reading the same data from S3 repeatedly. Arqfs caches
|
||||
data downloaded from S3 in $HOME/Library/Caches/arq-cache/.
|
||||
If an Arq installation is present on the same machine, arqfs will look in
|
||||
its cache ($HOME/Library/Arq/Cache.noindex) first, but arqfs will not
|
||||
write to Arq's cache directory.
|
||||
|
||||
Bugs
|
||||
|
||||
Arqfs only runs on OS X for now, because both FUSE and the keychain access
|
||||
packages have not been ported to other systems yet.
|
||||
|
||||
Both Arqfs and the FUSE package on which it is based have seen only light
|
||||
use. There are likely to be bugs. Mail rsc@swtch.com with reports.
|
||||
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
|
||||
"github.com/mattermost/rsc/arq"
|
||||
"github.com/mattermost/rsc/fuse"
|
||||
"github.com/mattermost/rsc/keychain"
|
||||
"launchpad.net/goamz/aws"
|
||||
)
|
||||
|
||||
var mtpt = flag.String("m", "/mnt/arq", "")
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
|
||||
if len(os.Args) == 3 && os.Args[1] == "MOUNTSLAVE" {
|
||||
*mtpt = os.Args[2]
|
||||
mountslave()
|
||||
return
|
||||
}
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "usage: arqfs [-m /mnt/arq]\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
flag.Parse()
|
||||
if len(flag.Args()) != 0 {
|
||||
flag.Usage()
|
||||
}
|
||||
|
||||
// Run in child so that we can exit once child is running.
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
cmd := exec.Command(os.Args[0], "MOUNTSLAVE", *mtpt)
|
||||
cmd.Stdout = w
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.Fatalf("mount process: %v", err)
|
||||
}
|
||||
w.Close()
|
||||
|
||||
buf := make([]byte, 10)
|
||||
n, _ := r.Read(buf)
|
||||
if n != 2 || string(buf[0:2]) != "OK" {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "mounted on %s\n", *mtpt)
|
||||
}
|
||||
|
||||
func mountslave() {
|
||||
stdout, _ := syscall.Dup(1)
|
||||
syscall.Dup2(2, 1)
|
||||
|
||||
access, secret, err := keychain.UserPasswd("s3.amazonaws.com", "")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
auth := aws.Auth{AccessKey: access, SecretKey: secret}
|
||||
|
||||
conn, err := arq.Dial(auth)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
comps, err := conn.Computers()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fs := &fuse.Tree{}
|
||||
for _, c := range comps {
|
||||
fmt.Fprintf(os.Stderr, "scanning %s...\n", c.Name)
|
||||
|
||||
// TODO: Better password protocol.
|
||||
_, pw, err := keychain.UserPasswd("arq.swtch.com", c.UUID)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
c.Unlock(pw)
|
||||
|
||||
folders, err := c.Folders()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
lastDate := ""
|
||||
n := 0
|
||||
for _, f := range folders {
|
||||
if err := f.Load(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
trees, err := f.Trees()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, t := range trees {
|
||||
y, m, d := t.Time.Date()
|
||||
date := fmt.Sprintf("%04d/%02d%02d", y, m, d)
|
||||
suffix := ""
|
||||
if date == lastDate {
|
||||
n++
|
||||
suffix = fmt.Sprintf(".%d", n)
|
||||
} else {
|
||||
n = 0
|
||||
}
|
||||
lastDate = date
|
||||
f, err := t.Root()
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
// TODO: Pass times to fs.Add.
|
||||
// fmt.Fprintf(os.Stderr, "%v %s %x\n", t.Time, c.Name+"/"+date+suffix+"/"+t.Path, t.Score)
|
||||
fs.Add(c.Name+"/"+date+suffix+"/"+t.Path, &fuseNode{f})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "mounting...\n")
|
||||
|
||||
c, err := fuse.Mount(*mtpt)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer exec.Command("umount", *mtpt).Run()
|
||||
|
||||
syscall.Write(stdout, []byte("OK"))
|
||||
syscall.Close(stdout)
|
||||
c.Serve(fs)
|
||||
}
|
||||
|
||||
type fuseNode struct {
|
||||
arq *arq.File
|
||||
}
|
||||
|
||||
func (f *fuseNode) Attr() fuse.Attr {
|
||||
de := f.arq.Stat()
|
||||
return fuse.Attr{
|
||||
Mode: de.Mode,
|
||||
Mtime: de.ModTime,
|
||||
Size: uint64(de.Size),
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fuseNode) Lookup(name string, intr fuse.Intr) (fuse.Node, fuse.Error) {
|
||||
ff, err := f.arq.Lookup(name)
|
||||
if err != nil {
|
||||
return nil, fuse.ENOENT
|
||||
}
|
||||
return &fuseNode{ff}, nil
|
||||
}
|
||||
|
||||
func (f *fuseNode) ReadDir(intr fuse.Intr) ([]fuse.Dirent, fuse.Error) {
|
||||
adir, err := f.arq.ReadDir()
|
||||
if err != nil {
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
var dir []fuse.Dirent
|
||||
for _, ade := range adir {
|
||||
dir = append(dir, fuse.Dirent{
|
||||
Name: ade.Name,
|
||||
})
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
// TODO: Implement Read+Release, not ReadAll, to avoid giant buffer.
|
||||
func (f *fuseNode) ReadAll(intr fuse.Intr) ([]byte, fuse.Error) {
|
||||
rc, err := f.arq.Open()
|
||||
if err != nil {
|
||||
return nil, fuse.EIO
|
||||
}
|
||||
defer rc.Close()
|
||||
data, err := ioutil.ReadAll(rc)
|
||||
if err != nil {
|
||||
return data, fuse.EIO
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
93
vendor/github.com/mattermost/rsc/arq/crypto.go
сгенерированный
поставляемый
93
vendor/github.com/mattermost/rsc/arq/crypto.go
сгенерированный
поставляемый
@@ -1,93 +0,0 @@
|
||||
// Copyright 2012 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 arq
|
||||
|
||||
import (
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/sha1"
|
||||
"hash"
|
||||
"log"
|
||||
|
||||
"bitbucket.org/taruti/pbkdf2.go" // TODO: Pull in copy
|
||||
)
|
||||
|
||||
type cryptoState struct {
|
||||
c cipher.Block
|
||||
iv []byte
|
||||
salt []byte
|
||||
}
|
||||
|
||||
func (c *cryptoState) unlock(pw string) {
|
||||
const (
|
||||
iter = 1000
|
||||
keyLen = 48
|
||||
aesKeyLen = 32
|
||||
aesIVLen = 16
|
||||
)
|
||||
key1 := pbkdf2.Pbkdf2([]byte(pw), c.salt, iter, sha1.New, keyLen)
|
||||
var key2 []byte
|
||||
key2, c.iv = bytesToKey(sha1.New, c.salt, key1, iter, aesKeyLen, aesIVLen)
|
||||
c.c, _ = aes.NewCipher(key2)
|
||||
}
|
||||
|
||||
func (c *cryptoState) decrypt(data []byte) []byte {
|
||||
dec := cipher.NewCBCDecrypter(c.c, c.iv)
|
||||
if len(data)%aes.BlockSize != 0 {
|
||||
log.Fatal("bad block")
|
||||
}
|
||||
dec.CryptBlocks(data, data)
|
||||
// fmt.Printf("% x\n", data)
|
||||
// fmt.Printf("%s\n", data)
|
||||
|
||||
// unpad
|
||||
{
|
||||
n := len(data)
|
||||
p := int(data[n-1])
|
||||
if p == 0 || p > aes.BlockSize {
|
||||
log.Fatal("impossible padding")
|
||||
}
|
||||
for i := 0; i < p; i++ {
|
||||
if data[n-1-i] != byte(p) {
|
||||
log.Fatal("bad padding")
|
||||
}
|
||||
}
|
||||
data = data[:n-p]
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func sha(data []byte) score {
|
||||
h := sha1.New()
|
||||
h.Write(data)
|
||||
var sc score
|
||||
copy(sc[:], h.Sum(nil))
|
||||
return sc
|
||||
}
|
||||
|
||||
func bytesToKey(hf func() hash.Hash, salt, data []byte, iter int, keySize, ivSize int) (key, iv []byte) {
|
||||
h := hf()
|
||||
var d, dcat []byte
|
||||
sum := make([]byte, 0, h.Size())
|
||||
for len(dcat) < keySize+ivSize {
|
||||
// D_i = HASH^count(D_(i-1) || data || salt)
|
||||
h.Reset()
|
||||
h.Write(d)
|
||||
h.Write(data)
|
||||
h.Write(salt)
|
||||
sum = h.Sum(sum[:0])
|
||||
|
||||
for j := 1; j < iter; j++ {
|
||||
h.Reset()
|
||||
h.Write(sum)
|
||||
sum = h.Sum(sum[:0])
|
||||
}
|
||||
|
||||
d = append(d[:0], sum...)
|
||||
dcat = append(dcat, d...)
|
||||
}
|
||||
|
||||
return dcat[:keySize], dcat[keySize : keySize+ivSize]
|
||||
}
|
||||
240
vendor/github.com/mattermost/rsc/arq/data.go
сгенерированный
поставляемый
240
vendor/github.com/mattermost/rsc/arq/data.go
сгенерированный
поставляемый
@@ -1,240 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// On-cloud data structures
|
||||
|
||||
package arq
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// plist data structures
|
||||
|
||||
type computerInfo struct {
|
||||
UserName string `plist:"userName"`
|
||||
ComputerName string `plist:"computerName"`
|
||||
}
|
||||
|
||||
type folderInfo struct {
|
||||
BucketUUID string
|
||||
BucketName string
|
||||
ComputerUUID string
|
||||
LocalPath string
|
||||
LocalMountPoint string
|
||||
// don't care about IgnoredRelativePaths or Excludes
|
||||
}
|
||||
|
||||
type reflog struct {
|
||||
OldHeadSHA1 string `plist:"oldHeadSHA1"`
|
||||
NewHeadSHA1 string `plist:"newHeadSHA1"`
|
||||
}
|
||||
|
||||
// binary data structures
|
||||
|
||||
type score [20]byte
|
||||
|
||||
type sscore struct {
|
||||
Score score `arq:"HexScore"`
|
||||
StretchKey bool // v4+
|
||||
}
|
||||
|
||||
type tag string
|
||||
|
||||
type commit struct {
|
||||
Tag tag `arq:"CommitV005"`
|
||||
Author string
|
||||
Comment string
|
||||
ParentCommits []sscore
|
||||
Tree sscore
|
||||
Location string
|
||||
MergeCommonAncestor sscore
|
||||
CreateTime time.Time
|
||||
Failed []failed // v3+
|
||||
BucketXML []byte // v5+
|
||||
}
|
||||
|
||||
type tree struct {
|
||||
Tag tag `arq:"TreeV015"`
|
||||
CompressXattr bool
|
||||
CompressACL bool
|
||||
Xattr sscore
|
||||
XattrSize uint64
|
||||
ACL sscore
|
||||
Uid int32
|
||||
Gid int32
|
||||
Mode int32
|
||||
Mtime unixTime
|
||||
Flags int64
|
||||
FinderFlags int32
|
||||
XFinderFlags int32
|
||||
StDev int32
|
||||
StIno int32
|
||||
StNlink uint32
|
||||
StRdev int32
|
||||
Ctime unixTime
|
||||
StBlocks int64
|
||||
StBlksize uint32
|
||||
AggrSize uint64
|
||||
Crtime unixTime
|
||||
Nodes []*nameNode `arq:"count32"`
|
||||
}
|
||||
|
||||
type nameNode struct {
|
||||
Name string
|
||||
Node node
|
||||
}
|
||||
|
||||
type node struct {
|
||||
IsTree bool
|
||||
CompressData bool
|
||||
CompressXattr bool
|
||||
CompressACL bool
|
||||
Blob []sscore `arq:"count32"`
|
||||
UncompressedSize uint64
|
||||
Thumbnail sscore
|
||||
Preview sscore
|
||||
Xattr sscore
|
||||
XattrSize uint64
|
||||
ACL sscore
|
||||
Uid int32
|
||||
Gid int32
|
||||
Mode int32
|
||||
Mtime unixTime
|
||||
Flags int64
|
||||
FinderFlags int32
|
||||
XFinderFlags int32
|
||||
FinderFileType string
|
||||
FinderFileCreator string
|
||||
IsExtHidden bool
|
||||
StDev int32
|
||||
StIno int32
|
||||
StNlink uint32
|
||||
StRdev int32
|
||||
Ctime unixTime
|
||||
CreateTime unixTime
|
||||
StBlocks int64
|
||||
StBlksize uint32
|
||||
}
|
||||
|
||||
func fileMode(m int32) os.FileMode {
|
||||
const (
|
||||
// Darwin file mode.
|
||||
S_IFBLK = 0x6000
|
||||
S_IFCHR = 0x2000
|
||||
S_IFDIR = 0x4000
|
||||
S_IFIFO = 0x1000
|
||||
S_IFLNK = 0xa000
|
||||
S_IFMT = 0xf000
|
||||
S_IFREG = 0x8000
|
||||
S_IFSOCK = 0xc000
|
||||
S_IFWHT = 0xe000
|
||||
S_ISGID = 0x400
|
||||
S_ISTXT = 0x200
|
||||
S_ISUID = 0x800
|
||||
S_ISVTX = 0x200
|
||||
)
|
||||
mode := os.FileMode(m & 0777)
|
||||
switch m & S_IFMT {
|
||||
case S_IFBLK, S_IFWHT:
|
||||
mode |= os.ModeDevice
|
||||
case S_IFCHR:
|
||||
mode |= os.ModeDevice | os.ModeCharDevice
|
||||
case S_IFDIR:
|
||||
mode |= os.ModeDir
|
||||
case S_IFIFO:
|
||||
mode |= os.ModeNamedPipe
|
||||
case S_IFLNK:
|
||||
mode |= os.ModeSymlink
|
||||
case S_IFREG:
|
||||
// nothing to do
|
||||
case S_IFSOCK:
|
||||
mode |= os.ModeSocket
|
||||
}
|
||||
if m&S_ISGID != 0 {
|
||||
mode |= os.ModeSetgid
|
||||
}
|
||||
if m&S_ISUID != 0 {
|
||||
mode |= os.ModeSetuid
|
||||
}
|
||||
if m&S_ISVTX != 0 {
|
||||
mode |= os.ModeSticky
|
||||
}
|
||||
return mode
|
||||
}
|
||||
|
||||
type unixTime struct {
|
||||
Sec int64
|
||||
Nsec int64
|
||||
}
|
||||
|
||||
func (t *unixTime) Time() time.Time {
|
||||
return time.Unix(t.Sec, t.Nsec)
|
||||
}
|
||||
|
||||
type failed struct {
|
||||
Path string
|
||||
Error string
|
||||
}
|
||||
|
||||
type ientry struct {
|
||||
File string
|
||||
Offset int64
|
||||
Size int64
|
||||
Score score
|
||||
}
|
||||
|
||||
func (s score) Equal(t score) bool {
|
||||
for i := range s {
|
||||
if s[i] != t[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s score) String() string {
|
||||
return fmt.Sprintf("%x", s[:])
|
||||
}
|
||||
|
||||
func binaryScore(b []byte) score {
|
||||
if len(b) < 20 {
|
||||
panic("BinaryScore: not enough data")
|
||||
}
|
||||
var sc score
|
||||
copy(sc[:], b)
|
||||
return sc
|
||||
}
|
||||
|
||||
func hexScore(b string) score {
|
||||
if len(b) < 40 {
|
||||
panic("HexScore: not enough data")
|
||||
}
|
||||
var sc score
|
||||
for i := 0; i < 40; i++ {
|
||||
ch := b[i]
|
||||
if '0' <= ch && ch <= '9' {
|
||||
ch -= '0'
|
||||
} else if 'a' <= ch && ch <= 'f' {
|
||||
ch -= 'a' - 10
|
||||
} else {
|
||||
panic("HexScore: invalid lower hex digit")
|
||||
}
|
||||
if i%2 == 0 {
|
||||
ch <<= 4
|
||||
}
|
||||
sc[i/2] |= ch
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
func (ss sscore) String() string {
|
||||
str := ss.Score.String()
|
||||
if ss.StretchKey {
|
||||
str += "Y"
|
||||
}
|
||||
return str
|
||||
}
|
||||
160
vendor/github.com/mattermost/rsc/arq/hist/hist.go
сгенерированный
поставляемый
160
vendor/github.com/mattermost/rsc/arq/hist/hist.go
сгенерированный
поставляемый
@@ -1,160 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
/*
|
||||
Hist shows the history of a given file, using Arq backups.
|
||||
|
||||
usage: hist [-d] [-h host] [-m mtpt] [-s yyyy/mmdd] file ...
|
||||
|
||||
The -d flag causes it to show diffs between successive versions.
|
||||
|
||||
By default, hist assumes backups are mounted at mtpt/host, where
|
||||
mtpt defaults to /mnt/arq and host is the first element of the local host name.
|
||||
Hist starts the file list with the present copy of the file.
|
||||
|
||||
The -h and -s flags override these assumptions.
|
||||
|
||||
*/
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var usageString = `usage: hist [-d] [-h host] [-m mtpt] [-s yyyy/mmdd] file ...
|
||||
|
||||
Hist lists the known versions of the given file.
|
||||
The -d flag causes it to show diffs between successive versions.
|
||||
|
||||
By default, hist assumes backups are mounted at mtpt/host, where
|
||||
mtpt defaults to /mnt/arq and host is the first element of the local host name.
|
||||
Hist starts the file list with the present copy of the file.
|
||||
|
||||
The -h and -s flags override these assumptions.
|
||||
`
|
||||
|
||||
var (
|
||||
diff = flag.Bool("d", false, "diff")
|
||||
host = flag.String("h", defaultHost(), "host name")
|
||||
mtpt = flag.String("m", "/mnt/arq", "mount point")
|
||||
vers = flag.String("s", "", "version")
|
||||
)
|
||||
|
||||
func defaultHost() string {
|
||||
name, _ := os.Hostname()
|
||||
if name == "" {
|
||||
name = "gnot"
|
||||
}
|
||||
if i := strings.Index(name, "."); i >= 0 {
|
||||
name = name[:i]
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = func() {
|
||||
fmt.Fprint(os.Stderr, usageString)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
if len(args) == 0 {
|
||||
flag.Usage()
|
||||
}
|
||||
|
||||
dates := loadDates()
|
||||
for _, file := range args {
|
||||
list(dates, file)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
yyyy = regexp.MustCompile(`^\d{4}$`)
|
||||
mmdd = regexp.MustCompile(`^\d{4}(\.\d+)?$`)
|
||||
)
|
||||
|
||||
func loadDates() []string {
|
||||
var all []string
|
||||
ydir, err := ioutil.ReadDir(filepath.Join(*mtpt, *host))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(3)
|
||||
}
|
||||
for _, y := range ydir {
|
||||
if !y.IsDir() || !yyyy.MatchString(y.Name()) {
|
||||
continue
|
||||
}
|
||||
ddir, err := ioutil.ReadDir(filepath.Join(*mtpt, *host, y.Name()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, d := range ddir {
|
||||
if !d.IsDir() || !mmdd.MatchString(d.Name()) {
|
||||
continue
|
||||
}
|
||||
date := y.Name() + "/" + d.Name()
|
||||
if *vers > date {
|
||||
continue
|
||||
}
|
||||
all = append(all, filepath.Join(*mtpt, *host, date))
|
||||
}
|
||||
}
|
||||
return all
|
||||
}
|
||||
|
||||
const timeFormat = "Jan 02 15:04:05 MST 2006"
|
||||
|
||||
func list(dates []string, file string) {
|
||||
var (
|
||||
last os.FileInfo
|
||||
lastPath string
|
||||
)
|
||||
|
||||
fi, err := os.Stat(file)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "hist: warning: %s: %v\n", file, err)
|
||||
} else {
|
||||
fmt.Printf("%s %s %d\n", fi.ModTime().Format(timeFormat), file, fi.Size())
|
||||
last = fi
|
||||
lastPath = file
|
||||
}
|
||||
|
||||
file, err = filepath.Abs(file)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "hist: abs: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
for i := len(dates)-1; i >= 0; i-- {
|
||||
p := filepath.Join(dates[i], file)
|
||||
fi, err := os.Stat(p)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if last != nil && fi.ModTime() == last.ModTime() && fi.Size() == last.Size() {
|
||||
continue
|
||||
}
|
||||
if *diff {
|
||||
cmd := exec.Command("diff", lastPath, p)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err := cmd.Start(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
}
|
||||
cmd.Wait()
|
||||
}
|
||||
fmt.Printf("%s %s %d\n", fi.ModTime().Format(timeFormat), p, fi.Size())
|
||||
last = fi
|
||||
lastPath = p
|
||||
}
|
||||
}
|
||||
|
||||
227
vendor/github.com/mattermost/rsc/arq/unpack.go
сгенерированный
поставляемый
227
vendor/github.com/mattermost/rsc/arq/unpack.go
сгенерированный
поставляемый
@@ -1,227 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// Parsing of Arq's binary data structures.
|
||||
|
||||
package arq
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
var errMalformed = fmt.Errorf("malformed data")
|
||||
var tagType = reflect.TypeOf(tag(""))
|
||||
var timeType = reflect.TypeOf(time.Time{})
|
||||
var scoreType = reflect.TypeOf(score{})
|
||||
|
||||
func unpack(data []byte, v interface{}) error {
|
||||
data, err := unpackValue(data, reflect.ValueOf(v).Elem(), "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(data) != 0 {
|
||||
if len(data) > 100 {
|
||||
return fmt.Errorf("more data than expected: %x...", data[:100])
|
||||
}
|
||||
return fmt.Errorf("more data than expected: %x", data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func unpackValue(data []byte, v reflect.Value, tag string) ([]byte, error) {
|
||||
//println("unpackvalue", v.Type().String(), len(data))
|
||||
switch v.Kind() {
|
||||
case reflect.String:
|
||||
if v.Type() == tagType {
|
||||
if tag == "" {
|
||||
panic("arqfs: missing reflect tag on Tag field")
|
||||
}
|
||||
if len(data) < len(tag) || !bytes.Equal(data[:len(tag)], []byte(tag)) {
|
||||
return nil, errMalformed
|
||||
}
|
||||
data = data[len(tag):]
|
||||
return data, nil
|
||||
}
|
||||
if len(data) < 1 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
if data[0] == 0 {
|
||||
data = data[1:]
|
||||
v.SetString("")
|
||||
return data, nil
|
||||
}
|
||||
if data[0] != 1 || len(data) < 1+8 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
n := binary.BigEndian.Uint64(data[1:])
|
||||
data = data[1+8:]
|
||||
if n >= uint64(len(data)) {
|
||||
return nil, errMalformed
|
||||
}
|
||||
str := data[:n]
|
||||
data = data[n:]
|
||||
v.SetString(string(str))
|
||||
return data, nil
|
||||
|
||||
case reflect.Uint32:
|
||||
if len(data) < 4 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
v.SetUint(uint64(binary.BigEndian.Uint32(data)))
|
||||
data = data[4:]
|
||||
return data, nil
|
||||
|
||||
case reflect.Int32:
|
||||
if len(data) < 4 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
v.SetInt(int64(binary.BigEndian.Uint32(data)))
|
||||
data = data[4:]
|
||||
return data, nil
|
||||
|
||||
case reflect.Uint8:
|
||||
if len(data) < 1 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
v.SetUint(uint64(data[0]))
|
||||
data = data[1:]
|
||||
return data, nil
|
||||
|
||||
case reflect.Uint64:
|
||||
if len(data) < 8 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
v.SetUint(binary.BigEndian.Uint64(data))
|
||||
data = data[8:]
|
||||
return data, nil
|
||||
|
||||
case reflect.Int64:
|
||||
if len(data) < 8 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
v.SetInt(int64(binary.BigEndian.Uint64(data)))
|
||||
data = data[8:]
|
||||
return data, nil
|
||||
|
||||
case reflect.Ptr:
|
||||
v.Set(reflect.New(v.Type().Elem()))
|
||||
return unpackValue(data, v.Elem(), tag)
|
||||
|
||||
case reflect.Slice:
|
||||
var n int
|
||||
if tag == "count32" {
|
||||
n32 := binary.BigEndian.Uint32(data)
|
||||
n = int(n32)
|
||||
if uint32(n) != n32 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
data = data[4:]
|
||||
} else {
|
||||
if len(data) < 8 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
n64 := binary.BigEndian.Uint64(data)
|
||||
n = int(n64)
|
||||
if uint64(n) != n64 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
data = data[8:]
|
||||
}
|
||||
v.Set(v.Slice(0, 0))
|
||||
if v.Type().Elem().Kind() == reflect.Uint8 {
|
||||
// Fast case for []byte
|
||||
if len(data) < n {
|
||||
return nil, errMalformed
|
||||
}
|
||||
v.Set(reflect.AppendSlice(v, reflect.ValueOf(data[:n])))
|
||||
return data[n:], nil
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
elem := reflect.New(v.Type().Elem()).Elem()
|
||||
var err error
|
||||
data, err = unpackValue(data, elem, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.Set(reflect.Append(v, elem))
|
||||
}
|
||||
return data, nil
|
||||
|
||||
case reflect.Array:
|
||||
if v.Type() == scoreType && tag == "HexScore" {
|
||||
var s string
|
||||
data, err := unpackValue(data, reflect.ValueOf(&s).Elem(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(s) != 0 {
|
||||
v.Set(reflect.ValueOf(hexScore(s)))
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
n := v.Len()
|
||||
if v.Type().Elem().Kind() == reflect.Uint8 {
|
||||
// Fast case for [n]byte
|
||||
if len(data) < n {
|
||||
return nil, errMalformed
|
||||
}
|
||||
reflect.Copy(v, reflect.ValueOf(data))
|
||||
data = data[n:]
|
||||
return data, nil
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
var err error
|
||||
data, err = unpackValue(data, v.Index(i), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
|
||||
case reflect.Bool:
|
||||
if len(data) < 1 || data[0] > 1 {
|
||||
if len(data) >= 1 {
|
||||
println("badbool", data[0])
|
||||
}
|
||||
return nil, errMalformed
|
||||
}
|
||||
v.SetBool(data[0] == 1)
|
||||
data = data[1:]
|
||||
return data, nil
|
||||
|
||||
case reflect.Struct:
|
||||
if v.Type() == timeType {
|
||||
if len(data) < 1 || data[0] > 1 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
if data[0] == 0 {
|
||||
v.Set(reflect.ValueOf(time.Time{}))
|
||||
return data[1:], nil
|
||||
}
|
||||
data = data[1:]
|
||||
if len(data) < 8 {
|
||||
return nil, errMalformed
|
||||
}
|
||||
ms := binary.BigEndian.Uint64(data)
|
||||
v.Set(reflect.ValueOf(time.Unix(int64(ms/1e3), int64(ms%1e3)*1e6)))
|
||||
return data[8:], nil
|
||||
}
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
f := v.Type().Field(i)
|
||||
fv := v.Field(i)
|
||||
var err error
|
||||
data, err = unpackValue(data, fv, f.Tag.Get("arq"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
panic("arqfs: unexpected type in unpackValue: " + v.Type().String())
|
||||
}
|
||||
58
vendor/github.com/mattermost/rsc/blog/atom/atom.go
сгенерированный
поставляемый
58
vendor/github.com/mattermost/rsc/blog/atom/atom.go
сгенерированный
поставляемый
@@ -1,58 +0,0 @@
|
||||
// Copyright 2009 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.
|
||||
|
||||
// Adapted from encoding/xml/read_test.go.
|
||||
|
||||
// Package atom defines XML data structures for an Atom feed.
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Feed struct {
|
||||
XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"`
|
||||
Title string `xml:"title"`
|
||||
ID string `xml:"id"`
|
||||
Link []Link `xml:"link"`
|
||||
Updated TimeStr `xml:"updated"`
|
||||
Author *Person `xml:"author"`
|
||||
Entry []*Entry `xml:"entry"`
|
||||
}
|
||||
|
||||
type Entry struct {
|
||||
Title string `xml:"title"`
|
||||
ID string `xml:"id"`
|
||||
Link []Link `xml:"link"`
|
||||
Published TimeStr `xml:"published"`
|
||||
Updated TimeStr `xml:"updated"`
|
||||
Author *Person `xml:"author"`
|
||||
Summary *Text `xml:"summary"`
|
||||
Content *Text `xml:"content"`
|
||||
}
|
||||
|
||||
type Link struct {
|
||||
Rel string `xml:"rel,attr"`
|
||||
Href string `xml:"href,attr"`
|
||||
}
|
||||
|
||||
type Person struct {
|
||||
Name string `xml:"name"`
|
||||
URI string `xml:"uri"`
|
||||
Email string `xml:"email"`
|
||||
InnerXML string `xml:",innerxml"`
|
||||
}
|
||||
|
||||
type Text struct {
|
||||
Type string `xml:"type,attr"`
|
||||
Body string `xml:",chardata"`
|
||||
}
|
||||
|
||||
type TimeStr string
|
||||
|
||||
func Time(t time.Time) TimeStr {
|
||||
return TimeStr(t.Format("2006-01-02T15:04:05-07:00"))
|
||||
}
|
||||
|
||||
15
vendor/github.com/mattermost/rsc/blog/main.go
сгенерированный
поставляемый
15
vendor/github.com/mattermost/rsc/blog/main.go
сгенерированный
поставляемый
@@ -1,15 +0,0 @@
|
||||
// Copyright 2011 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 main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/rsc/devweb/slave"
|
||||
|
||||
_ "github.com/mattermost/rsc/blog/post"
|
||||
)
|
||||
|
||||
func main() {
|
||||
slave.Main()
|
||||
}
|
||||
534
vendor/github.com/mattermost/rsc/blog/post/post.go
сгенерированный
поставляемый
534
vendor/github.com/mattermost/rsc/blog/post/post.go
сгенерированный
поставляемый
@@ -1,534 +0,0 @@
|
||||
// Copyright 2011 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 post
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"runtime/debug"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/rsc/appfs/fs"
|
||||
"github.com/mattermost/rsc/appfs/proto"
|
||||
"github.com/mattermost/rsc/blog/atom"
|
||||
)
|
||||
|
||||
func init() {
|
||||
fs.Root = os.Getenv("HOME") + "/app/"
|
||||
http.HandleFunc("/", serve)
|
||||
http.Handle("/feeds/posts/default", http.RedirectHandler("/feed.atom", http.StatusFound))
|
||||
}
|
||||
|
||||
var funcMap = template.FuncMap{
|
||||
"now": time.Now,
|
||||
"date": timeFormat,
|
||||
}
|
||||
|
||||
func timeFormat(fmt string, t time.Time) string {
|
||||
return t.Format(fmt)
|
||||
}
|
||||
|
||||
type blogTime struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
var timeFormats = []string{
|
||||
time.RFC3339,
|
||||
"Monday, January 2, 2006",
|
||||
"January 2, 2006 15:00 -0700",
|
||||
}
|
||||
|
||||
func (t *blogTime) UnmarshalJSON(data []byte) (err error) {
|
||||
str := string(data)
|
||||
for _, f := range timeFormats {
|
||||
tt, err := time.Parse(`"`+f+`"`, str)
|
||||
if err == nil {
|
||||
t.Time = tt
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("did not recognize time: %s", str)
|
||||
}
|
||||
|
||||
type PostData struct {
|
||||
FileModTime time.Time
|
||||
FileSize int64
|
||||
|
||||
Title string
|
||||
Date blogTime
|
||||
Name string
|
||||
OldURL string
|
||||
Summary string
|
||||
Favorite bool
|
||||
|
||||
Reader []string
|
||||
|
||||
PlusAuthor string // Google+ ID of author
|
||||
PlusPage string // Google+ Post ID for comment post
|
||||
PlusAPIKey string // Google+ API key
|
||||
PlusURL string
|
||||
HostURL string // host URL
|
||||
Comments bool
|
||||
|
||||
article string
|
||||
}
|
||||
|
||||
func (d *PostData) canRead(user string) bool {
|
||||
for _, r := range d.Reader {
|
||||
if r == user {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *PostData) IsDraft() bool {
|
||||
return d.Date.IsZero() || d.Date.After(time.Now())
|
||||
}
|
||||
|
||||
// To find PlusPage value:
|
||||
// https://www.googleapis.com/plus/v1/people/116810148281701144465/activities/public?key=AIzaSyB_JO6hyAJAL659z0Dmu0RUVVvTx02ZPMM
|
||||
//
|
||||
|
||||
const owner = "rsc@swtch.com"
|
||||
const plusRsc = "116810148281701144465"
|
||||
const plusKey = "AIzaSyB_JO6hyAJAL659z0Dmu0RUVVvTx02ZPMM"
|
||||
const feedID = "tag:research.swtch.com,2012:research.swtch.com"
|
||||
|
||||
var replacer = strings.NewReplacer(
|
||||
"⁰", "<sup>0</sup>",
|
||||
"¹", "<sup>1</sup>",
|
||||
"²", "<sup>2</sup>",
|
||||
"³", "<sup>3</sup>",
|
||||
"⁴", "<sup>4</sup>",
|
||||
"⁵", "<sup>5</sup>",
|
||||
"⁶", "<sup>6</sup>",
|
||||
"⁷", "<sup>7</sup>",
|
||||
"⁸", "<sup>8</sup>",
|
||||
"⁹", "<sup>9</sup>",
|
||||
"ⁿ", "<sup>n</sup>",
|
||||
"₀", "<sub>0</sub>",
|
||||
"₁", "<sub>1</sub>",
|
||||
"₂", "<sub>2</sub>",
|
||||
"₃", "<sub>3</sub>",
|
||||
"₄", "<sub>4</sub>",
|
||||
"₅", "<sub>5</sub>",
|
||||
"₆", "<sub>6</sub>",
|
||||
"₇", "<sub>7</sub>",
|
||||
"₈", "<sub>8</sub>",
|
||||
"₉", "<sub>9</sub>",
|
||||
"``", "“",
|
||||
"''", "”",
|
||||
)
|
||||
|
||||
func serve(w http.ResponseWriter, req *http.Request) {
|
||||
ctxt := fs.NewContext(req)
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprintf(&buf, "panic: %s\n\n", err)
|
||||
buf.Write(debug.Stack())
|
||||
ctxt.Criticalf("%s", buf.String())
|
||||
|
||||
http.Error(w, buf.String(), 500)
|
||||
}
|
||||
}()
|
||||
|
||||
p := path.Clean("/" + req.URL.Path)
|
||||
/*
|
||||
if strings.Contains(req.Host, "appspot.com") {
|
||||
http.Redirect(w, req, "http://research.swtch.com" + p, http.StatusFound)
|
||||
}
|
||||
*/
|
||||
if p != req.URL.Path {
|
||||
http.Redirect(w, req, p, http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
if p == "/feed.atom" {
|
||||
atomfeed(w, req)
|
||||
return
|
||||
}
|
||||
|
||||
if strings.HasPrefix(p, "/20") && strings.Contains(p[1:], "/") {
|
||||
// Assume this is an old-style URL.
|
||||
oldRedirect(ctxt, w, req, p)
|
||||
}
|
||||
|
||||
user := ctxt.User()
|
||||
isOwner := ctxt.User() == owner || len(os.Args) >= 2 && os.Args[1] == "LISTEN_STDIN"
|
||||
if p == "" || p == "/" || p == "/draft" {
|
||||
if p == "/draft" && user == "?" {
|
||||
ctxt.Criticalf("/draft loaded by %s", user)
|
||||
notfound(ctxt, w, req)
|
||||
return
|
||||
}
|
||||
toc(w, req, p == "/draft", isOwner, user)
|
||||
return
|
||||
}
|
||||
|
||||
draft := false
|
||||
if strings.HasPrefix(p, "/draft/") {
|
||||
if user == "?" {
|
||||
ctxt.Criticalf("/draft loaded by %s", user)
|
||||
notfound(ctxt, w, req)
|
||||
return
|
||||
}
|
||||
draft = true
|
||||
p = p[len("/draft"):]
|
||||
}
|
||||
|
||||
if strings.Contains(p[1:], "/") {
|
||||
notfound(ctxt, w, req)
|
||||
return
|
||||
}
|
||||
|
||||
if strings.Contains(p, ".") {
|
||||
// Let Google's front end servers cache static
|
||||
// content for a short amount of time.
|
||||
httpCache(w, 5*time.Minute)
|
||||
ctxt.ServeFile(w, req, "blog/static/"+p)
|
||||
return
|
||||
}
|
||||
|
||||
// Use just 'blog' as the cache path so that if we change
|
||||
// templates, all the cached HTML gets invalidated.
|
||||
var data []byte
|
||||
pp := "bloghtml:"+p
|
||||
if draft && !isOwner {
|
||||
pp += ",user="+user
|
||||
}
|
||||
if key, ok := ctxt.CacheLoad(pp, "blog", &data); !ok {
|
||||
meta, article, err := loadPost(ctxt, p, req)
|
||||
if err != nil || meta.IsDraft() != draft || (draft && !isOwner && !meta.canRead(user)) {
|
||||
ctxt.Criticalf("no %s for %s", p, user)
|
||||
notfound(ctxt, w, req)
|
||||
return
|
||||
}
|
||||
t := mainTemplate(ctxt)
|
||||
template.Must(t.New("article").Parse(article))
|
||||
|
||||
var buf bytes.Buffer
|
||||
meta.Comments = true
|
||||
if err := t.Execute(&buf, meta); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data = buf.Bytes()
|
||||
ctxt.CacheStore(key, data)
|
||||
}
|
||||
w.Write(data)
|
||||
}
|
||||
|
||||
func notfound(ctxt *fs.Context, w http.ResponseWriter, req *http.Request) {
|
||||
var buf bytes.Buffer
|
||||
var data struct {
|
||||
HostURL string
|
||||
}
|
||||
data.HostURL = hostURL(req)
|
||||
t := mainTemplate(ctxt)
|
||||
if err := t.Lookup("404").Execute(&buf, &data); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w.WriteHeader(404)
|
||||
w.Write(buf.Bytes())
|
||||
}
|
||||
|
||||
func mainTemplate(c *fs.Context) *template.Template {
|
||||
t := template.New("main")
|
||||
t.Funcs(funcMap)
|
||||
|
||||
main, _, err := c.Read("blog/main.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
style, _, _ := c.Read("blog/style.html")
|
||||
main = append(main, style...)
|
||||
_, err = t.Parse(string(main))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func loadPost(c *fs.Context, name string, req *http.Request) (meta *PostData, article string, err error) {
|
||||
meta = &PostData{
|
||||
Name: name,
|
||||
Title: "TITLE HERE",
|
||||
PlusAuthor: plusRsc,
|
||||
PlusAPIKey: plusKey,
|
||||
HostURL: hostURL(req),
|
||||
}
|
||||
|
||||
art, fi, err := c.Read("blog/post/" + name)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if bytes.HasPrefix(art, []byte("{\n")) {
|
||||
i := bytes.Index(art, []byte("\n}\n"))
|
||||
if i < 0 {
|
||||
panic("cannot find end of json metadata")
|
||||
}
|
||||
hdr, rest := art[:i+3], art[i+3:]
|
||||
if err := json.Unmarshal(hdr, meta); err != nil {
|
||||
panic(fmt.Sprintf("loading %s: %s", name, err))
|
||||
}
|
||||
art = rest
|
||||
}
|
||||
meta.FileModTime = fi.ModTime
|
||||
meta.FileSize = fi.Size
|
||||
|
||||
return meta, replacer.Replace(string(art)), nil
|
||||
}
|
||||
|
||||
type byTime []*PostData
|
||||
|
||||
func (x byTime) Len() int { return len(x) }
|
||||
func (x byTime) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||
func (x byTime) Less(i, j int) bool { return x[i].Date.Time.After(x[j].Date.Time) }
|
||||
|
||||
type TocData struct {
|
||||
Draft bool
|
||||
HostURL string
|
||||
Posts []*PostData
|
||||
}
|
||||
|
||||
func toc(w http.ResponseWriter, req *http.Request, draft bool, isOwner bool, user string) {
|
||||
c := fs.NewContext(req)
|
||||
|
||||
var data []byte
|
||||
keystr := fmt.Sprintf("blog:toc:%v", draft)
|
||||
if req.FormValue("readdir") != "" {
|
||||
keystr += ",readdir=" + req.FormValue("readdir")
|
||||
}
|
||||
if draft {
|
||||
keystr += ",user="+user
|
||||
}
|
||||
|
||||
if key, ok := c.CacheLoad(keystr, "blog", &data); !ok {
|
||||
c := fs.NewContext(req)
|
||||
dir, err := c.ReadDir("blog/post")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if req.FormValue("readdir") == "1" {
|
||||
fmt.Fprintf(w, "%d dir entries\n", len(dir))
|
||||
return
|
||||
}
|
||||
|
||||
postCache := map[string]*PostData{}
|
||||
if data, _, err := c.Read("blogcache"); err == nil {
|
||||
if err := json.Unmarshal(data, &postCache); err != nil {
|
||||
c.Criticalf("unmarshal blogcache: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
ch := make(chan *PostData, len(dir))
|
||||
const par = 20
|
||||
var limit = make(chan bool, par)
|
||||
for i := 0; i < par; i++ {
|
||||
limit <- true
|
||||
}
|
||||
for _, d := range dir {
|
||||
if meta := postCache[d.Name]; meta != nil && meta.FileModTime.Equal(d.ModTime) && meta.FileSize == d.Size {
|
||||
ch <- meta
|
||||
continue
|
||||
}
|
||||
|
||||
<-limit
|
||||
go func(d proto.FileInfo) {
|
||||
defer func() { limit <- true }()
|
||||
meta, _, err := loadPost(c, d.Name, req)
|
||||
if err != nil {
|
||||
// Should not happen: we just listed the directory.
|
||||
c.Criticalf("loadPost %s: %v", d.Name, err)
|
||||
return
|
||||
}
|
||||
ch <- meta
|
||||
}(d)
|
||||
}
|
||||
for i := 0; i < par; i++ {
|
||||
<-limit
|
||||
}
|
||||
close(ch)
|
||||
postCache = map[string]*PostData{}
|
||||
var all []*PostData
|
||||
for meta := range ch {
|
||||
postCache[meta.Name] = meta
|
||||
if meta.IsDraft() == draft && (!draft || isOwner || meta.canRead(user)) {
|
||||
all = append(all, meta)
|
||||
}
|
||||
}
|
||||
sort.Sort(byTime(all))
|
||||
|
||||
if data, err := json.Marshal(postCache); err != nil {
|
||||
c.Criticalf("marshal blogcache: %v", err)
|
||||
} else if err := c.Write("blogcache", data); err != nil {
|
||||
c.Criticalf("write blogcache: %v", err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
t := mainTemplate(c)
|
||||
if err := t.Lookup("toc").Execute(&buf, &TocData{draft, hostURL(req), all}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
data = buf.Bytes()
|
||||
c.CacheStore(key, data)
|
||||
}
|
||||
w.Write(data)
|
||||
}
|
||||
|
||||
func oldRedirect(ctxt *fs.Context, w http.ResponseWriter, req *http.Request, p string) {
|
||||
m := map[string]string{}
|
||||
if key, ok := ctxt.CacheLoad("blog:oldRedirectMap", "blog/post", &m); !ok {
|
||||
dir, err := ctxt.ReadDir("blog/post")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, d := range dir {
|
||||
meta, _, err := loadPost(ctxt, d.Name, req)
|
||||
if err != nil {
|
||||
// Should not happen: we just listed the directory.
|
||||
panic(err)
|
||||
}
|
||||
m[meta.OldURL] = "/" + d.Name
|
||||
}
|
||||
|
||||
ctxt.CacheStore(key, m)
|
||||
}
|
||||
|
||||
if url, ok := m[p]; ok {
|
||||
http.Redirect(w, req, url, http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
notfound(ctxt, w, req)
|
||||
}
|
||||
|
||||
func hostURL(req *http.Request) string {
|
||||
if strings.HasPrefix(req.Host, "localhost") {
|
||||
return "http://localhost:8080"
|
||||
}
|
||||
return "http://research.swtch.com"
|
||||
}
|
||||
|
||||
func atomfeed(w http.ResponseWriter, req *http.Request) {
|
||||
c := fs.NewContext(req)
|
||||
|
||||
c.Criticalf("Header: %v", req.Header)
|
||||
|
||||
var data []byte
|
||||
if key, ok := c.CacheLoad("blog:atomfeed", "blog/post", &data); !ok {
|
||||
dir, err := c.ReadDir("blog/post")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var all []*PostData
|
||||
for _, d := range dir {
|
||||
meta, article, err := loadPost(c, d.Name, req)
|
||||
if err != nil {
|
||||
// Should not happen: we just loaded the directory.
|
||||
panic(err)
|
||||
}
|
||||
if meta.IsDraft() {
|
||||
continue
|
||||
}
|
||||
meta.article = article
|
||||
all = append(all, meta)
|
||||
}
|
||||
sort.Sort(byTime(all))
|
||||
|
||||
show := all
|
||||
if len(show) > 10 {
|
||||
show = show[:10]
|
||||
for _, meta := range all[10:] {
|
||||
if meta.Favorite {
|
||||
show = append(show, meta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
feed := &atom.Feed{
|
||||
Title: "research!rsc",
|
||||
ID: feedID,
|
||||
Updated: atom.Time(show[0].Date.Time),
|
||||
Author: &atom.Person{
|
||||
Name: "Russ Cox",
|
||||
URI: "https://plus.google.com/" + plusRsc,
|
||||
Email: "rsc@swtch.com",
|
||||
},
|
||||
Link: []atom.Link{
|
||||
{Rel: "self", Href: hostURL(req) + "/feed.atom"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, meta := range show {
|
||||
t := template.New("main")
|
||||
t.Funcs(funcMap)
|
||||
main, _, err := c.Read("blog/atom.html")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = t.Parse(string(main))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
template.Must(t.New("article").Parse(meta.article))
|
||||
var buf bytes.Buffer
|
||||
if err := t.Execute(&buf, meta); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
e := &atom.Entry{
|
||||
Title: meta.Title,
|
||||
ID: feed.ID + "/" + meta.Name,
|
||||
Link: []atom.Link{
|
||||
{Rel: "alternate", Href: meta.HostURL + "/" + meta.Name},
|
||||
},
|
||||
Published: atom.Time(meta.Date.Time),
|
||||
Updated: atom.Time(meta.Date.Time),
|
||||
Summary: &atom.Text{
|
||||
Type: "text",
|
||||
Body: meta.Summary,
|
||||
},
|
||||
Content: &atom.Text{
|
||||
Type: "html",
|
||||
Body: buf.String(),
|
||||
},
|
||||
}
|
||||
|
||||
feed.Entry = append(feed.Entry, e)
|
||||
}
|
||||
|
||||
data, err = xml.Marshal(&feed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.CacheStore(key, data)
|
||||
}
|
||||
|
||||
// Feed readers like to hammer us; let Google cache the
|
||||
// response to reduce the traffic we have to serve.
|
||||
httpCache(w, 15*time.Minute)
|
||||
|
||||
w.Header().Set("Content-Type", "application/atom+xml")
|
||||
w.Write(data)
|
||||
}
|
||||
|
||||
func httpCache(w http.ResponseWriter, dt time.Duration) {
|
||||
w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", int(dt.Seconds())))
|
||||
}
|
||||
34
vendor/github.com/mattermost/rsc/blog/post/qr.go
сгенерированный
поставляемый
34
vendor/github.com/mattermost/rsc/blog/post/qr.go
сгенерированный
поставляемый
@@ -1,34 +0,0 @@
|
||||
package post
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
|
||||
qrweb "github.com/mattermost/rsc/qr/web"
|
||||
)
|
||||
|
||||
func carp(f http.HandlerFunc) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
fmt.Fprintf(w, "<pre>\npanic: %s\n\n%s\n", err, debug.Stack())
|
||||
}
|
||||
}()
|
||||
f.ServeHTTP(w, req)
|
||||
})
|
||||
}
|
||||
|
||||
func init() {
|
||||
// http.Handle("/qr/bits", carp(qrweb.Bits))
|
||||
http.Handle("/qr/frame", carp(qrweb.Frame))
|
||||
http.Handle("/qr/frames", carp(qrweb.Frames))
|
||||
http.Handle("/qr/mask", carp(qrweb.Mask))
|
||||
http.Handle("/qr/masks", carp(qrweb.Masks))
|
||||
http.Handle("/qr/arrow", carp(qrweb.Arrow))
|
||||
http.Handle("/qr/draw", carp(qrweb.Draw))
|
||||
http.Handle("/qr/bitstable", carp(qrweb.BitsTable))
|
||||
http.Handle("/qr/encode", carp(qrweb.Encode))
|
||||
http.Handle("/qr/show/", carp(qrweb.Show))
|
||||
}
|
||||
79
vendor/github.com/mattermost/rsc/cmd/crypt/crypt.go
сгенерированный
поставляемый
79
vendor/github.com/mattermost/rsc/cmd/crypt/crypt.go
сгенерированный
поставляемый
@@ -1,79 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// Crypt is a simple password-based encryption program,
|
||||
// demonstrating how to use github.com/mattermost/rsc/crypt.
|
||||
//
|
||||
// Encrypt input to output using password:
|
||||
// crypt password <input >output
|
||||
//
|
||||
// Decrypt input to output using password:
|
||||
// crypt -d password <input >output
|
||||
//
|
||||
// Yes, the password is a command-line argument. This is a demo of the
|
||||
// github.com/mattermost/rsc/crypt package. It's not intended for real use.
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/rsc/crypt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
encrypt := true
|
||||
if len(args) >= 1 && args[0] == "-d" {
|
||||
encrypt = false
|
||||
args = args[1:]
|
||||
}
|
||||
if len(args) != 1 || strings.HasPrefix(args[0], "-") {
|
||||
fmt.Fprintf(os.Stderr, "usage: crypt [-d] password < input > output\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
password := args[0]
|
||||
|
||||
data, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "reading stdin: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if encrypt {
|
||||
pkt, err := crypt.Encrypt(password, data)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
str := base64.StdEncoding.EncodeToString(pkt)
|
||||
for len(str) > 60 {
|
||||
fmt.Printf("%s\n", str[:60])
|
||||
str = str[60:]
|
||||
}
|
||||
fmt.Printf("%s\n", str)
|
||||
} else {
|
||||
pkt, err := base64.StdEncoding.DecodeString(strings.Map(noSpace, string(data)))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "decoding input: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
dec, err := crypt.Decrypt(password, pkt)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Stdout.Write(dec)
|
||||
}
|
||||
}
|
||||
|
||||
func noSpace(r rune) rune {
|
||||
if r == ' ' || r == '\t' || r == '\n' {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}
|
||||
185
vendor/github.com/mattermost/rsc/cmd/issue/issue.go
сгенерированный
поставляемый
185
vendor/github.com/mattermost/rsc/cmd/issue/issue.go
сгенерированный
поставляемый
@@ -1,185 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, `usage: issue [-p project] query
|
||||
|
||||
If query is a single number, prints the full history for the issue.
|
||||
Otherwise, prints a table of matching results.
|
||||
The special query 'go1' is shorthand for 'Priority-Go1'.
|
||||
`)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
type Feed struct {
|
||||
Entry Entries `xml:"entry"`
|
||||
}
|
||||
|
||||
type Entry struct {
|
||||
ID string `xml:"id"`
|
||||
Title string `xml:"title"`
|
||||
Published time.Time `xml:"published"`
|
||||
Content string `xml:"content"`
|
||||
Updates []Update `xml:"updates"`
|
||||
Author struct {
|
||||
Name string `xml:"name"`
|
||||
} `xml:"author"`
|
||||
Owner string `xml:"owner"`
|
||||
Status string `xml:"status"`
|
||||
Label []string `xml:"label"`
|
||||
}
|
||||
|
||||
type Update struct {
|
||||
Summary string `xml:"summary"`
|
||||
Owner string `xml:"ownerUpdate"`
|
||||
Label string `xml:"label"`
|
||||
Status string `xml:"status"`
|
||||
}
|
||||
|
||||
type Entries []Entry
|
||||
|
||||
func (e Entries) Len() int { return len(e) }
|
||||
func (e Entries) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
|
||||
func (e Entries) Less(i, j int) bool { return e[i].Title < e[j].Title }
|
||||
|
||||
var project = flag.String("p", "go", "code.google.com project identifier")
|
||||
var v = flag.Bool("v", false, "verbose")
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
if flag.NArg() != 1 {
|
||||
usage()
|
||||
}
|
||||
|
||||
full := false
|
||||
q := flag.Arg(0)
|
||||
n, _ := strconv.Atoi(q)
|
||||
if n != 0 {
|
||||
q = "id:" + q
|
||||
full = true
|
||||
}
|
||||
if q == "go1" {
|
||||
q = "label:Priority-Go1"
|
||||
}
|
||||
|
||||
log.SetFlags(0)
|
||||
|
||||
query := url.Values{
|
||||
"q": {q},
|
||||
"max-results": {"400"},
|
||||
}
|
||||
if !full {
|
||||
query["can"] = []string{"open"}
|
||||
}
|
||||
u := "https://code.google.com/feeds/issues/p/" + *project + "/issues/full?" + query.Encode()
|
||||
if *v {
|
||||
log.Print(u)
|
||||
}
|
||||
r, err := http.Get(u)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var feed Feed
|
||||
if err := xml.NewDecoder(r.Body).Decode(&feed); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
r.Body.Close()
|
||||
|
||||
sort.Sort(feed.Entry)
|
||||
for _, e := range feed.Entry {
|
||||
id := e.ID
|
||||
if i := strings.Index(id, "id="); i >= 0 {
|
||||
id = id[:i+len("id=")]
|
||||
}
|
||||
fmt.Printf("%s\t%s\n", id, e.Title)
|
||||
if full {
|
||||
fmt.Printf("Reported by %s (%s)\n", e.Author.Name, e.Published.Format("2006-01-02 15:04:05"))
|
||||
if e.Owner != "" {
|
||||
fmt.Printf("\tOwner: %s\n", e.Owner)
|
||||
}
|
||||
if e.Status != "" {
|
||||
fmt.Printf("\tStatus: %s\n", e.Status)
|
||||
}
|
||||
for _, l := range e.Label {
|
||||
fmt.Printf("\tLabel: %s\n", l)
|
||||
}
|
||||
if e.Content != "" {
|
||||
fmt.Printf("\n\t%s\n", wrap(html.UnescapeString(e.Content), "\t"))
|
||||
}
|
||||
u := "https://code.google.com/feeds/issues/p/" + *project + "/issues/" + id + "/comments/full"
|
||||
if *v {
|
||||
log.Print(u)
|
||||
}
|
||||
r, err := http.Get(u)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var feed Feed
|
||||
if err := xml.NewDecoder(r.Body).Decode(&feed); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
r.Body.Close()
|
||||
|
||||
for _, e := range feed.Entry {
|
||||
fmt.Printf("\n%s (%s)\n", e.Title, e.Published.Format("2006-01-02 15:04:05"))
|
||||
for _, up := range e.Updates {
|
||||
if up.Summary != "" {
|
||||
fmt.Printf("\tSummary: %s\n", up.Summary)
|
||||
}
|
||||
if up.Owner != "" {
|
||||
fmt.Printf("\tOwner: %s\n", up.Owner)
|
||||
}
|
||||
if up.Status != "" {
|
||||
fmt.Printf("\tStatus: %s\n", up.Status)
|
||||
}
|
||||
if up.Label != "" {
|
||||
fmt.Printf("\tLabel: %s\n", up.Label)
|
||||
}
|
||||
}
|
||||
if e.Content != "" {
|
||||
fmt.Printf("\n\t%s\n", wrap(html.UnescapeString(e.Content), "\t"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func wrap(t string, prefix string) string {
|
||||
out := ""
|
||||
t = strings.Replace(t, "\r\n", "\n", -1)
|
||||
lines := strings.Split(t, "\n")
|
||||
for i, line := range lines {
|
||||
if i > 0 {
|
||||
out += "\n" + prefix
|
||||
}
|
||||
s := line
|
||||
for len(s) > 70 {
|
||||
i := strings.LastIndex(s[:70], " ")
|
||||
if i < 0 {
|
||||
i = 69
|
||||
}
|
||||
i++
|
||||
out += s[:i] + "\n" + prefix
|
||||
s = s[i:]
|
||||
}
|
||||
out += s
|
||||
}
|
||||
return out
|
||||
}
|
||||
37
vendor/github.com/mattermost/rsc/cmd/jfmt/main.go
сгенерированный
поставляемый
37
vendor/github.com/mattermost/rsc/cmd/jfmt/main.go
сгенерированный
поставляемый
@@ -1,37 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// jfmt reads JSON from standard input, formats it, and writes it to standard output.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
|
||||
if len(os.Args) > 1 {
|
||||
fmt.Fprintf(os.Stderr, "usage: json < input > output\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
// TODO: Can do on the fly.
|
||||
|
||||
data, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
json.Indent(&buf, data, "", " ")
|
||||
buf.WriteByte('\n')
|
||||
|
||||
os.Stdout.Write(buf.Bytes())
|
||||
}
|
||||
150
vendor/github.com/mattermost/rsc/crypt/crypt.go
сгенерированный
поставляемый
150
vendor/github.com/mattermost/rsc/crypt/crypt.go
сгенерированный
поставляемый
@@ -1,150 +0,0 @@
|
||||
// Copyright 2012 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 crypt provides simple, password-based encryption and decryption of data blobs.
|
||||
package crypt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"code.google.com/p/go.crypto/pbkdf2"
|
||||
)
|
||||
|
||||
// This program manipulates encrypted, signed packets with the following format:
|
||||
// 1 byte version
|
||||
// 8 byte salt
|
||||
// 4 byte key hash
|
||||
// aes.BlockSize-byte IV
|
||||
// aes.BlockSize-byte encryption (maybe longer)
|
||||
// sha1.Size-byte HMAC signature
|
||||
|
||||
const version = 0
|
||||
|
||||
// deriveKey returns the AES key, HMAC-SHA1 key, and key hash for
|
||||
// the given password, salt combination.
|
||||
func deriveKey(password string, salt []byte) (aesKey, hmacKey, keyHash []byte) {
|
||||
const keySize = 16
|
||||
key := pbkdf2.Key([]byte(password), salt, 4096, 2*keySize, sha1.New)
|
||||
aesKey = key[:keySize]
|
||||
hmacKey = key[keySize:]
|
||||
h := sha1.New()
|
||||
h.Write(key)
|
||||
keyHash = h.Sum(nil)[:4]
|
||||
return
|
||||
}
|
||||
|
||||
// Encrypt encrypts the plaintext into an encrypted packet
|
||||
// using the given password. The password is required for
|
||||
// decryption.
|
||||
func Encrypt(password string, plaintext []byte) (encrypted []byte, err error) {
|
||||
// Derive key material from password and salt.
|
||||
salt := make([]byte, 8)
|
||||
_, err = io.ReadFull(rand.Reader, salt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aesKey, hmacKey, keyHash := deriveKey(password, salt)
|
||||
|
||||
// Pad.
|
||||
n := aes.BlockSize - len(plaintext)%aes.BlockSize
|
||||
dec := make([]byte, len(plaintext)+n)
|
||||
copy(dec, plaintext)
|
||||
for i := len(plaintext); i < len(dec); i++ {
|
||||
dec[i] = byte(n)
|
||||
}
|
||||
|
||||
// Encrypt.
|
||||
iv := make([]byte, aes.BlockSize)
|
||||
_, err = io.ReadFull(rand.Reader, iv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aesBlock, err := aes.NewCipher(aesKey)
|
||||
if err != nil {
|
||||
// Cannot happen - key is right size.
|
||||
panic("aes: " + err.Error())
|
||||
}
|
||||
m := cipher.NewCBCEncrypter(aesBlock, iv)
|
||||
enc := make([]byte, len(dec))
|
||||
m.CryptBlocks(enc, dec)
|
||||
|
||||
// Construct packet.
|
||||
var pkt []byte
|
||||
pkt = append(pkt, version)
|
||||
pkt = append(pkt, salt...)
|
||||
pkt = append(pkt, keyHash...)
|
||||
pkt = append(pkt, iv...)
|
||||
pkt = append(pkt, enc...)
|
||||
|
||||
// Sign.
|
||||
h := hmac.New(sha1.New, hmacKey)
|
||||
h.Write(pkt)
|
||||
pkt = append(pkt, h.Sum(nil)...)
|
||||
|
||||
return pkt, nil
|
||||
}
|
||||
|
||||
// Decrypt decrypts the encrypted packet using the given password.
|
||||
// It returns the decrypted data.
|
||||
func Decrypt(password string, encrypted []byte) (plaintext []byte, err error) {
|
||||
// Pull apart packet.
|
||||
pkt := encrypted
|
||||
if len(pkt) < 1+8+4+2*aes.BlockSize+sha1.Size {
|
||||
return nil, fmt.Errorf("encrypted packet too short")
|
||||
}
|
||||
vers, pkt := pkt[:1], pkt[1:]
|
||||
salt, pkt := pkt[:8], pkt[8:]
|
||||
hash, pkt := pkt[:4], pkt[4:]
|
||||
iv, pkt := pkt[:aes.BlockSize], pkt[aes.BlockSize:]
|
||||
enc, sig := pkt[:len(pkt)-sha1.Size], pkt[len(pkt)-sha1.Size:]
|
||||
|
||||
if vers[0] != version || len(enc)%aes.BlockSize != 0 {
|
||||
return nil, fmt.Errorf("malformed encrypted packet")
|
||||
}
|
||||
|
||||
// Derive key and check against hash.
|
||||
aesKey, hmacKey, keyHash := deriveKey(password, salt)
|
||||
if !bytes.Equal(hash, keyHash) {
|
||||
return nil, fmt.Errorf("incorrect password - %x vs %x", hash, keyHash)
|
||||
}
|
||||
|
||||
// Verify signature.
|
||||
h := hmac.New(sha1.New, hmacKey)
|
||||
h.Write(encrypted[:len(encrypted)-len(sig)])
|
||||
if !bytes.Equal(sig, h.Sum(nil)) {
|
||||
return nil, fmt.Errorf("cannot authenticate encrypted packet")
|
||||
}
|
||||
|
||||
// Decrypt.
|
||||
aesBlock, err := aes.NewCipher(aesKey)
|
||||
if err != nil {
|
||||
// Cannot happen - key is right size.
|
||||
panic("aes: " + err.Error())
|
||||
}
|
||||
m := cipher.NewCBCDecrypter(aesBlock, iv)
|
||||
dec := make([]byte, len(enc))
|
||||
m.CryptBlocks(dec, enc)
|
||||
|
||||
// Unpad.
|
||||
pad := dec[len(dec)-1]
|
||||
if pad <= 0 || pad > aes.BlockSize {
|
||||
return nil, fmt.Errorf("malformed packet padding")
|
||||
}
|
||||
for _, b := range dec[len(dec)-int(pad):] {
|
||||
if b != pad {
|
||||
return nil, fmt.Errorf("malformed packet padding")
|
||||
}
|
||||
}
|
||||
dec = dec[:len(dec)-int(pad)]
|
||||
|
||||
// Success!
|
||||
return dec, nil
|
||||
}
|
||||
317
vendor/github.com/mattermost/rsc/devweb/main.go
сгенерированный
поставляемый
317
vendor/github.com/mattermost/rsc/devweb/main.go
сгенерированный
поставляемый
@@ -1,317 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Devweb is a simple environment for developing a web server.
|
||||
// It runs its own web server on the given address and proxies
|
||||
// all requests to the http server program named by importpath.
|
||||
// It takes care of recompiling and restarting the program as needed.
|
||||
//
|
||||
// The server program should be a trivial main program like:
|
||||
//
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// "github.com/mattermost/rsc/devweb/slave"
|
||||
//
|
||||
// _ "this/package"
|
||||
// _ "that/package"
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
// slave.Main()
|
||||
// }
|
||||
//
|
||||
// The import _ lines import packages that register HTTP handlers,
|
||||
// like in an App Engine program.
|
||||
//
|
||||
// As you make changes to this/package or that/package (or their
|
||||
// dependencies), devweb recompiles and relaunches the servers as
|
||||
// needed to serve requests.
|
||||
//
|
||||
package main
|
||||
|
||||
// BUG(rsc): Devweb should probably
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprint(os.Stderr, `usage: devweb [-addr :8000] importpath
|
||||
|
||||
Devweb runs a web server on the given address and proxies all requests
|
||||
to the http server program named by importpath. It takes care of
|
||||
recompiling and restarting the program as needed.
|
||||
|
||||
The http server program must itself have a -addr argument that
|
||||
says which TCP port to listen on.
|
||||
`,
|
||||
)
|
||||
}
|
||||
|
||||
var addr = flag.String("addr", ":8000", "web service address")
|
||||
var rootPackage string
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
args := flag.Args()
|
||||
if len(args) != 1 {
|
||||
usage()
|
||||
}
|
||||
rootPackage = args[0]
|
||||
|
||||
log.Fatal(http.ListenAndServe(*addr, http.HandlerFunc(relay)))
|
||||
}
|
||||
|
||||
func relay(w http.ResponseWriter, req *http.Request) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
http.Error(w, fmt.Sprint(err), 200)
|
||||
}
|
||||
}()
|
||||
|
||||
c, proxy, err := buildProxy()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer c.Close()
|
||||
_ = proxy
|
||||
|
||||
outreq := new(http.Request)
|
||||
*outreq = *req // includes shallow copies of maps, but okay
|
||||
|
||||
outreq.Proto = "HTTP/1.1"
|
||||
outreq.ProtoMajor = 1
|
||||
outreq.ProtoMinor = 1
|
||||
outreq.Close = false
|
||||
|
||||
// Remove the connection header to the backend. We want a
|
||||
// persistent connection, regardless of what the client sent
|
||||
// to us. This is modifying the same underlying map from req
|
||||
// (shallow copied above) so we only copy it if necessary.
|
||||
if outreq.Header.Get("Connection") != "" {
|
||||
outreq.Header = make(http.Header)
|
||||
copyHeader(outreq.Header, req.Header)
|
||||
outreq.Header.Del("Connection")
|
||||
}
|
||||
|
||||
outreq.Write(c)
|
||||
|
||||
br := bufio.NewReader(c)
|
||||
resp, err := http.ReadResponse(br, outreq)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
copyHeader(w.Header(), resp.Header)
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
|
||||
if resp.Body != nil {
|
||||
io.Copy(w, resp.Body)
|
||||
}
|
||||
}
|
||||
|
||||
func copyHeader(dst, src http.Header) {
|
||||
for k, vv := range src {
|
||||
for _, v := range vv {
|
||||
dst.Add(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type cmdProxy struct {
|
||||
cmd *exec.Cmd
|
||||
addr string
|
||||
}
|
||||
|
||||
func (p *cmdProxy) kill() {
|
||||
if p == nil {
|
||||
return
|
||||
}
|
||||
p.cmd.Process.Kill()
|
||||
p.cmd.Wait()
|
||||
}
|
||||
|
||||
var proxyInfo struct {
|
||||
sync.Mutex
|
||||
build time.Time
|
||||
check time.Time
|
||||
active *cmdProxy
|
||||
err error
|
||||
}
|
||||
|
||||
func buildProxy() (c net.Conn, proxy *cmdProxy, err error) {
|
||||
p := &proxyInfo
|
||||
|
||||
t := time.Now()
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
if t.Before(p.check) {
|
||||
// We waited for the lock while someone else dialed.
|
||||
// If we can connect, done.
|
||||
if p.active != nil {
|
||||
if c, err := net.DialTimeout("tcp", p.active.addr, 5*time.Second); err == nil {
|
||||
return c, p.active, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
defer func() {
|
||||
p.err = err
|
||||
p.check = time.Now()
|
||||
}()
|
||||
|
||||
pkgs, err := loadPackage(rootPackage)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("load %s: %s", rootPackage, err)
|
||||
}
|
||||
|
||||
deps := pkgs[0].Deps
|
||||
if len(deps) > 0 && deps[0] == "C" {
|
||||
deps = deps[1:]
|
||||
}
|
||||
pkgs1, err := loadPackage(deps...)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("load %v: %s", deps, err)
|
||||
}
|
||||
pkgs = append(pkgs, pkgs1...)
|
||||
|
||||
var latest time.Time
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
var files []string
|
||||
files = append(files, pkg.GoFiles...)
|
||||
files = append(files, pkg.CFiles...)
|
||||
files = append(files, pkg.HFiles...)
|
||||
files = append(files, pkg.SFiles...)
|
||||
files = append(files, pkg.CgoFiles...)
|
||||
|
||||
for _, file := range files {
|
||||
if fi, err := os.Stat(filepath.Join(pkg.Dir, file)); err == nil && fi.ModTime().After(latest) {
|
||||
latest = fi.ModTime()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if latest.After(p.build) {
|
||||
p.active.kill()
|
||||
p.active = nil
|
||||
|
||||
out, err := exec.Command("go", "build", "-o", "prox.exe", rootPackage).CombinedOutput()
|
||||
if len(out) > 0 {
|
||||
return nil, nil, fmt.Errorf("%s", out)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
p.build = latest
|
||||
}
|
||||
|
||||
// If we can connect, done.
|
||||
if p.active != nil {
|
||||
if c, err := net.DialTimeout("tcp", p.active.addr, 5*time.Second); err == nil {
|
||||
return c, p.active, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, start a new server.
|
||||
p.active.kill()
|
||||
p.active = nil
|
||||
|
||||
l, err := net.Listen("tcp", "localhost:0")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
addr := l.Addr().String()
|
||||
|
||||
cmd := exec.Command("prox.exe", "LISTEN_STDIN")
|
||||
cmd.Stdin, err = l.(*net.TCPListener).File()
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
if err != nil {
|
||||
l.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
err = cmd.Start()
|
||||
l.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
c, err = net.DialTimeout("tcp", addr, 5*time.Second)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
p.active = &cmdProxy{cmd, addr}
|
||||
return c, p.active, nil
|
||||
}
|
||||
|
||||
type Pkg struct {
|
||||
ImportPath string
|
||||
Dir string
|
||||
GoFiles []string
|
||||
CFiles []string
|
||||
HFiles []string
|
||||
SFiles []string
|
||||
CgoFiles []string
|
||||
Deps []string
|
||||
}
|
||||
|
||||
func loadPackage(name ...string) ([]*Pkg, error) {
|
||||
args := []string{"list", "-json"}
|
||||
args = append(args, name...)
|
||||
var stderr bytes.Buffer
|
||||
cmd := exec.Command("go", args...)
|
||||
r, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Start(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dec := json.NewDecoder(r)
|
||||
var pkgs []*Pkg
|
||||
for {
|
||||
p := new(Pkg)
|
||||
if err := dec.Decode(p); err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
cmd.Process.Kill()
|
||||
return nil, err
|
||||
}
|
||||
pkgs = append(pkgs, p)
|
||||
}
|
||||
|
||||
err = cmd.Wait()
|
||||
if b := stderr.Bytes(); len(b) > 0 {
|
||||
return nil, fmt.Errorf("%s", b)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(pkgs) != len(name) {
|
||||
return nil, fmt.Errorf("found fewer packages than expected")
|
||||
}
|
||||
return pkgs, nil
|
||||
}
|
||||
26
vendor/github.com/mattermost/rsc/devweb/slave/slave.go
сгенерированный
поставляемый
26
vendor/github.com/mattermost/rsc/devweb/slave/slave.go
сгенерированный
поставляемый
@@ -1,26 +0,0 @@
|
||||
// Copyright 2011 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 slave
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func Main() {
|
||||
if len(os.Args) != 2 || os.Args[1] != "LISTEN_STDIN" {
|
||||
fmt.Fprintf(os.Stderr, "devweb slave must be invoked by devweb\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
l, err := net.FileListener(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Stdin.Close()
|
||||
log.Fatal(http.Serve(l, nil))
|
||||
}
|
||||
20
vendor/github.com/mattermost/rsc/fuse/debug.go
сгенерированный
поставляемый
20
vendor/github.com/mattermost/rsc/fuse/debug.go
сгенерированный
поставляемый
@@ -1,20 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// FUSE service loop, for servers that wish to use it.
|
||||
|
||||
package fuse
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func stack() string {
|
||||
buf := make([]byte, 1024)
|
||||
return string(buf[:runtime.Stack(buf, false)])
|
||||
}
|
||||
|
||||
var Debugf = nop
|
||||
|
||||
func nop(string, ...interface{}) {}
|
||||
1650
vendor/github.com/mattermost/rsc/fuse/fuse.go
сгенерированный
поставляемый
1650
vendor/github.com/mattermost/rsc/fuse/fuse.go
сгенерированный
поставляемый
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
539
vendor/github.com/mattermost/rsc/fuse/fuse_kernel.go
сгенерированный
поставляемый
539
vendor/github.com/mattermost/rsc/fuse/fuse_kernel.go
сгенерированный
поставляемый
@@ -1,539 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Derived from FUSE's fuse_kernel.h
|
||||
/*
|
||||
This file defines the kernel interface of FUSE
|
||||
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
||||
|
||||
|
||||
This -- and only this -- header file may also be distributed under
|
||||
the terms of the BSD Licence as follows:
|
||||
|
||||
Copyright (C) 2001-2007 Miklos Szeredi. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. 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.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY AUTHOR 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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
package fuse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Version is the FUSE version implemented by the package.
|
||||
const Version = "7.8"
|
||||
|
||||
const (
|
||||
kernelVersion = 7
|
||||
kernelMinorVersion = 8
|
||||
rootID = 1
|
||||
)
|
||||
|
||||
type kstatfs struct {
|
||||
Blocks uint64
|
||||
Bfree uint64
|
||||
Bavail uint64
|
||||
Files uint64
|
||||
Ffree uint64
|
||||
Bsize uint32
|
||||
Namelen uint32
|
||||
Frsize uint32
|
||||
Padding uint32
|
||||
Spare [6]uint32
|
||||
}
|
||||
|
||||
type fileLock struct {
|
||||
Start uint64
|
||||
End uint64
|
||||
Type uint32
|
||||
Pid uint32
|
||||
}
|
||||
|
||||
// The SetattrValid are bit flags describing which fields in the SetattrRequest
|
||||
// are included in the change.
|
||||
type SetattrValid uint32
|
||||
|
||||
const (
|
||||
SetattrMode SetattrValid = 1 << 0
|
||||
SetattrUid SetattrValid = 1 << 1
|
||||
SetattrGid SetattrValid = 1 << 2
|
||||
SetattrSize SetattrValid = 1 << 3
|
||||
SetattrAtime SetattrValid = 1 << 4
|
||||
SetattrMtime SetattrValid = 1 << 5
|
||||
SetattrHandle SetattrValid = 1 << 6 // TODO: What does this mean?
|
||||
|
||||
// Linux only(?)
|
||||
SetattrAtimeNow SetattrValid = 1 << 7
|
||||
SetattrMtimeNow SetattrValid = 1 << 8
|
||||
SetattrLockOwner SetattrValid = 1 << 9 // http://www.mail-archive.com/git-commits-head@vger.kernel.org/msg27852.html
|
||||
|
||||
// OS X only
|
||||
SetattrCrtime SetattrValid = 1 << 28
|
||||
SetattrChgtime SetattrValid = 1 << 29
|
||||
SetattrBkuptime SetattrValid = 1 << 30
|
||||
SetattrFlags SetattrValid = 1 << 31
|
||||
)
|
||||
|
||||
func (fl SetattrValid) Mode() bool { return fl&SetattrMode != 0 }
|
||||
func (fl SetattrValid) Uid() bool { return fl&SetattrUid != 0 }
|
||||
func (fl SetattrValid) Gid() bool { return fl&SetattrGid != 0 }
|
||||
func (fl SetattrValid) Size() bool { return fl&SetattrSize != 0 }
|
||||
func (fl SetattrValid) Atime() bool { return fl&SetattrAtime != 0 }
|
||||
func (fl SetattrValid) Mtime() bool { return fl&SetattrMtime != 0 }
|
||||
func (fl SetattrValid) Handle() bool { return fl&SetattrHandle != 0 }
|
||||
func (fl SetattrValid) Crtime() bool { return fl&SetattrCrtime != 0 }
|
||||
func (fl SetattrValid) Chgtime() bool { return fl&SetattrChgtime != 0 }
|
||||
func (fl SetattrValid) Bkuptime() bool { return fl&SetattrBkuptime != 0 }
|
||||
func (fl SetattrValid) Flags() bool { return fl&SetattrFlags != 0 }
|
||||
|
||||
func (fl SetattrValid) String() string {
|
||||
return flagString(uint32(fl), setattrValidNames)
|
||||
}
|
||||
|
||||
var setattrValidNames = []flagName{
|
||||
{uint32(SetattrMode), "SetattrMode"},
|
||||
{uint32(SetattrUid), "SetattrUid"},
|
||||
{uint32(SetattrGid), "SetattrGid"},
|
||||
{uint32(SetattrSize), "SetattrSize"},
|
||||
{uint32(SetattrAtime), "SetattrAtime"},
|
||||
{uint32(SetattrMtime), "SetattrMtime"},
|
||||
{uint32(SetattrHandle), "SetattrHandle"},
|
||||
{uint32(SetattrCrtime), "SetattrCrtime"},
|
||||
{uint32(SetattrChgtime), "SetattrChgtime"},
|
||||
{uint32(SetattrBkuptime), "SetattrBkuptime"},
|
||||
{uint32(SetattrFlags), "SetattrFlags"},
|
||||
}
|
||||
|
||||
// The OpenFlags are returned in the OpenResponse.
|
||||
type OpenFlags uint32
|
||||
|
||||
const (
|
||||
OpenDirectIO OpenFlags = 1 << 0 // bypass page cache for this open file
|
||||
OpenKeepCache OpenFlags = 1 << 1 // don't invalidate the data cache on open
|
||||
OpenNonSeekable OpenFlags = 1 << 2 // (Linux?)
|
||||
|
||||
OpenPurgeAttr OpenFlags = 1 << 30 // OS X
|
||||
OpenPurgeUBC OpenFlags = 1 << 31 // OS X
|
||||
)
|
||||
|
||||
func (fl OpenFlags) String() string {
|
||||
return flagString(uint32(fl), openFlagNames)
|
||||
}
|
||||
|
||||
var openFlagNames = []flagName{
|
||||
{uint32(OpenDirectIO), "OpenDirectIO"},
|
||||
{uint32(OpenKeepCache), "OpenKeepCache"},
|
||||
{uint32(OpenPurgeAttr), "OpenPurgeAttr"},
|
||||
{uint32(OpenPurgeUBC), "OpenPurgeUBC"},
|
||||
}
|
||||
|
||||
// The InitFlags are used in the Init exchange.
|
||||
type InitFlags uint32
|
||||
|
||||
const (
|
||||
InitAsyncRead InitFlags = 1 << 0
|
||||
InitPosixLocks InitFlags = 1 << 1
|
||||
|
||||
InitCaseSensitive InitFlags = 1 << 29 // OS X only
|
||||
InitVolRename InitFlags = 1 << 30 // OS X only
|
||||
InitXtimes InitFlags = 1 << 31 // OS X only
|
||||
)
|
||||
|
||||
type flagName struct {
|
||||
bit uint32
|
||||
name string
|
||||
}
|
||||
|
||||
var initFlagNames = []flagName{
|
||||
{uint32(InitAsyncRead), "InitAsyncRead"},
|
||||
{uint32(InitPosixLocks), "InitPosixLocks"},
|
||||
{uint32(InitCaseSensitive), "InitCaseSensitive"},
|
||||
{uint32(InitVolRename), "InitVolRename"},
|
||||
{uint32(InitXtimes), "InitXtimes"},
|
||||
}
|
||||
|
||||
func (fl InitFlags) String() string {
|
||||
return flagString(uint32(fl), initFlagNames)
|
||||
}
|
||||
|
||||
func flagString(f uint32, names []flagName) string {
|
||||
var s string
|
||||
|
||||
if f == 0 {
|
||||
return "0"
|
||||
}
|
||||
|
||||
for _, n := range names {
|
||||
if f&n.bit != 0 {
|
||||
s += "+" + n.name
|
||||
f &^= n.bit
|
||||
}
|
||||
}
|
||||
if f != 0 {
|
||||
s += fmt.Sprintf("%+#x", f)
|
||||
}
|
||||
return s[1:]
|
||||
}
|
||||
|
||||
// The ReleaseFlags are used in the Release exchange.
|
||||
type ReleaseFlags uint32
|
||||
|
||||
const (
|
||||
ReleaseFlush ReleaseFlags = 1 << 0
|
||||
)
|
||||
|
||||
func (fl ReleaseFlags) String() string {
|
||||
return flagString(uint32(fl), releaseFlagNames)
|
||||
}
|
||||
|
||||
var releaseFlagNames = []flagName{
|
||||
{uint32(ReleaseFlush), "ReleaseFlush"},
|
||||
}
|
||||
|
||||
// Opcodes
|
||||
const (
|
||||
opLookup = 1
|
||||
opForget = 2 // no reply
|
||||
opGetattr = 3
|
||||
opSetattr = 4
|
||||
opReadlink = 5
|
||||
opSymlink = 6
|
||||
opMknod = 8
|
||||
opMkdir = 9
|
||||
opUnlink = 10
|
||||
opRmdir = 11
|
||||
opRename = 12
|
||||
opLink = 13
|
||||
opOpen = 14
|
||||
opRead = 15
|
||||
opWrite = 16
|
||||
opStatfs = 17
|
||||
opRelease = 18
|
||||
opFsync = 20
|
||||
opSetxattr = 21
|
||||
opGetxattr = 22
|
||||
opListxattr = 23
|
||||
opRemovexattr = 24
|
||||
opFlush = 25
|
||||
opInit = 26
|
||||
opOpendir = 27
|
||||
opReaddir = 28
|
||||
opReleasedir = 29
|
||||
opFsyncdir = 30
|
||||
opGetlk = 31
|
||||
opSetlk = 32
|
||||
opSetlkw = 33
|
||||
opAccess = 34
|
||||
opCreate = 35
|
||||
opInterrupt = 36
|
||||
opBmap = 37
|
||||
opDestroy = 38
|
||||
opIoctl = 39 // Linux?
|
||||
opPoll = 40 // Linux?
|
||||
|
||||
// OS X
|
||||
opSetvolname = 61
|
||||
opGetxtimes = 62
|
||||
opExchange = 63
|
||||
)
|
||||
|
||||
// The read buffer is required to be at least 8k but may be much larger
|
||||
const minReadBuffer = 8192
|
||||
|
||||
type entryOut struct {
|
||||
outHeader
|
||||
Nodeid uint64 // Inode ID
|
||||
Generation uint64 // Inode generation
|
||||
EntryValid uint64 // Cache timeout for the name
|
||||
AttrValid uint64 // Cache timeout for the attributes
|
||||
EntryValidNsec uint32
|
||||
AttrValidNsec uint32
|
||||
Attr attr
|
||||
}
|
||||
|
||||
type forgetIn struct {
|
||||
Nlookup uint64
|
||||
}
|
||||
|
||||
type attrOut struct {
|
||||
outHeader
|
||||
AttrValid uint64 // Cache timeout for the attributes
|
||||
AttrValidNsec uint32
|
||||
Dummy uint32
|
||||
Attr attr
|
||||
}
|
||||
|
||||
// OS X
|
||||
type getxtimesOut struct {
|
||||
outHeader
|
||||
Bkuptime uint64
|
||||
Crtime uint64
|
||||
BkuptimeNsec uint32
|
||||
CrtimeNsec uint32
|
||||
}
|
||||
|
||||
type mknodIn struct {
|
||||
Mode uint32
|
||||
Rdev uint32
|
||||
// "filename\x00" follows.
|
||||
}
|
||||
|
||||
type mkdirIn struct {
|
||||
Mode uint32
|
||||
Padding uint32
|
||||
// filename follows
|
||||
}
|
||||
|
||||
type renameIn struct {
|
||||
Newdir uint64
|
||||
// "oldname\x00newname\x00" follows
|
||||
}
|
||||
|
||||
// OS X
|
||||
type exchangeIn struct {
|
||||
Olddir uint64
|
||||
Newdir uint64
|
||||
Options uint64
|
||||
}
|
||||
|
||||
type linkIn struct {
|
||||
Oldnodeid uint64
|
||||
}
|
||||
|
||||
type setattrInCommon struct {
|
||||
Valid uint32
|
||||
Padding uint32
|
||||
Fh uint64
|
||||
Size uint64
|
||||
LockOwner uint64 // unused on OS X?
|
||||
Atime uint64
|
||||
Mtime uint64
|
||||
Unused2 uint64
|
||||
AtimeNsec uint32
|
||||
MtimeNsec uint32
|
||||
Unused3 uint32
|
||||
Mode uint32
|
||||
Unused4 uint32
|
||||
Uid uint32
|
||||
Gid uint32
|
||||
Unused5 uint32
|
||||
}
|
||||
|
||||
type openIn struct {
|
||||
Flags uint32
|
||||
Mode uint32
|
||||
}
|
||||
|
||||
type openOut struct {
|
||||
outHeader
|
||||
Fh uint64
|
||||
OpenFlags uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type createOut struct {
|
||||
outHeader
|
||||
|
||||
Nodeid uint64 // Inode ID
|
||||
Generation uint64 // Inode generation
|
||||
EntryValid uint64 // Cache timeout for the name
|
||||
AttrValid uint64 // Cache timeout for the attributes
|
||||
EntryValidNsec uint32
|
||||
AttrValidNsec uint32
|
||||
Attr attr
|
||||
|
||||
Fh uint64
|
||||
OpenFlags uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type releaseIn struct {
|
||||
Fh uint64
|
||||
Flags uint32
|
||||
ReleaseFlags uint32
|
||||
LockOwner uint32
|
||||
}
|
||||
|
||||
type flushIn struct {
|
||||
Fh uint64
|
||||
FlushFlags uint32
|
||||
Padding uint32
|
||||
LockOwner uint64
|
||||
}
|
||||
|
||||
type readIn struct {
|
||||
Fh uint64
|
||||
Offset uint64
|
||||
Size uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type writeIn struct {
|
||||
Fh uint64
|
||||
Offset uint64
|
||||
Size uint32
|
||||
WriteFlags uint32
|
||||
}
|
||||
|
||||
type writeOut struct {
|
||||
outHeader
|
||||
Size uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
// The WriteFlags are returned in the WriteResponse.
|
||||
type WriteFlags uint32
|
||||
|
||||
func (fl WriteFlags) String() string {
|
||||
return flagString(uint32(fl), writeFlagNames)
|
||||
}
|
||||
|
||||
var writeFlagNames = []flagName{}
|
||||
|
||||
const compatStatfsSize = 48
|
||||
|
||||
type statfsOut struct {
|
||||
outHeader
|
||||
St kstatfs
|
||||
}
|
||||
|
||||
type fsyncIn struct {
|
||||
Fh uint64
|
||||
FsyncFlags uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type setxattrIn struct {
|
||||
Size uint32
|
||||
Flags uint32
|
||||
}
|
||||
|
||||
type setxattrInOSX struct {
|
||||
Size uint32
|
||||
Flags uint32
|
||||
|
||||
// OS X only
|
||||
Position uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type getxattrIn struct {
|
||||
Size uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type getxattrInOSX struct {
|
||||
Size uint32
|
||||
Padding uint32
|
||||
|
||||
// OS X only
|
||||
Position uint32
|
||||
Padding2 uint32
|
||||
}
|
||||
|
||||
type getxattrOut struct {
|
||||
outHeader
|
||||
Size uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type lkIn struct {
|
||||
Fh uint64
|
||||
Owner uint64
|
||||
Lk fileLock
|
||||
}
|
||||
|
||||
type lkOut struct {
|
||||
outHeader
|
||||
Lk fileLock
|
||||
}
|
||||
|
||||
type accessIn struct {
|
||||
Mask uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type initIn struct {
|
||||
Major uint32
|
||||
Minor uint32
|
||||
MaxReadahead uint32
|
||||
Flags uint32
|
||||
}
|
||||
|
||||
const initInSize = int(unsafe.Sizeof(initIn{}))
|
||||
|
||||
type initOut struct {
|
||||
outHeader
|
||||
Major uint32
|
||||
Minor uint32
|
||||
MaxReadahead uint32
|
||||
Flags uint32
|
||||
Unused uint32
|
||||
MaxWrite uint32
|
||||
}
|
||||
|
||||
type interruptIn struct {
|
||||
Unique uint64
|
||||
}
|
||||
|
||||
type bmapIn struct {
|
||||
Block uint64
|
||||
BlockSize uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
type bmapOut struct {
|
||||
outHeader
|
||||
Block uint64
|
||||
}
|
||||
|
||||
type inHeader struct {
|
||||
Len uint32
|
||||
Opcode uint32
|
||||
Unique uint64
|
||||
Nodeid uint64
|
||||
Uid uint32
|
||||
Gid uint32
|
||||
Pid uint32
|
||||
Padding uint32
|
||||
}
|
||||
|
||||
const inHeaderSize = int(unsafe.Sizeof(inHeader{}))
|
||||
|
||||
type outHeader struct {
|
||||
Len uint32
|
||||
Error int32
|
||||
Unique uint64
|
||||
}
|
||||
|
||||
type dirent struct {
|
||||
Ino uint64
|
||||
Off uint64
|
||||
Namelen uint32
|
||||
Type uint32
|
||||
Name [0]byte
|
||||
}
|
||||
|
||||
const direntSize = 8 + 8 + 4 + 4
|
||||
58
vendor/github.com/mattermost/rsc/fuse/fuse_kernel_darwin.go
сгенерированный
поставляемый
58
vendor/github.com/mattermost/rsc/fuse/fuse_kernel_darwin.go
сгенерированный
поставляемый
@@ -1,58 +0,0 @@
|
||||
package fuse
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type attr struct {
|
||||
Ino uint64
|
||||
Size uint64
|
||||
Blocks uint64
|
||||
Atime uint64
|
||||
Mtime uint64
|
||||
Ctime uint64
|
||||
Crtime_ uint64 // OS X only
|
||||
AtimeNsec uint32
|
||||
MtimeNsec uint32
|
||||
CtimeNsec uint32
|
||||
CrtimeNsec uint32 // OS X only
|
||||
Mode uint32
|
||||
Nlink uint32
|
||||
Uid uint32
|
||||
Gid uint32
|
||||
Rdev uint32
|
||||
Flags_ uint32 // OS X only; see chflags(2)
|
||||
}
|
||||
|
||||
func (a *attr) SetCrtime(s uint64, ns uint32) {
|
||||
a.Crtime_, a.CrtimeNsec = s, ns
|
||||
}
|
||||
|
||||
func (a *attr) SetFlags(f uint32) {
|
||||
a.Flags_ = f
|
||||
}
|
||||
|
||||
type setattrIn struct {
|
||||
setattrInCommon
|
||||
|
||||
// OS X only
|
||||
Bkuptime_ uint64
|
||||
Chgtime_ uint64
|
||||
Crtime uint64
|
||||
BkuptimeNsec uint32
|
||||
ChgtimeNsec uint32
|
||||
CrtimeNsec uint32
|
||||
Flags_ uint32 // see chflags(2)
|
||||
}
|
||||
|
||||
func (in *setattrIn) BkupTime() time.Time {
|
||||
return time.Unix(int64(in.Bkuptime_), int64(in.BkuptimeNsec))
|
||||
}
|
||||
|
||||
func (in *setattrIn) Chgtime() time.Time {
|
||||
return time.Unix(int64(in.Chgtime_), int64(in.ChgtimeNsec))
|
||||
}
|
||||
|
||||
func (in *setattrIn) Flags() uint32 {
|
||||
return in.Flags_
|
||||
}
|
||||
50
vendor/github.com/mattermost/rsc/fuse/fuse_kernel_linux.go
сгенерированный
поставляемый
50
vendor/github.com/mattermost/rsc/fuse/fuse_kernel_linux.go
сгенерированный
поставляемый
@@ -1,50 +0,0 @@
|
||||
package fuse
|
||||
|
||||
import "time"
|
||||
|
||||
type attr struct {
|
||||
Ino uint64
|
||||
Size uint64
|
||||
Blocks uint64
|
||||
Atime uint64
|
||||
Mtime uint64
|
||||
Ctime uint64
|
||||
AtimeNsec uint32
|
||||
MtimeNsec uint32
|
||||
CtimeNsec uint32
|
||||
Mode uint32
|
||||
Nlink uint32
|
||||
Uid uint32
|
||||
Gid uint32
|
||||
Rdev uint32
|
||||
// Blksize uint32 // Only in protocol 7.9
|
||||
// padding_ uint32 // Only in protocol 7.9
|
||||
}
|
||||
|
||||
func (a *attr) Crtime() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (a *attr) SetCrtime(s uint64, ns uint32) {
|
||||
// Ignored on Linux.
|
||||
}
|
||||
|
||||
func (a *attr) SetFlags(f uint32) {
|
||||
// Ignored on Linux.
|
||||
}
|
||||
|
||||
type setattrIn struct {
|
||||
setattrInCommon
|
||||
}
|
||||
|
||||
func (in *setattrIn) BkupTime() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (in *setattrIn) Chgtime() time.Time {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
func (in *setattrIn) Flags() uint32 {
|
||||
return 0
|
||||
}
|
||||
1
vendor/github.com/mattermost/rsc/fuse/fuse_kernel_std.go
сгенерированный
поставляемый
1
vendor/github.com/mattermost/rsc/fuse/fuse_kernel_std.go
сгенерированный
поставляемый
@@ -1 +0,0 @@
|
||||
package fuse
|
||||
594
vendor/github.com/mattermost/rsc/fuse/fuse_test.go
сгенерированный
поставляемый
594
vendor/github.com/mattermost/rsc/fuse/fuse_test.go
сгенерированный
поставляемый
@@ -1,594 +0,0 @@
|
||||
// Copyright 2012 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 fuse
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var fuseRun = flag.String("fuserun", "", "which fuse test to run. runs all if empty.")
|
||||
|
||||
// umount tries its best to unmount dir.
|
||||
func umount(dir string) {
|
||||
err := exec.Command("umount", dir).Run()
|
||||
if err != nil && runtime.GOOS == "linux" {
|
||||
exec.Command("/bin/fusermount", "-u", dir).Run()
|
||||
}
|
||||
}
|
||||
|
||||
func TestFuse(t *testing.T) {
|
||||
Debugf = log.Printf
|
||||
dir, err := ioutil.TempDir("", "fusetest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.MkdirAll(dir, 0777)
|
||||
|
||||
c, err := Mount(dir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer umount(dir)
|
||||
|
||||
go func() {
|
||||
err := c.Serve(testFS{})
|
||||
if err != nil {
|
||||
fmt.Printf("SERVE ERROR: %v\n", err)
|
||||
}
|
||||
}()
|
||||
|
||||
waitForMount(t, dir)
|
||||
|
||||
for _, tt := range fuseTests {
|
||||
if *fuseRun == "" || *fuseRun == tt.name {
|
||||
t.Logf("running %T", tt.node)
|
||||
tt.node.test(dir+"/"+tt.name, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func waitForMount(t *testing.T, dir string) {
|
||||
// Filename to wait for in dir:
|
||||
probeEntry := *fuseRun
|
||||
if probeEntry == "" {
|
||||
probeEntry = fuseTests[0].name
|
||||
}
|
||||
for tries := 0; tries < 100; tries++ {
|
||||
_, err := os.Stat(dir + "/" + probeEntry)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
t.Fatalf("mount did not work")
|
||||
}
|
||||
|
||||
var fuseTests = []struct {
|
||||
name string
|
||||
node interface {
|
||||
Node
|
||||
test(string, *testing.T)
|
||||
}
|
||||
}{
|
||||
{"readAll", readAll{}},
|
||||
{"readAll1", &readAll1{}},
|
||||
{"write", &write{}},
|
||||
{"writeAll", &writeAll{}},
|
||||
{"writeAll2", &writeAll2{}},
|
||||
{"release", &release{}},
|
||||
{"mkdir1", &mkdir1{}},
|
||||
{"create1", &create1{}},
|
||||
{"create2", &create2{}},
|
||||
{"symlink1", &symlink1{}},
|
||||
{"link1", &link1{}},
|
||||
{"rename1", &rename1{}},
|
||||
{"mknod1", &mknod1{}},
|
||||
}
|
||||
|
||||
// TO TEST:
|
||||
// Statfs
|
||||
// Lookup(*LookupRequest, *LookupResponse)
|
||||
// Getattr(*GetattrRequest, *GetattrResponse)
|
||||
// Attr with explicit inode
|
||||
// Setattr(*SetattrRequest, *SetattrResponse)
|
||||
// Access(*AccessRequest)
|
||||
// Open(*OpenRequest, *OpenResponse)
|
||||
// Getxattr, Setxattr, Listxattr, Removexattr
|
||||
// Write(*WriteRequest, *WriteResponse)
|
||||
// Flush(*FlushRequest, *FlushResponse)
|
||||
|
||||
// Test Read calling ReadAll.
|
||||
|
||||
type readAll struct{ file }
|
||||
|
||||
const hi = "hello, world"
|
||||
|
||||
func (readAll) ReadAll(intr Intr) ([]byte, Error) {
|
||||
return []byte(hi), nil
|
||||
}
|
||||
|
||||
func (readAll) test(path string, t *testing.T) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Errorf("readAll: %v", err)
|
||||
return
|
||||
}
|
||||
if string(data) != hi {
|
||||
t.Errorf("readAll = %q, want %q", data, hi)
|
||||
}
|
||||
}
|
||||
|
||||
// Test Read.
|
||||
|
||||
type readAll1 struct{ file }
|
||||
|
||||
func (readAll1) Read(req *ReadRequest, resp *ReadResponse, intr Intr) Error {
|
||||
HandleRead(req, resp, []byte(hi))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (readAll1) test(path string, t *testing.T) {
|
||||
readAll{}.test(path, t)
|
||||
}
|
||||
|
||||
// Test Write calling basic Write, with an fsync thrown in too.
|
||||
|
||||
type write struct {
|
||||
file
|
||||
data []byte
|
||||
gotfsync bool
|
||||
}
|
||||
|
||||
func (w *write) Write(req *WriteRequest, resp *WriteResponse, intr Intr) Error {
|
||||
w.data = append(w.data, req.Data...)
|
||||
resp.Size = len(req.Data)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *write) Fsync(r *FsyncRequest, intr Intr) Error {
|
||||
w.gotfsync = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *write) test(path string, t *testing.T) {
|
||||
log.Printf("pre-write Create")
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
t.Fatalf("Create: %v", err)
|
||||
}
|
||||
log.Printf("pre-write Write")
|
||||
n, err := f.Write([]byte(hi))
|
||||
if err != nil {
|
||||
t.Fatalf("Write: %v", err)
|
||||
}
|
||||
if n != len(hi) {
|
||||
t.Fatalf("short write; n=%d; hi=%d", n, len(hi))
|
||||
}
|
||||
|
||||
err = syscall.Fsync(int(f.Fd()))
|
||||
if err != nil {
|
||||
t.Fatalf("Fsync = %v", err)
|
||||
}
|
||||
if !w.gotfsync {
|
||||
t.Errorf("never received expected fsync call")
|
||||
}
|
||||
|
||||
log.Printf("pre-write Close")
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
t.Fatalf("Close: %v", err)
|
||||
}
|
||||
log.Printf("post-write Close")
|
||||
if string(w.data) != hi {
|
||||
t.Errorf("writeAll = %q, want %q", w.data, hi)
|
||||
}
|
||||
}
|
||||
|
||||
// Test Write calling WriteAll.
|
||||
|
||||
type writeAll struct {
|
||||
file
|
||||
data []byte
|
||||
gotfsync bool
|
||||
}
|
||||
|
||||
func (w *writeAll) Fsync(r *FsyncRequest, intr Intr) Error {
|
||||
w.gotfsync = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *writeAll) WriteAll(data []byte, intr Intr) Error {
|
||||
w.data = data
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *writeAll) test(path string, t *testing.T) {
|
||||
err := ioutil.WriteFile(path, []byte(hi), 0666)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteFile: %v", err)
|
||||
return
|
||||
}
|
||||
if string(w.data) != hi {
|
||||
t.Errorf("writeAll = %q, want %q", w.data, hi)
|
||||
}
|
||||
}
|
||||
|
||||
// Test Write calling Setattr+Write+Flush.
|
||||
|
||||
type writeAll2 struct {
|
||||
file
|
||||
data []byte
|
||||
setattr bool
|
||||
flush bool
|
||||
}
|
||||
|
||||
func (w *writeAll2) Setattr(req *SetattrRequest, resp *SetattrResponse, intr Intr) Error {
|
||||
w.setattr = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *writeAll2) Flush(req *FlushRequest, intr Intr) Error {
|
||||
w.flush = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *writeAll2) Write(req *WriteRequest, resp *WriteResponse, intr Intr) Error {
|
||||
w.data = append(w.data, req.Data...)
|
||||
resp.Size = len(req.Data)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *writeAll2) test(path string, t *testing.T) {
|
||||
err := ioutil.WriteFile(path, []byte(hi), 0666)
|
||||
if err != nil {
|
||||
t.Errorf("WriteFile: %v", err)
|
||||
return
|
||||
}
|
||||
if !w.setattr || string(w.data) != hi || !w.flush {
|
||||
t.Errorf("writeAll = %v, %q, %v, want %v, %q, %v", w.setattr, string(w.data), w.flush, true, hi, true)
|
||||
}
|
||||
}
|
||||
|
||||
// Test Mkdir.
|
||||
|
||||
type mkdir1 struct {
|
||||
dir
|
||||
name string
|
||||
}
|
||||
|
||||
func (f *mkdir1) Mkdir(req *MkdirRequest, intr Intr) (Node, Error) {
|
||||
f.name = req.Name
|
||||
return &mkdir1{}, nil
|
||||
}
|
||||
|
||||
func (f *mkdir1) test(path string, t *testing.T) {
|
||||
f.name = ""
|
||||
err := os.Mkdir(path+"/foo", 0777)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if f.name != "foo" {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Test Create (and fsync)
|
||||
|
||||
type create1 struct {
|
||||
dir
|
||||
name string
|
||||
f *writeAll
|
||||
}
|
||||
|
||||
func (f *create1) Create(req *CreateRequest, resp *CreateResponse, intr Intr) (Node, Handle, Error) {
|
||||
f.name = req.Name
|
||||
f.f = &writeAll{}
|
||||
return f.f, f.f, nil
|
||||
}
|
||||
|
||||
func (f *create1) test(path string, t *testing.T) {
|
||||
f.name = ""
|
||||
ff, err := os.Create(path + "/foo")
|
||||
if err != nil {
|
||||
t.Errorf("create1 WriteFile: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = syscall.Fsync(int(ff.Fd()))
|
||||
if err != nil {
|
||||
t.Fatalf("Fsync = %v", err)
|
||||
}
|
||||
|
||||
if !f.f.gotfsync {
|
||||
t.Errorf("never received expected fsync call")
|
||||
}
|
||||
|
||||
ff.Close()
|
||||
if f.name != "foo" {
|
||||
t.Errorf("create1 name=%q want foo", f.name)
|
||||
}
|
||||
}
|
||||
|
||||
// Test Create + WriteAll + Remove
|
||||
|
||||
type create2 struct {
|
||||
dir
|
||||
name string
|
||||
f *writeAll
|
||||
fooExists bool
|
||||
}
|
||||
|
||||
func (f *create2) Create(req *CreateRequest, resp *CreateResponse, intr Intr) (Node, Handle, Error) {
|
||||
f.name = req.Name
|
||||
f.f = &writeAll{}
|
||||
return f.f, f.f, nil
|
||||
}
|
||||
|
||||
func (f *create2) Lookup(name string, intr Intr) (Node, Error) {
|
||||
if f.fooExists && name == "foo" {
|
||||
return file{}, nil
|
||||
}
|
||||
return nil, ENOENT
|
||||
}
|
||||
|
||||
func (f *create2) Remove(r *RemoveRequest, intr Intr) Error {
|
||||
if f.fooExists && r.Name == "foo" && !r.Dir {
|
||||
f.fooExists = false
|
||||
return nil
|
||||
}
|
||||
return ENOENT
|
||||
}
|
||||
|
||||
func (f *create2) test(path string, t *testing.T) {
|
||||
f.name = ""
|
||||
err := ioutil.WriteFile(path+"/foo", []byte(hi), 0666)
|
||||
if err != nil {
|
||||
t.Fatalf("create2 WriteFile: %v", err)
|
||||
}
|
||||
if string(f.f.data) != hi {
|
||||
t.Fatalf("create2 writeAll = %q, want %q", f.f.data, hi)
|
||||
}
|
||||
|
||||
f.fooExists = true
|
||||
log.Printf("pre-Remove")
|
||||
err = os.Remove(path + "/foo")
|
||||
if err != nil {
|
||||
t.Fatalf("Remove: %v", err)
|
||||
}
|
||||
err = os.Remove(path + "/foo")
|
||||
if err == nil {
|
||||
t.Fatalf("second Remove = nil; want some error")
|
||||
}
|
||||
}
|
||||
|
||||
// Test symlink + readlink
|
||||
|
||||
type symlink1 struct {
|
||||
dir
|
||||
newName, target string
|
||||
}
|
||||
|
||||
func (f *symlink1) Symlink(req *SymlinkRequest, intr Intr) (Node, Error) {
|
||||
f.newName = req.NewName
|
||||
f.target = req.Target
|
||||
return symlink{target: req.Target}, nil
|
||||
}
|
||||
|
||||
func (f *symlink1) test(path string, t *testing.T) {
|
||||
const target = "/some-target"
|
||||
|
||||
err := os.Symlink(target, path+"/symlink.file")
|
||||
if err != nil {
|
||||
t.Errorf("os.Symlink: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if f.newName != "symlink.file" {
|
||||
t.Errorf("symlink newName = %q; want %q", f.newName, "symlink.file")
|
||||
}
|
||||
if f.target != target {
|
||||
t.Errorf("symlink target = %q; want %q", f.target, target)
|
||||
}
|
||||
|
||||
gotName, err := os.Readlink(path + "/symlink.file")
|
||||
if err != nil {
|
||||
t.Errorf("os.Readlink: %v", err)
|
||||
return
|
||||
}
|
||||
if gotName != target {
|
||||
t.Errorf("os.Readlink = %q; want %q", gotName, target)
|
||||
}
|
||||
}
|
||||
|
||||
// Test link
|
||||
|
||||
type link1 struct {
|
||||
dir
|
||||
newName string
|
||||
}
|
||||
|
||||
func (f *link1) Lookup(name string, intr Intr) (Node, Error) {
|
||||
if name == "old" {
|
||||
return file{}, nil
|
||||
}
|
||||
return nil, ENOENT
|
||||
}
|
||||
|
||||
func (f *link1) Link(r *LinkRequest, old Node, intr Intr) (Node, Error) {
|
||||
f.newName = r.NewName
|
||||
return file{}, nil
|
||||
}
|
||||
|
||||
func (f *link1) test(path string, t *testing.T) {
|
||||
err := os.Link(path+"/old", path+"/new")
|
||||
if err != nil {
|
||||
t.Fatalf("Link: %v", err)
|
||||
}
|
||||
if f.newName != "new" {
|
||||
t.Fatalf("saw Link for newName %q; want %q", f.newName, "new")
|
||||
}
|
||||
}
|
||||
|
||||
// Test Rename
|
||||
|
||||
type rename1 struct {
|
||||
dir
|
||||
renames int
|
||||
}
|
||||
|
||||
func (f *rename1) Lookup(name string, intr Intr) (Node, Error) {
|
||||
if name == "old" {
|
||||
return file{}, nil
|
||||
}
|
||||
return nil, ENOENT
|
||||
}
|
||||
|
||||
func (f *rename1) Rename(r *RenameRequest, newDir Node, intr Intr) Error {
|
||||
if r.OldName == "old" && r.NewName == "new" && newDir == f {
|
||||
f.renames++
|
||||
return nil
|
||||
}
|
||||
return EIO
|
||||
}
|
||||
|
||||
func (f *rename1) test(path string, t *testing.T) {
|
||||
err := os.Rename(path+"/old", path+"/new")
|
||||
if err != nil {
|
||||
t.Fatalf("Rename: %v", err)
|
||||
}
|
||||
if f.renames != 1 {
|
||||
t.Fatalf("expected rename didn't happen")
|
||||
}
|
||||
err = os.Rename(path+"/old2", path+"/new2")
|
||||
if err == nil {
|
||||
t.Fatal("expected error on second Rename; got nil")
|
||||
}
|
||||
}
|
||||
|
||||
// Test Release.
|
||||
|
||||
type release struct {
|
||||
file
|
||||
did bool
|
||||
}
|
||||
|
||||
func (r *release) Release(*ReleaseRequest, Intr) Error {
|
||||
r.did = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *release) test(path string, t *testing.T) {
|
||||
r.did = false
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
f.Close()
|
||||
time.Sleep(1 * time.Second)
|
||||
if !r.did {
|
||||
t.Error("Close did not Release")
|
||||
}
|
||||
}
|
||||
|
||||
// Test mknod
|
||||
|
||||
type mknod1 struct {
|
||||
dir
|
||||
gotr *MknodRequest
|
||||
}
|
||||
|
||||
func (f *mknod1) Mknod(r *MknodRequest, intr Intr) (Node, Error) {
|
||||
f.gotr = r
|
||||
return fifo{}, nil
|
||||
}
|
||||
|
||||
func (f *mknod1) test(path string, t *testing.T) {
|
||||
if os.Getuid() != 0 {
|
||||
t.Logf("skipping unless root")
|
||||
return
|
||||
}
|
||||
defer syscall.Umask(syscall.Umask(0))
|
||||
err := syscall.Mknod(path+"/node", syscall.S_IFIFO|0666, 123)
|
||||
if err != nil {
|
||||
t.Fatalf("Mknod: %v", err)
|
||||
}
|
||||
if f.gotr == nil {
|
||||
t.Fatalf("no recorded MknodRequest")
|
||||
}
|
||||
if g, e := f.gotr.Name, "node"; g != e {
|
||||
t.Errorf("got Name = %q; want %q", g, e)
|
||||
}
|
||||
if g, e := f.gotr.Rdev, uint32(123); g != e {
|
||||
if runtime.GOOS == "linux" {
|
||||
// Linux fuse doesn't echo back the rdev if the node
|
||||
// isn't a device (we're using a FIFO here, as that
|
||||
// bit is portable.)
|
||||
} else {
|
||||
t.Errorf("got Rdev = %v; want %v", g, e)
|
||||
}
|
||||
}
|
||||
if g, e := f.gotr.Mode, os.FileMode(os.ModeNamedPipe|0666); g != e {
|
||||
t.Errorf("got Mode = %v; want %v", g, e)
|
||||
}
|
||||
t.Logf("Got request: %#v", f.gotr)
|
||||
}
|
||||
|
||||
type file struct{}
|
||||
type dir struct{}
|
||||
type fifo struct{}
|
||||
type symlink struct {
|
||||
target string
|
||||
}
|
||||
|
||||
func (f file) Attr() Attr { return Attr{Mode: 0666} }
|
||||
func (f dir) Attr() Attr { return Attr{Mode: os.ModeDir | 0777} }
|
||||
func (f fifo) Attr() Attr { return Attr{Mode: os.ModeNamedPipe | 0666} }
|
||||
func (f symlink) Attr() Attr { return Attr{Mode: os.ModeSymlink | 0666} }
|
||||
|
||||
func (f symlink) Readlink(*ReadlinkRequest, Intr) (string, Error) {
|
||||
return f.target, nil
|
||||
}
|
||||
|
||||
type testFS struct{}
|
||||
|
||||
func (testFS) Root() (Node, Error) {
|
||||
return testFS{}, nil
|
||||
}
|
||||
|
||||
func (testFS) Attr() Attr {
|
||||
return Attr{Mode: os.ModeDir | 0555}
|
||||
}
|
||||
|
||||
func (testFS) Lookup(name string, intr Intr) (Node, Error) {
|
||||
for _, tt := range fuseTests {
|
||||
if tt.name == name {
|
||||
return tt.node, nil
|
||||
}
|
||||
}
|
||||
return nil, ENOENT
|
||||
}
|
||||
|
||||
func (testFS) ReadDir(intr Intr) ([]Dirent, Error) {
|
||||
var dirs []Dirent
|
||||
for _, tt := range fuseTests {
|
||||
if *fuseRun == "" || *fuseRun == tt.name {
|
||||
log.Printf("Readdir; adding %q", tt.name)
|
||||
dirs = append(dirs, Dirent{Name: tt.name})
|
||||
}
|
||||
}
|
||||
return dirs, nil
|
||||
}
|
||||
62
vendor/github.com/mattermost/rsc/fuse/hellofs/hello.go
сгенерированный
поставляемый
62
vendor/github.com/mattermost/rsc/fuse/hellofs/hello.go
сгенерированный
поставляемый
@@ -1,62 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// Hellofs implements a simple "hello world" file system.
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/rsc/fuse"
|
||||
)
|
||||
|
||||
func main() {
|
||||
c, err := fuse.Mount("/mnt/hellofs")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
c.Serve(FS{})
|
||||
}
|
||||
|
||||
// FS implements the hello world file system.
|
||||
type FS struct{}
|
||||
|
||||
func (FS) Root() (fuse.Node, fuse.Error) {
|
||||
return Dir{}, nil
|
||||
}
|
||||
|
||||
// Dir implements both Node and Handle for the root directory.
|
||||
type Dir struct{}
|
||||
|
||||
func (Dir) Attr() fuse.Attr {
|
||||
return fuse.Attr{Mode: os.ModeDir | 0555}
|
||||
}
|
||||
|
||||
func (Dir) Lookup(name string, intr fuse.Intr) (fuse.Node, fuse.Error) {
|
||||
if name == "hello" {
|
||||
return File{}, nil
|
||||
}
|
||||
return nil, fuse.ENOENT
|
||||
}
|
||||
|
||||
var dirDirs = []fuse.Dirent{
|
||||
{Inode: 2, Name: "hello", Type: 0},
|
||||
}
|
||||
|
||||
func (Dir) ReadDir(intr fuse.Intr) ([]fuse.Dirent, fuse.Error) {
|
||||
return dirDirs, nil
|
||||
}
|
||||
|
||||
// File implements both Node and Handle for the hello file.
|
||||
type File struct{}
|
||||
|
||||
func (File) Attr() fuse.Attr {
|
||||
return fuse.Attr{Mode: 0444}
|
||||
}
|
||||
|
||||
func (File) ReadAll(intr fuse.Intr) ([]byte, fuse.Error) {
|
||||
return []byte("hello, world\n"), nil
|
||||
}
|
||||
122
vendor/github.com/mattermost/rsc/fuse/mount_darwin.go
сгенерированный
поставляемый
122
vendor/github.com/mattermost/rsc/fuse/mount_darwin.go
сгенерированный
поставляемый
@@ -1,122 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// TODO: Rewrite using package syscall not cgo
|
||||
|
||||
package fuse
|
||||
|
||||
/*
|
||||
|
||||
// Adapted from Plan 9 from User Space's src/cmd/9pfuse/fuse.c,
|
||||
// which carries this notice:
|
||||
//
|
||||
// The files in this directory are subject to the following license.
|
||||
//
|
||||
// The author of this software is Russ Cox.
|
||||
//
|
||||
// Copyright (c) 2006 Russ Cox
|
||||
//
|
||||
// Permission to use, copy, modify, and distribute this software for any
|
||||
// purpose without fee is hereby granted, provided that this entire notice
|
||||
// is included in all copies of any software which is or includes a copy
|
||||
// or modification of this software and in all copies of the supporting
|
||||
// documentation for such software.
|
||||
//
|
||||
// THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
||||
// WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION OR WARRANTY
|
||||
// OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS SOFTWARE OR ITS
|
||||
// FITNESS FOR ANY PARTICULAR PURPOSE.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define nil ((void*)0)
|
||||
|
||||
static int
|
||||
mountfuse(char *mtpt, char **err)
|
||||
{
|
||||
int i, pid, fd, r;
|
||||
char buf[200];
|
||||
struct vfsconf vfs;
|
||||
char *f;
|
||||
|
||||
if(getvfsbyname("fusefs", &vfs) < 0){
|
||||
if(access(f="/Library/Filesystems/osxfusefs.fs"
|
||||
"/Support/load_osxfusefs", 0) < 0){
|
||||
*err = strdup("cannot find load_fusefs");
|
||||
return -1;
|
||||
}
|
||||
if((r=system(f)) < 0){
|
||||
snprintf(buf, sizeof buf, "%s: %s", f, strerror(errno));
|
||||
*err = strdup(buf);
|
||||
return -1;
|
||||
}
|
||||
if(r != 0){
|
||||
snprintf(buf, sizeof buf, "load_fusefs failed: exit %d", r);
|
||||
*err = strdup(buf);
|
||||
return -1;
|
||||
}
|
||||
if(getvfsbyname("osxfusefs", &vfs) < 0){
|
||||
snprintf(buf, sizeof buf, "getvfsbyname osxfusefs: %s", strerror(errno));
|
||||
*err = strdup(buf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Look for available FUSE device.
|
||||
for(i=0;; i++){
|
||||
snprintf(buf, sizeof buf, "/dev/osxfuse%d", i);
|
||||
if(access(buf, 0) < 0){
|
||||
*err = strdup("no available fuse devices");
|
||||
return -1;
|
||||
}
|
||||
if((fd = open(buf, O_RDWR)) >= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
pid = fork();
|
||||
if(pid < 0)
|
||||
return -1;
|
||||
if(pid == 0){
|
||||
snprintf(buf, sizeof buf, "%d", fd);
|
||||
setenv("MOUNT_FUSEFS_CALL_BY_LIB", "", 1);
|
||||
// Different versions of MacFUSE put the
|
||||
// mount_fusefs binary in different places.
|
||||
// Try all.
|
||||
// Leopard location
|
||||
setenv("MOUNT_FUSEFS_DAEMON_PATH",
|
||||
"/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs", 1);
|
||||
execl("/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs",
|
||||
"mount_osxfusefs",
|
||||
"-o", "iosize=4096", buf, mtpt, nil);
|
||||
fprintf(stderr, "exec mount_osxfusefs: %s\n", strerror(errno));
|
||||
_exit(1);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func mount(dir string) (int, string) {
|
||||
errp := (**C.char)(C.malloc(16))
|
||||
*errp = nil
|
||||
defer C.free(unsafe.Pointer(errp))
|
||||
cdir := C.CString(dir)
|
||||
defer C.free(unsafe.Pointer(cdir))
|
||||
fd := C.mountfuse(cdir, errp)
|
||||
var err string
|
||||
if *errp != nil {
|
||||
err = C.GoString(*errp)
|
||||
}
|
||||
return int(fd), err
|
||||
}
|
||||
67
vendor/github.com/mattermost/rsc/fuse/mount_linux.go
сгенерированный
поставляемый
67
vendor/github.com/mattermost/rsc/fuse/mount_linux.go
сгенерированный
поставляемый
@@ -1,67 +0,0 @@
|
||||
// Copyright 2012 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 fuse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func mount(dir string) (fusefd int, errmsg string) {
|
||||
fds, err := syscall.Socketpair(syscall.AF_FILE, syscall.SOCK_STREAM, 0)
|
||||
if err != nil {
|
||||
return -1, fmt.Sprintf("socketpair error: %v", err)
|
||||
}
|
||||
defer syscall.Close(fds[0])
|
||||
defer syscall.Close(fds[1])
|
||||
|
||||
cmd := exec.Command("/bin/fusermount", "--", dir)
|
||||
cmd.Env = append(os.Environ(), "_FUSE_COMMFD=3")
|
||||
|
||||
writeFile := os.NewFile(uintptr(fds[0]), "fusermount-child-writes")
|
||||
defer writeFile.Close()
|
||||
cmd.ExtraFiles = []*os.File{writeFile}
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
if len(out) > 0 || err != nil {
|
||||
return -1, fmt.Sprintf("fusermount: %q, %v", out, err)
|
||||
}
|
||||
|
||||
readFile := os.NewFile(uintptr(fds[1]), "fusermount-parent-reads")
|
||||
defer readFile.Close()
|
||||
c, err := net.FileConn(readFile)
|
||||
if err != nil {
|
||||
return -1, fmt.Sprintf("FileConn from fusermount socket: %v", err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
uc, ok := c.(*net.UnixConn)
|
||||
if !ok {
|
||||
return -1, fmt.Sprintf("unexpected FileConn type; expected UnixConn, got %T", c)
|
||||
}
|
||||
|
||||
buf := make([]byte, 32) // expect 1 byte
|
||||
oob := make([]byte, 32) // expect 24 bytes
|
||||
_, oobn, _, _, err := uc.ReadMsgUnix(buf, oob)
|
||||
scms, err := syscall.ParseSocketControlMessage(oob[:oobn])
|
||||
if err != nil {
|
||||
return -1, fmt.Sprintf("ParseSocketControlMessage: %v", err)
|
||||
}
|
||||
if len(scms) != 1 {
|
||||
return -1, fmt.Sprintf("expected 1 SocketControlMessage; got scms = %#v", scms)
|
||||
}
|
||||
scm := scms[0]
|
||||
gotFds, err := syscall.ParseUnixRights(&scm)
|
||||
if err != nil {
|
||||
return -1, fmt.Sprintf("syscall.ParseUnixRights: %v", err)
|
||||
}
|
||||
if len(gotFds) != 1 {
|
||||
return -1, fmt.Sprintf("wanted 1 fd; got %#v", gotFds)
|
||||
}
|
||||
return gotFds[0], ""
|
||||
}
|
||||
1022
vendor/github.com/mattermost/rsc/fuse/serve.go
сгенерированный
поставляемый
1022
vendor/github.com/mattermost/rsc/fuse/serve.go
сгенерированный
поставляемый
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
93
vendor/github.com/mattermost/rsc/fuse/tree.go
сгенерированный
поставляемый
93
vendor/github.com/mattermost/rsc/fuse/tree.go
сгенерированный
поставляемый
@@ -1,93 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// FUSE directory tree, for servers that wish to use it with the service loop.
|
||||
|
||||
package fuse
|
||||
|
||||
import (
|
||||
"os"
|
||||
pathpkg "path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// A Tree implements a basic directory tree for FUSE.
|
||||
type Tree struct {
|
||||
tree
|
||||
}
|
||||
|
||||
func (t *Tree) Root() (Node, Error) {
|
||||
return &t.tree, nil
|
||||
}
|
||||
|
||||
// Add adds the path to the tree, resolving to the given node.
|
||||
// If path or a prefix of path has already been added to the tree,
|
||||
// Add panics.
|
||||
func (t *Tree) Add(path string, node Node) {
|
||||
path = pathpkg.Clean("/" + path)[1:]
|
||||
elems := strings.Split(path, "/")
|
||||
dir := Node(&t.tree)
|
||||
for i, elem := range elems {
|
||||
dt, ok := dir.(*tree)
|
||||
if !ok {
|
||||
panic("fuse: Tree.Add for " + strings.Join(elems[:i], "/") + " and " + path)
|
||||
}
|
||||
n := dt.lookup(elem)
|
||||
if n != nil {
|
||||
if i+1 == len(elems) {
|
||||
panic("fuse: Tree.Add for " + path + " conflicts with " + elem)
|
||||
}
|
||||
dir = n
|
||||
} else {
|
||||
if i+1 == len(elems) {
|
||||
dt.add(elem, node)
|
||||
} else {
|
||||
dir = &tree{}
|
||||
dt.add(elem, dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type treeDir struct {
|
||||
name string
|
||||
node Node
|
||||
}
|
||||
|
||||
type tree struct {
|
||||
dir []treeDir
|
||||
}
|
||||
|
||||
func (t *tree) lookup(name string) Node {
|
||||
for _, d := range t.dir {
|
||||
if d.name == name {
|
||||
return d.node
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *tree) add(name string, n Node) {
|
||||
t.dir = append(t.dir, treeDir{name, n})
|
||||
}
|
||||
|
||||
func (t *tree) Attr() Attr {
|
||||
return Attr{Mode: os.ModeDir | 0555}
|
||||
}
|
||||
|
||||
func (t *tree) Lookup(name string, intr Intr) (Node, Error) {
|
||||
n := t.lookup(name)
|
||||
if n != nil {
|
||||
return n, nil
|
||||
}
|
||||
return nil, ENOENT
|
||||
}
|
||||
|
||||
func (t *tree) ReadDir(intr Intr) ([]Dirent, Error) {
|
||||
var out []Dirent
|
||||
for _, d := range t.dir {
|
||||
out = append(out, Dirent{Name: d.name})
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
85
vendor/github.com/mattermost/rsc/gf256/blog_test.go
сгенерированный
поставляемый
85
vendor/github.com/mattermost/rsc/gf256/blog_test.go
сгенерированный
поставляемый
@@ -1,85 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// This file contains a straightforward implementation of
|
||||
// Reed-Solomon encoding, along with a benchmark.
|
||||
// It goes with http://research.swtch.com/field.
|
||||
//
|
||||
// For an optimized implementation, see gf256.go.
|
||||
|
||||
package gf256
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// BlogECC writes to check the error correcting code bytes
|
||||
// for data using the given Reed-Solomon parameters.
|
||||
func BlogECC(rs *RSEncoder, m []byte, check []byte) {
|
||||
if len(check) < rs.c {
|
||||
panic("gf256: invalid check byte length")
|
||||
}
|
||||
if rs.c == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// The check bytes are the remainder after dividing
|
||||
// data padded with c zeros by the generator polynomial.
|
||||
|
||||
// p = data padded with c zeros.
|
||||
var p []byte
|
||||
n := len(m) + rs.c
|
||||
if len(rs.p) >= n {
|
||||
p = rs.p
|
||||
} else {
|
||||
p = make([]byte, n)
|
||||
}
|
||||
copy(p, m)
|
||||
for i := len(m); i < len(p); i++ {
|
||||
p[i] = 0
|
||||
}
|
||||
|
||||
gen := rs.gen
|
||||
|
||||
// Divide p by gen, leaving the remainder in p[len(data):].
|
||||
// p[0] is the most significant term in p, and
|
||||
// gen[0] is the most significant term in the generator.
|
||||
for i := 0; i < len(m); i++ {
|
||||
k := f.Mul(p[i], f.Inv(gen[0])) // k = pi / g0
|
||||
// p -= k·g
|
||||
for j, g := range gen {
|
||||
p[i+j] = f.Add(p[i+j], f.Mul(k, g))
|
||||
}
|
||||
}
|
||||
|
||||
copy(check, p[len(m):])
|
||||
rs.p = p
|
||||
}
|
||||
|
||||
func BenchmarkBlogECC(b *testing.B) {
|
||||
data := []byte{0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11}
|
||||
check := []byte{0x29, 0x41, 0xb3, 0x93, 0x8, 0xe8, 0xa3, 0xe7, 0x63, 0x8f}
|
||||
out := make([]byte, len(check))
|
||||
rs := NewRSEncoder(f, len(check))
|
||||
for i := 0; i < b.N; i++ {
|
||||
BlogECC(rs, data, out)
|
||||
}
|
||||
b.SetBytes(int64(len(data)))
|
||||
if !bytes.Equal(out, check) {
|
||||
fmt.Printf("have %#v want %#v\n", out, check)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlogECC(t *testing.T) {
|
||||
data := []byte{0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11}
|
||||
check := []byte{0xa5, 0x24, 0xd4, 0xc1, 0xed, 0x36, 0xc7, 0x87, 0x2c, 0x55}
|
||||
out := make([]byte, len(check))
|
||||
rs := NewRSEncoder(f, len(check))
|
||||
BlogECC(rs, data, out)
|
||||
if !bytes.Equal(out, check) {
|
||||
t.Errorf("have %x want %x", out, check)
|
||||
}
|
||||
}
|
||||
194
vendor/github.com/mattermost/rsc/gf256/gf256_test.go
сгенерированный
поставляемый
194
vendor/github.com/mattermost/rsc/gf256/gf256_test.go
сгенерированный
поставляемый
@@ -1,194 +0,0 @@
|
||||
// Copyright 2010 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 gf256
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var f = NewField(0x11d, 2) // x^8 + x^4 + x^3 + x^2 + 1
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
if f.Exp(0) != 1 || f.Exp(1) != 2 || f.Exp(255) != 1 {
|
||||
panic("bad Exp")
|
||||
}
|
||||
}
|
||||
|
||||
func TestECC(t *testing.T) {
|
||||
data := []byte{0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11}
|
||||
check := []byte{0xa5, 0x24, 0xd4, 0xc1, 0xed, 0x36, 0xc7, 0x87, 0x2c, 0x55}
|
||||
out := make([]byte, len(check))
|
||||
rs := NewRSEncoder(f, len(check))
|
||||
rs.ECC(data, out)
|
||||
if !bytes.Equal(out, check) {
|
||||
t.Errorf("have %x want %x", out, check)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinear(t *testing.T) {
|
||||
d1 := []byte{0x00, 0x00}
|
||||
c1 := []byte{0x00, 0x00}
|
||||
out := make([]byte, len(c1))
|
||||
rs := NewRSEncoder(f, len(c1))
|
||||
if rs.ECC(d1, out); !bytes.Equal(out, c1) {
|
||||
t.Errorf("ECBytes(%x, %d) = %x, want 0", d1, len(c1), out)
|
||||
}
|
||||
d2 := []byte{0x00, 0x01}
|
||||
c2 := make([]byte, 2)
|
||||
rs.ECC(d2, c2)
|
||||
d3 := []byte{0x00, 0x02}
|
||||
c3 := make([]byte, 2)
|
||||
rs.ECC(d3, c3)
|
||||
cx := make([]byte, 2)
|
||||
for i := range cx {
|
||||
cx[i] = c2[i] ^ c3[i]
|
||||
}
|
||||
d4 := []byte{0x00, 0x03}
|
||||
c4 := make([]byte, 2)
|
||||
rs.ECC(d4, c4)
|
||||
if !bytes.Equal(cx, c4) {
|
||||
t.Errorf("ECBytes(%x, 2) = %x\nECBytes(%x, 2) = %x\nxor = %x\nECBytes(%x, 2) = %x",
|
||||
d2, c2, d3, c3, cx, d4, c4)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGaussJordan(t *testing.T) {
|
||||
rs := NewRSEncoder(f, 2)
|
||||
m := make([][]byte, 16)
|
||||
for i := range m {
|
||||
m[i] = make([]byte, 4)
|
||||
m[i][i/8] = 1 << uint(i%8)
|
||||
rs.ECC(m[i][:2], m[i][2:])
|
||||
}
|
||||
if false {
|
||||
fmt.Printf("---\n")
|
||||
for _, row := range m {
|
||||
fmt.Printf("%x\n", row)
|
||||
}
|
||||
}
|
||||
b := []uint{0, 1, 2, 3, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25, 26, 27}
|
||||
for i := 0; i < 16; i++ {
|
||||
bi := b[i]
|
||||
if m[i][bi/8]&(1<<(7-bi%8)) == 0 {
|
||||
for j := i + 1; ; j++ {
|
||||
if j >= len(m) {
|
||||
t.Errorf("lost track for %d", bi)
|
||||
break
|
||||
}
|
||||
if m[j][bi/8]&(1<<(7-bi%8)) != 0 {
|
||||
m[i], m[j] = m[j], m[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
for j := i + 1; j < len(m); j++ {
|
||||
if m[j][bi/8]&(1<<(7-bi%8)) != 0 {
|
||||
for k := range m[j] {
|
||||
m[j][k] ^= m[i][k]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if false {
|
||||
fmt.Printf("---\n")
|
||||
for _, row := range m {
|
||||
fmt.Printf("%x\n", row)
|
||||
}
|
||||
}
|
||||
for i := 15; i >= 0; i-- {
|
||||
bi := b[i]
|
||||
for j := i - 1; j >= 0; j-- {
|
||||
if m[j][bi/8]&(1<<(7-bi%8)) != 0 {
|
||||
for k := range m[j] {
|
||||
m[j][k] ^= m[i][k]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if false {
|
||||
fmt.Printf("---\n")
|
||||
for _, row := range m {
|
||||
fmt.Printf("%x", row)
|
||||
out := make([]byte, 2)
|
||||
if rs.ECC(row[:2], out); !bytes.Equal(out, row[2:]) {
|
||||
fmt.Printf(" - want %x", out)
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkECC(b *testing.B) {
|
||||
data := []byte{0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11}
|
||||
check := []byte{0x29, 0x41, 0xb3, 0x93, 0x8, 0xe8, 0xa3, 0xe7, 0x63, 0x8f}
|
||||
out := make([]byte, len(check))
|
||||
rs := NewRSEncoder(f, len(check))
|
||||
for i := 0; i < b.N; i++ {
|
||||
rs.ECC(data, out)
|
||||
}
|
||||
b.SetBytes(int64(len(data)))
|
||||
if !bytes.Equal(out, check) {
|
||||
fmt.Printf("have %#v want %#v\n", out, check)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGen(t *testing.T) {
|
||||
for i := 0; i < 256; i++ {
|
||||
_, lg := f.gen(i)
|
||||
if lg[0] != 0 {
|
||||
t.Errorf("#%d: %x", i, lg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReducible(t *testing.T) {
|
||||
var count = []int{1, 2, 3, 6, 9, 18, 30, 56, 99, 186} // oeis.org/A1037
|
||||
for i, want := range count {
|
||||
n := 0
|
||||
for p := 1 << uint(i+2); p < 1<<uint(i+3); p++ {
|
||||
if !reducible(p) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
if n != want {
|
||||
t.Errorf("#reducible(%d-bit) = %d, want %d", i+2, n, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExhaustive(t *testing.T) {
|
||||
for poly := 0x100; poly < 0x200; poly++ {
|
||||
if reducible(poly) {
|
||||
continue
|
||||
}
|
||||
α := 2
|
||||
for !generates(α, poly) {
|
||||
α++
|
||||
}
|
||||
f := NewField(poly, α)
|
||||
for p := 0; p < 256; p++ {
|
||||
for q := 0; q < 256; q++ {
|
||||
fm := int(f.Mul(byte(p), byte(q)))
|
||||
pm := mul(p, q, poly)
|
||||
if fm != pm {
|
||||
t.Errorf("NewField(%#x).Mul(%#x, %#x) = %#x, want %#x", poly, p, q, fm, pm)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func generates(α, poly int) bool {
|
||||
x := α
|
||||
for i := 0; i < 254; i++ {
|
||||
if x == 1 {
|
||||
return false
|
||||
}
|
||||
x = mul(x, α, poly)
|
||||
}
|
||||
return true
|
||||
}
|
||||
575
vendor/github.com/mattermost/rsc/google/acme/Chat/main.go
сгенерированный
поставляемый
575
vendor/github.com/mattermost/rsc/google/acme/Chat/main.go
сгенерированный
поставляемый
@@ -1,575 +0,0 @@
|
||||
// Copyright 2011 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 main
|
||||
|
||||
/*
|
||||
TODO:
|
||||
- Del of main window should move to other window.
|
||||
- Editing main window should update status on \n or something like that.
|
||||
- Make use of full names from roster
|
||||
*/
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.google.com/p/goplan9/plan9/acme"
|
||||
"github.com/mattermost/rsc/google"
|
||||
"github.com/mattermost/rsc/xmpp"
|
||||
)
|
||||
|
||||
var acmeDebug = flag.Bool("acmedebug", false, "print acme debugging")
|
||||
|
||||
type Window struct {
|
||||
*acme.Win // acme window
|
||||
*acme.Event // most recent event received
|
||||
err error // error reading event
|
||||
typ string // kind of window "main", "chat"
|
||||
name string // acme window title
|
||||
remote string // for typ=="chat", remote address
|
||||
dirty bool // window is dirty
|
||||
blinky bool // window's dirty box is blinking
|
||||
|
||||
lastTime time.Time
|
||||
}
|
||||
|
||||
type Msg struct {
|
||||
w *Window // window where message belongs
|
||||
*xmpp.Chat // recently received chat
|
||||
err error // error reading chat message
|
||||
}
|
||||
|
||||
var (
|
||||
client *xmpp.Client // current xmpp client (can reconnect)
|
||||
acct google.Account // google acct info
|
||||
statusCache = make(map[string][]*xmpp.Presence)
|
||||
active = make(map[string]*Window) // active windows
|
||||
acmeChan = make(chan *Window) // acme events
|
||||
msgChan = make(chan *Msg) // chat events
|
||||
mainWin *Window
|
||||
status = xmpp.Available
|
||||
statusMsg = ""
|
||||
lastActivity time.Time
|
||||
)
|
||||
|
||||
const (
|
||||
awayTime = 10 * time.Minute
|
||||
extendedAwayTime = 30 * time.Minute
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, "usage: Chat [-a acct] name...\n")
|
||||
flag.PrintDefaults()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
var acctName = flag.String("a", "", "account to use")
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
acct = google.Acct(*acctName)
|
||||
|
||||
aw, err := acme.New()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
aw.Name("Chat/" + acct.Nick + "/")
|
||||
|
||||
client, err = xmpp.NewClient("talk.google.com:443", acct.Email, acct.Password)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
w := &Window{Win: aw, typ: "main", name: "Chat/" + acct.Nick + "/"}
|
||||
data, err := ioutil.ReadFile(google.Dir() + "/chat." + acct.Nick)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err == nil {
|
||||
w.Write("body", data)
|
||||
}
|
||||
mainWin = w
|
||||
active[w.name] = w
|
||||
go w.readAcme()
|
||||
client.Roster()
|
||||
setStatus(status)
|
||||
go w.readChat()
|
||||
lastActivity = time.Now()
|
||||
|
||||
tick := time.Tick(0.5e9)
|
||||
Loop:
|
||||
for len(active) > 0 {
|
||||
select {
|
||||
case w := <-acmeChan:
|
||||
if w == nil {
|
||||
// Sync with reader.
|
||||
continue
|
||||
}
|
||||
if w.err != nil {
|
||||
if active[w.name] == nil {
|
||||
continue
|
||||
}
|
||||
log.Fatal(w.err)
|
||||
}
|
||||
if *acmeDebug {
|
||||
fmt.Fprintf(os.Stderr, "%s %c%c %d,%d %q\n", w.name, w.C1, w.C2, w.Q0, w.Q1, w.Text)
|
||||
}
|
||||
if w.C1 == 'M' || w.C1 == 'K' {
|
||||
lastActivity = time.Now()
|
||||
if status != xmpp.Available {
|
||||
setStatus(xmpp.Available)
|
||||
}
|
||||
}
|
||||
if (w.C2 == 'x' || w.C2 == 'X') && string(w.Text) == "Del" {
|
||||
// TODO: Hangup connection for w.typ == "acct"?
|
||||
delete(active, w.name)
|
||||
w.Del(true)
|
||||
continue Loop
|
||||
}
|
||||
|
||||
switch w.typ {
|
||||
case "main":
|
||||
switch w.C2 {
|
||||
case 'L': // Button 3 in body: load chat window for contact.
|
||||
w.expand()
|
||||
fallthrough
|
||||
case 'l': // Button 3 in tag
|
||||
arg := string(w.Text)
|
||||
showContact(arg)
|
||||
continue Loop
|
||||
}
|
||||
case "chat":
|
||||
if w.C1 == 'F' && w.C2 == 'I' {
|
||||
continue Loop
|
||||
}
|
||||
if w.C1 != 'M' && w.C1 != 'K' {
|
||||
break
|
||||
}
|
||||
if w.blinky {
|
||||
w.blinky = false
|
||||
w.Fprintf("ctl", "dirty\n")
|
||||
}
|
||||
switch w.C2 {
|
||||
case 'X', 'x':
|
||||
if string(w.Text) == "Ack" {
|
||||
w.Fprintf("ctl", "clean\n")
|
||||
}
|
||||
case 'I':
|
||||
w.sendMsg()
|
||||
continue Loop
|
||||
}
|
||||
}
|
||||
w.WriteEvent(w.Event)
|
||||
|
||||
case msg := <-msgChan:
|
||||
w := msg.w
|
||||
if msg.err != nil {
|
||||
w.Fprintf("body", "ERROR: %s\n", msg.err)
|
||||
continue Loop
|
||||
}
|
||||
you := msg.Remote
|
||||
if i := strings.Index(you, "/"); i >= 0 {
|
||||
you = you[:i]
|
||||
}
|
||||
switch msg.Type {
|
||||
case "chat":
|
||||
w := showContact(you)
|
||||
text := strings.TrimSpace(msg.Text)
|
||||
if text == "" {
|
||||
// Probably a composing notification.
|
||||
continue
|
||||
}
|
||||
w.message("> %s\n", text)
|
||||
w.blinky = true
|
||||
w.dirty = true
|
||||
|
||||
case "presence":
|
||||
pr := msg.Presence
|
||||
pr, new := savePresence(pr, you)
|
||||
if !new {
|
||||
continue
|
||||
}
|
||||
w := lookContact(you)
|
||||
if w != nil {
|
||||
w.status(pr)
|
||||
}
|
||||
mainStatus(pr, you)
|
||||
}
|
||||
|
||||
case t := <-tick:
|
||||
switch status {
|
||||
case xmpp.Available:
|
||||
if t.Sub(lastActivity) > awayTime {
|
||||
setStatus(xmpp.Away)
|
||||
}
|
||||
case xmpp.Away:
|
||||
if t.Sub(lastActivity) > extendedAwayTime {
|
||||
setStatus(xmpp.ExtendedAway)
|
||||
}
|
||||
}
|
||||
for _, w := range active {
|
||||
if w.blinky {
|
||||
w.dirty = !w.dirty
|
||||
if w.dirty {
|
||||
w.Fprintf("ctl", "dirty\n")
|
||||
} else {
|
||||
w.Fprintf("ctl", "clean\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setStatus(st xmpp.Status) {
|
||||
status = st
|
||||
client.Status(status, statusMsg)
|
||||
mainWin.statusTag(status, statusMsg)
|
||||
}
|
||||
|
||||
func savePresence(pr *xmpp.Presence, you string) (pr1 *xmpp.Presence, new bool) {
|
||||
old := cachedPresence(you)
|
||||
|
||||
pr.StatusMsg = strings.TrimSpace(pr.StatusMsg)
|
||||
c := statusCache[you]
|
||||
for i, p := range c {
|
||||
if p.Remote == pr.Remote {
|
||||
c[i] = pr
|
||||
c[0], c[i] = c[i], c[0]
|
||||
goto Best
|
||||
}
|
||||
}
|
||||
c = append(c, pr)
|
||||
c[0], c[len(c)-1] = c[len(c)-1], c[0]
|
||||
statusCache[you] = c
|
||||
|
||||
Best:
|
||||
best := cachedPresence(you)
|
||||
return best, old == nil || old.Status != best.Status || old.StatusMsg != best.StatusMsg
|
||||
}
|
||||
|
||||
func cachedPresence(you string) *xmpp.Presence {
|
||||
c := statusCache[you]
|
||||
if len(c) == 0 {
|
||||
return nil
|
||||
}
|
||||
best := c[0]
|
||||
for _, p := range c {
|
||||
if p.Status > best.Status {
|
||||
best = p
|
||||
}
|
||||
}
|
||||
return best
|
||||
}
|
||||
|
||||
func short(st xmpp.Status) string {
|
||||
switch st {
|
||||
case xmpp.Unavailable:
|
||||
return "?"
|
||||
case xmpp.ExtendedAway:
|
||||
return "x"
|
||||
case xmpp.Away:
|
||||
return "-"
|
||||
case xmpp.Available:
|
||||
return "+"
|
||||
case xmpp.DoNotDisturb:
|
||||
return "!"
|
||||
}
|
||||
return st.String()
|
||||
}
|
||||
|
||||
func long(st xmpp.Status) string {
|
||||
switch st {
|
||||
case xmpp.Unavailable:
|
||||
return "unavailable"
|
||||
case xmpp.ExtendedAway:
|
||||
return "offline"
|
||||
case xmpp.Away:
|
||||
return "away"
|
||||
case xmpp.Available:
|
||||
return "available"
|
||||
case xmpp.DoNotDisturb:
|
||||
return "busy"
|
||||
}
|
||||
return st.String()
|
||||
}
|
||||
|
||||
func (w *Window) time() string {
|
||||
/*
|
||||
Auto-date chat windows:
|
||||
|
||||
Show date and time on first message.
|
||||
Show time if minute is different from last message.
|
||||
Show date if day is different from last message.
|
||||
|
||||
Oct 10 12:01 > hi
|
||||
12:03 hello there
|
||||
12:05 > what's up?
|
||||
|
||||
12:10 [Away]
|
||||
*/
|
||||
now := time.Now()
|
||||
m1, d1, y1 := w.lastTime.Date()
|
||||
m2, d2, y2 := now.Date()
|
||||
w.lastTime = now
|
||||
|
||||
if m1 != m2 || d1 != d2 || y1 != y2 {
|
||||
return now.Format("Jan 2 15:04 ")
|
||||
}
|
||||
return now.Format("15:04 ")
|
||||
}
|
||||
|
||||
func (w *Window) status(pr *xmpp.Presence) {
|
||||
msg := ""
|
||||
if pr.StatusMsg != "" {
|
||||
msg = ": " + pr.StatusMsg
|
||||
}
|
||||
w.message("[%s%s]\n", long(pr.Status), msg)
|
||||
|
||||
w.statusTag(pr.Status, pr.StatusMsg)
|
||||
}
|
||||
|
||||
func (w *Window) statusTag(status xmpp.Status, statusMsg string) {
|
||||
data, err := w.ReadAll("tag")
|
||||
if err != nil {
|
||||
log.Printf("read tag: %v", err)
|
||||
return
|
||||
}
|
||||
//log.Printf("tag1: %s\n", data)
|
||||
i := bytes.IndexByte(data, '|')
|
||||
if i >= 0 {
|
||||
data = data[i+1:]
|
||||
} else {
|
||||
data = nil
|
||||
}
|
||||
//log.Printf("tag2: %s\n", data)
|
||||
j := bytes.IndexByte(data, '|')
|
||||
if j >= 0 {
|
||||
data = data[j+1:]
|
||||
}
|
||||
//log.Printf("tag3: %s\n", data)
|
||||
|
||||
msg := ""
|
||||
if statusMsg != "" {
|
||||
msg = " " + statusMsg
|
||||
}
|
||||
w.Ctl("cleartag\n")
|
||||
w.Write("tag", []byte(" "+short(status)+msg+" |"+string(data)))
|
||||
}
|
||||
|
||||
func mainStatus(pr *xmpp.Presence, you string) {
|
||||
w := mainWin
|
||||
if err := w.Addr("#0/^(.[ \t]+)?" + regexp.QuoteMeta(you) + "([ \t]*|$)/"); err != nil {
|
||||
return
|
||||
}
|
||||
q0, q1, err := w.ReadAddr()
|
||||
if err != nil {
|
||||
log.Printf("ReadAddr: %s\n", err)
|
||||
return
|
||||
}
|
||||
if err := w.Addr("#%d/"+regexp.QuoteMeta(you)+"/", q0); err != nil {
|
||||
log.Printf("Addr2: %s\n", err)
|
||||
}
|
||||
q2, q3, err := w.ReadAddr()
|
||||
if err != nil {
|
||||
log.Printf("ReadAddr2: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
space := " "
|
||||
if q1 > q3 || pr.StatusMsg == "" { // already have or don't need space
|
||||
space = ""
|
||||
}
|
||||
if err := w.Addr("#%d/.*/", q1); err != nil {
|
||||
log.Printf("Addr3: %s\n", err)
|
||||
}
|
||||
w.Fprintf("data", "%s%s", space, pr.StatusMsg)
|
||||
|
||||
space = ""
|
||||
if q0 == q2 {
|
||||
w.Addr("#%d,#%d", q0, q0)
|
||||
space = " "
|
||||
} else {
|
||||
w.Addr("#%d,#%d", q0, q0+1)
|
||||
}
|
||||
w.Fprintf("data", "%s%s", short(pr.Status), space)
|
||||
}
|
||||
|
||||
func (w *Window) expand() {
|
||||
// Use selection if any.
|
||||
w.Fprintf("ctl", "addr=dot\n")
|
||||
q0, q1, err := w.ReadAddr()
|
||||
if err == nil && q0 <= w.Q0 && w.Q0 <= q1 {
|
||||
goto Read
|
||||
}
|
||||
if err = w.Addr("#%d-/[a-zA-Z0-9_@.\\-]*/,#%d+/[a-zA-Z0-9_@.\\-]*/", w.Q0, w.Q1); err != nil {
|
||||
log.Printf("expand: %v", err)
|
||||
return
|
||||
}
|
||||
q0, q1, err = w.ReadAddr()
|
||||
if err != nil {
|
||||
log.Printf("expand: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
Read:
|
||||
data, err := w.ReadAll("xdata")
|
||||
if err != nil {
|
||||
log.Printf("read: %v", err)
|
||||
return
|
||||
}
|
||||
w.Text = data
|
||||
w.Q0 = q0
|
||||
w.Q1 = q1
|
||||
return
|
||||
}
|
||||
|
||||
// Invariant: in chat windows, the acme addr corresponds to the
|
||||
// empty string just before the input being typed. Text before addr
|
||||
// is the chat history (usually ending in a blank line).
|
||||
|
||||
func (w *Window) message(format string, args ...interface{}) {
|
||||
if *acmeDebug {
|
||||
q0, q1, _ := w.ReadAddr()
|
||||
log.Printf("message; addr=%d,%d", q0, q1)
|
||||
}
|
||||
if err := w.Addr(".-/\\n?\\n?/"); err != nil && *acmeDebug {
|
||||
log.Printf("set addr: %s", err)
|
||||
}
|
||||
q0, _, _ := w.ReadAddr()
|
||||
nl := ""
|
||||
if q0 > 0 {
|
||||
nl = "\n"
|
||||
}
|
||||
if *acmeDebug {
|
||||
q0, q1, _ := w.ReadAddr()
|
||||
log.Printf("inserting; addr=%d,%d", q0, q1)
|
||||
}
|
||||
w.Fprintf("data", nl+w.time()+format+"\n", args...)
|
||||
if *acmeDebug {
|
||||
q0, q1, _ := w.ReadAddr()
|
||||
log.Printf("wrote; addr=%d,%d", q0, q1)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) sendMsg() {
|
||||
if *acmeDebug {
|
||||
q0, q1, _ := w.ReadAddr()
|
||||
log.Printf("sendMsg; addr=%d,%d", q0, q1)
|
||||
}
|
||||
if err := w.Addr(`.,./(.|\n)*\n/`); err != nil {
|
||||
if *acmeDebug {
|
||||
q0, q1, _ := w.ReadAddr()
|
||||
log.Printf("no text (%s); addr=%d,%d", err, q0, q1)
|
||||
}
|
||||
return
|
||||
}
|
||||
q0, q1, _ := w.ReadAddr()
|
||||
if *acmeDebug {
|
||||
log.Printf("found msg; addr=%d,%d", q0, q1)
|
||||
}
|
||||
line, _ := w.ReadAll("xdata")
|
||||
trim := string(bytes.TrimSpace(line))
|
||||
if len(trim) > 0 {
|
||||
err := client.Send(xmpp.Chat{Remote: w.remote, Type: "chat", Text: trim})
|
||||
|
||||
// Select blank line before input (if any) and input.
|
||||
w.Addr("#%d-/\\n?\\n?/,#%d", q0, q1)
|
||||
if *acmeDebug {
|
||||
q0, q1, _ := w.ReadAddr()
|
||||
log.Printf("selected text; addr=%d,%d", q0, q1)
|
||||
}
|
||||
q0, _, _ := w.ReadAddr()
|
||||
|
||||
// Overwrite with \nmsg\n\n.
|
||||
// Leaves addr after final \n, which is where we want it.
|
||||
nl := ""
|
||||
if q0 > 0 {
|
||||
nl = "\n"
|
||||
}
|
||||
errstr := ""
|
||||
if err != nil {
|
||||
errstr = fmt.Sprintf("\n%s", errstr)
|
||||
}
|
||||
w.Fprintf("data", "%s%s%s%s\n\n", nl, w.time(), trim, errstr)
|
||||
if *acmeDebug {
|
||||
q0, q1, _ := w.ReadAddr()
|
||||
log.Printf("wrote; addr=%d,%d", q0, q1)
|
||||
}
|
||||
w.Fprintf("ctl", "clean\n")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) readAcme() {
|
||||
for {
|
||||
e, err := w.ReadEvent()
|
||||
if err != nil {
|
||||
w.err = err
|
||||
acmeChan <- w
|
||||
break
|
||||
}
|
||||
//fmt.Printf("%c%c %d,%d %d,%d %#x %#q %#q %#q\n", e.C1, e.C2, e.Q0, e.Q1, e.OrigQ0, e.OrigQ1, e.Flag, e.Text, e.Arg, e.Loc)
|
||||
w.Event = e
|
||||
acmeChan <- w
|
||||
acmeChan <- nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Window) readChat() {
|
||||
for {
|
||||
msg, err := client.Recv()
|
||||
if err != nil {
|
||||
msgChan <- &Msg{w: w, err: err}
|
||||
break
|
||||
}
|
||||
//fmt.Printf("%s\n", *msg)
|
||||
msgChan <- &Msg{w: w, Chat: &msg}
|
||||
}
|
||||
}
|
||||
|
||||
func lookContact(you string) *Window {
|
||||
return active["Chat/"+acct.Nick+"/"+you]
|
||||
}
|
||||
|
||||
func showContact(you string) *Window {
|
||||
w := lookContact(you)
|
||||
if w != nil {
|
||||
w.Ctl("show\n")
|
||||
return w
|
||||
}
|
||||
|
||||
ww, err := acme.New()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
name := "Chat/" + acct.Nick + "/" + you
|
||||
ww.Name(name)
|
||||
w = &Window{Win: ww, typ: "chat", name: name, remote: you}
|
||||
w.Fprintf("body", "\n")
|
||||
w.Addr("#1")
|
||||
w.OpenEvent()
|
||||
w.Fprintf("ctl", "cleartag\n")
|
||||
w.Fprintf("tag", " Ack")
|
||||
if p := cachedPresence(you); p != nil {
|
||||
w.status(p)
|
||||
}
|
||||
active[name] = w
|
||||
go w.readAcme()
|
||||
return w
|
||||
}
|
||||
|
||||
func randid() string {
|
||||
return fmt.Sprint(time.Now())
|
||||
}
|
||||
39
vendor/github.com/mattermost/rsc/google/chat.go
сгенерированный
поставляемый
39
vendor/github.com/mattermost/rsc/google/chat.go
сгенерированный
поставляемый
@@ -1,39 +0,0 @@
|
||||
// Copyright 2011 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 google
|
||||
|
||||
import "github.com/mattermost/rsc/xmpp"
|
||||
|
||||
type ChatID struct {
|
||||
ID string
|
||||
Email string
|
||||
Status xmpp.Status
|
||||
StatusMsg string
|
||||
}
|
||||
|
||||
type ChatSend struct {
|
||||
ID *ChatID
|
||||
Msg xmpp.Chat
|
||||
}
|
||||
|
||||
func (g *Client) ChatRecv(cid *ChatID) (*xmpp.Chat, error) {
|
||||
var msg xmpp.Chat
|
||||
if err := g.client.Call("goog.ChatRecv", cid, &msg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &msg, nil
|
||||
}
|
||||
|
||||
func (g *Client) ChatStatus(cid *ChatID) error {
|
||||
return g.client.Call("goog.ChatRecv", cid, &Empty{})
|
||||
}
|
||||
|
||||
func (g *Client) ChatSend(cid *ChatID, msg *xmpp.Chat) error {
|
||||
return g.client.Call("goog.ChatSend", &ChatSend{cid, *msg}, &Empty{})
|
||||
}
|
||||
|
||||
func (g *Client) ChatRoster(cid *ChatID) error {
|
||||
return g.client.Call("goog.ChatRoster", cid, &Empty{})
|
||||
}
|
||||
1241
vendor/github.com/mattermost/rsc/google/gmail/gmail.go
сгенерированный
поставляемый
1241
vendor/github.com/mattermost/rsc/google/gmail/gmail.go
сгенерированный
поставляемый
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
370
vendor/github.com/mattermost/rsc/google/gmailsend/send.go
сгенерированный
поставляемый
370
vendor/github.com/mattermost/rsc/google/gmailsend/send.go
сгенерированный
поставляемый
@@ -1,370 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/smtp"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/rsc/google"
|
||||
)
|
||||
|
||||
func enc(s string) string {
|
||||
// TODO =? .. ?=
|
||||
return s
|
||||
}
|
||||
|
||||
type Addr struct {
|
||||
Name string
|
||||
Email string
|
||||
}
|
||||
|
||||
func (a Addr) enc() string {
|
||||
if a.Name == "" {
|
||||
return "<" + a.Email + ">"
|
||||
}
|
||||
if a.Email == "" {
|
||||
return enc(a.Name) + ":;"
|
||||
}
|
||||
return enc(a.Name) + " <" + a.Email + ">"
|
||||
}
|
||||
|
||||
type Addrs []Addr
|
||||
|
||||
func (a *Addrs) String() string {
|
||||
return "[addrlist]"
|
||||
}
|
||||
|
||||
func (a Addrs) has(s string) bool {
|
||||
for _, aa := range a {
|
||||
if aa.Email == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *Addrs) Set(s string) bool {
|
||||
s = strings.TrimSpace(s)
|
||||
if strings.HasSuffix(s, ">") {
|
||||
j := strings.LastIndex(s, "<")
|
||||
if j >= 0 {
|
||||
*a = append(*a, Addr{strings.TrimSpace(s[:j]), s[j+1 : len(s)-1]})
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if strings.Contains(s, " ") {
|
||||
fmt.Fprintf(os.Stderr, "invalid address: %s", s)
|
||||
os.Exit(2)
|
||||
}
|
||||
*a = append(*a, Addr{"", s})
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *Addrs) parseLine(s string) {
|
||||
for _, f := range strings.Split(s, ",") {
|
||||
f = strings.TrimSpace(f)
|
||||
if f != "" {
|
||||
a.Set(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a Addrs) fixDomain() {
|
||||
i := strings.Index(acct.Email, "@")
|
||||
if i < 0 {
|
||||
return
|
||||
}
|
||||
dom := acct.Email[i:]
|
||||
for i := range a {
|
||||
if a[i].Email != "" && !strings.Contains(a[i].Email, "@") {
|
||||
a[i].Email += dom
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var from, to, cc, bcc, replyTo Addrs
|
||||
var inReplyTo, subject string
|
||||
var appendFile = flag.String("append", "", "file to append to end of body")
|
||||
|
||||
var acct google.Account
|
||||
var acctName = flag.String("a", "", "account to use")
|
||||
var inputHeader = flag.Bool("i", false, "read additional header lines from stdin")
|
||||
|
||||
func holdmode() {
|
||||
if os.Getenv("TERM") == "9term" {
|
||||
// forgive me
|
||||
os.Stdout.WriteString("\x1B];*9term-hold+\x07")
|
||||
}
|
||||
}
|
||||
|
||||
func match(line, prefix string, arg *string) bool {
|
||||
if len(line) < len(prefix) || !strings.EqualFold(line[:len(prefix)], prefix) {
|
||||
return false
|
||||
}
|
||||
*arg = strings.TrimSpace(line[len(prefix):])
|
||||
return true
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.StringVar(&inReplyTo, "in-reply-to", "", "In-Reply-To")
|
||||
flag.StringVar(&subject, "s", "", "Subject")
|
||||
flag.Var(&from, "from", "From (can repeat)")
|
||||
flag.Var(&to, "to", "To (can repeat)")
|
||||
flag.Var(&cc, "cc", "CC (can repeat)")
|
||||
flag.Var(&bcc, "bcc", "BCC (can repeat)")
|
||||
flag.Var(&replyTo, "replyTo", "Reply-To (can repeat)")
|
||||
|
||||
flag.Parse()
|
||||
if flag.NArg() != 0 && !*inputHeader {
|
||||
flag.Usage()
|
||||
}
|
||||
|
||||
var body bytes.Buffer
|
||||
input := bufio.NewReader(os.Stdin)
|
||||
if *inputHeader {
|
||||
holdmode()
|
||||
Loop:
|
||||
for {
|
||||
s, err := input.ReadString('\n')
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break Loop
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "reading stdin: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
var arg string
|
||||
switch {
|
||||
default:
|
||||
if ok, _ := regexp.MatchString(`^\S+:`, s); ok {
|
||||
fmt.Fprintf(os.Stderr, "unknown header line: %s", s)
|
||||
os.Exit(2)
|
||||
}
|
||||
body.WriteString(s)
|
||||
break Loop
|
||||
case match(s, "from:", &arg):
|
||||
from.parseLine(arg)
|
||||
case match(s, "to:", &arg):
|
||||
to.parseLine(arg)
|
||||
case match(s, "cc:", &arg):
|
||||
cc.parseLine(arg)
|
||||
case match(s, "bcc:", &arg):
|
||||
bcc.parseLine(arg)
|
||||
case match(s, "reply-to:", &arg):
|
||||
replyTo.parseLine(arg)
|
||||
case match(s, "subject:", &arg):
|
||||
subject = arg
|
||||
case match(s, "in-reply-to:", &arg):
|
||||
inReplyTo = arg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
acct = google.Acct(*acctName)
|
||||
from.fixDomain()
|
||||
to.fixDomain()
|
||||
cc.fixDomain()
|
||||
bcc.fixDomain()
|
||||
replyTo.fixDomain()
|
||||
|
||||
smtpTo := append(append(to, cc...), bcc...)
|
||||
|
||||
if len(from) == 0 {
|
||||
// TODO: Much better
|
||||
name := ""
|
||||
email := acct.Email
|
||||
if email == "rsc@swtch.com" || email == "rsc@google.com" {
|
||||
name = "Russ Cox"
|
||||
}
|
||||
if email == "rsc@google.com" && (smtpTo.has("go@googlecode.com") || smtpTo.has("golang-dev@googlegroups.com") || smtpTo.has("golang-nuts@googlegroups.com")) {
|
||||
from = append(from, Addr{name, "rsc@golang.org"})
|
||||
} else {
|
||||
from = append(from, Addr{name, email})
|
||||
}
|
||||
}
|
||||
|
||||
if len(from) > 1 {
|
||||
fmt.Fprintf(os.Stderr, "missing -from\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if len(to)+len(cc)+len(bcc) == 0 {
|
||||
fmt.Fprintf(os.Stderr, "missing destinations\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if !*inputHeader {
|
||||
holdmode()
|
||||
}
|
||||
_, err := io.Copy(&body, input)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "reading stdin: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if *appendFile != "" {
|
||||
f, err := os.Open(*appendFile)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "append: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
_, err = io.Copy(&body, f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "append: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
var msg bytes.Buffer
|
||||
fmt.Fprintf(&msg, "MIME-Version: 1.0\n")
|
||||
if len(from) > 0 {
|
||||
fmt.Fprintf(&msg, "From: ")
|
||||
for i, a := range from {
|
||||
if i > 0 {
|
||||
fmt.Fprintf(&msg, ", ")
|
||||
}
|
||||
fmt.Fprintf(&msg, "%s", a.enc())
|
||||
}
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
}
|
||||
if len(to) > 0 {
|
||||
fmt.Fprintf(&msg, "To: ")
|
||||
for i, a := range to {
|
||||
if i > 0 {
|
||||
fmt.Fprintf(&msg, ", ")
|
||||
}
|
||||
fmt.Fprintf(&msg, "%s", a.enc())
|
||||
}
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
}
|
||||
if len(cc) > 0 {
|
||||
fmt.Fprintf(&msg, "CC: ")
|
||||
for i, a := range cc {
|
||||
if i > 0 {
|
||||
fmt.Fprintf(&msg, ", ")
|
||||
}
|
||||
fmt.Fprintf(&msg, "%s", a.enc())
|
||||
}
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
}
|
||||
if len(replyTo) > 0 {
|
||||
fmt.Fprintf(&msg, "Reply-To: ")
|
||||
for i, a := range replyTo {
|
||||
if i > 0 {
|
||||
fmt.Fprintf(&msg, ", ")
|
||||
}
|
||||
fmt.Fprintf(&msg, "%s", a.enc())
|
||||
}
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
}
|
||||
if inReplyTo != "" {
|
||||
fmt.Fprintf(&msg, "In-Reply-To: %s\n", inReplyTo)
|
||||
}
|
||||
if subject != "" {
|
||||
fmt.Fprintf(&msg, "Subject: %s\n", enc(subject))
|
||||
}
|
||||
fmt.Fprintf(&msg, "Date: xxx\n")
|
||||
fmt.Fprintf(&msg, "Content-Type: text/plain; charset=\"utf-8\"\n")
|
||||
fmt.Fprintf(&msg, "Content-Transfer-Encoding: base64\n")
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
enc64 := base64.StdEncoding.EncodeToString(body.Bytes())
|
||||
for len(enc64) > 72 {
|
||||
fmt.Fprintf(&msg, "%s\n", enc64[:72])
|
||||
enc64 = enc64[72:]
|
||||
}
|
||||
fmt.Fprintf(&msg, "%s\n\n", enc64)
|
||||
|
||||
auth := smtp.PlainAuth(
|
||||
"",
|
||||
acct.Email,
|
||||
acct.Password,
|
||||
"smtp.gmail.com",
|
||||
)
|
||||
var smtpToEmail []string
|
||||
for _, a := range smtpTo {
|
||||
if a.Email != "" {
|
||||
smtpToEmail = append(smtpToEmail, a.Email)
|
||||
}
|
||||
}
|
||||
|
||||
if err := sendMail("smtp.gmail.com:587", auth, from[0].Email, smtpToEmail, msg.Bytes()); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "sending mail: %s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
MIME-Version: 1.0
|
||||
Subject: commit/plan9port: rsc: 9term: hold mode back door
|
||||
From: Bitbucket <commits-noreply@bitbucket.org>
|
||||
To: plan9port-dev@googlegroups.com
|
||||
Date: Tue, 11 Oct 2011 13:34:30 -0000
|
||||
Message-ID: <20111011133430.31146.55070@bitbucket13.managed.contegix.com>
|
||||
Reply-To: commits-noreply@bitbucket.org
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
1 new changeset in plan9port:
|
||||
|
||||
http://bitbucket.org/rsc/plan9port/changeset/8735d7708a1b/
|
||||
changeset: 8735d7708a1b
|
||||
user: rsc
|
||||
date: 2011-10-11 15:34:25
|
||||
summary: 9term: hold mode back door
|
||||
|
||||
R=3Drsc
|
||||
http://codereview.appspot.com/5248056
|
||||
affected #: 2 files (-1 bytes)
|
||||
|
||||
Repository URL: https://bitbucket.org/rsc/plan9port/
|
||||
|
||||
--
|
||||
|
||||
This is a commit notification from bitbucket.org. You are receiving
|
||||
this because you have the service enabled, addressing the recipient of
|
||||
this email.
|
||||
|
||||
*/
|
||||
|
||||
func sendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) error {
|
||||
c, err := smtp.Dial(addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = c.StartTLS(nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = c.Auth(a); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = c.Mail(from); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, addr := range to {
|
||||
if err = c.Rcpt(addr); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
w, err := c.Data()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = w.Write(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = w.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.Quit()
|
||||
}
|
||||
80
vendor/github.com/mattermost/rsc/google/googleserver/chat.go
сгенерированный
поставляемый
80
vendor/github.com/mattermost/rsc/google/googleserver/chat.go
сгенерированный
поставляемый
@@ -1,80 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// TODO: Add ChatHangup.
|
||||
// TODO: Auto-hangup chats that are gone.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/rsc/google"
|
||||
"github.com/mattermost/rsc/xmpp"
|
||||
)
|
||||
|
||||
type chatClient struct {
|
||||
email string
|
||||
id string
|
||||
xmpp *xmpp.Client
|
||||
}
|
||||
|
||||
var chatClients = map[string]*chatClient{}
|
||||
|
||||
func (*Server) chatClient(cid *google.ChatID) (*chatClient, error) {
|
||||
id := cid.ID
|
||||
cc := chatClients[cid.ID]
|
||||
if cc == nil {
|
||||
a := google.Cfg.AccountByEmail(cid.Email)
|
||||
if a == nil {
|
||||
return nil, fmt.Errorf("unknown account %s", cid.Email)
|
||||
}
|
||||
// New client.
|
||||
cli, err := xmpp.NewClient("talk.google.com:443", a.Email, a.Password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cc = &chatClient{email: a.Email, id: id, xmpp: cli}
|
||||
cc.xmpp.Status(cid.Status, cid.StatusMsg)
|
||||
chatClients[id] = cc
|
||||
}
|
||||
return cc, nil
|
||||
}
|
||||
|
||||
func (srv *Server) ChatRecv(cid *google.ChatID, msg *xmpp.Chat) error {
|
||||
cc, err := srv.chatClient(cid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
chat, err := cc.xmpp.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*msg = chat
|
||||
return nil
|
||||
}
|
||||
|
||||
func (srv *Server) ChatStatus(cid *google.ChatID, _ *Empty) error {
|
||||
cc, err := srv.chatClient(cid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cc.xmpp.Status(cid.Status, cid.StatusMsg)
|
||||
}
|
||||
|
||||
func (srv *Server) ChatSend(arg *google.ChatSend, _ *Empty) error {
|
||||
cc, err := srv.chatClient(arg.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cc.xmpp.Send(arg.Msg)
|
||||
}
|
||||
|
||||
func (srv *Server) ChatRoster(cid *google.ChatID, _ *Empty) error {
|
||||
cc, err := srv.chatClient(cid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cc.xmpp.Roster()
|
||||
}
|
||||
139
vendor/github.com/mattermost/rsc/google/googleserver/main.go
сгенерированный
поставляемый
139
vendor/github.com/mattermost/rsc/google/googleserver/main.go
сгенерированный
поставляемый
@@ -1,139 +0,0 @@
|
||||
// Copyright 2011 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 main
|
||||
|
||||
import (
|
||||
// "flag"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/mattermost/rsc/google"
|
||||
"github.com/mattermost/rsc/xmpp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
google.ReadConfig()
|
||||
switch os.Args[1] {
|
||||
case "add":
|
||||
google.Cfg.Account = append(google.Cfg.Account, &google.Account{Email: os.Args[2], Password: os.Args[3]})
|
||||
google.WriteConfig()
|
||||
case "serve":
|
||||
serve()
|
||||
case "accounts":
|
||||
c, err := google.Dial()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
out, err := c.Accounts()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, email := range out {
|
||||
fmt.Printf("%s\n", email)
|
||||
}
|
||||
case "ping":
|
||||
c, err := google.Dial()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := c.Ping(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
case "chat":
|
||||
c, err := google.Dial()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
cid := &google.ChatID{ID: "1", Email: os.Args[2], Status: xmpp.Available, StatusMsg: ""}
|
||||
go chatRecv(c, cid)
|
||||
c.ChatRoster(cid)
|
||||
b := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
line, err := b.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
line = line[:len(line)-1]
|
||||
i := strings.Index(line, ": ")
|
||||
if i < 0 {
|
||||
log.Printf("<who>: <msg>, please")
|
||||
continue
|
||||
}
|
||||
who, msg := line[:i], line[i+2:]
|
||||
if err := c.ChatSend(cid, &xmpp.Chat{Remote: who, Type: "chat", Text: msg}); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func chatRecv(c *google.Client, cid *google.ChatID) {
|
||||
for {
|
||||
msg, err := c.ChatRecv(cid)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
switch msg.Type {
|
||||
case "roster":
|
||||
for _, contact := range msg.Roster {
|
||||
fmt.Printf("%v\n", contact)
|
||||
}
|
||||
case "presence":
|
||||
fmt.Printf("%v\n", msg.Presence)
|
||||
case "chat":
|
||||
fmt.Printf("%s: %s\n", msg.Remote, msg.Text)
|
||||
default:
|
||||
fmt.Printf("<%s>\n", msg.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func listen() net.Listener {
|
||||
socket := google.Dir() + "/socket"
|
||||
os.Remove(socket)
|
||||
l, err := net.Listen("unix", socket)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func serve() {
|
||||
f, err := os.OpenFile(google.Dir()+"/log", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0600)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.SetOutput(f)
|
||||
syscall.Dup2(f.Fd(), 2)
|
||||
os.Stdout = f
|
||||
os.Stderr = f
|
||||
l := listen()
|
||||
rpc.RegisterName("goog", &Server{})
|
||||
rpc.Accept(l)
|
||||
log.Fatal("rpc.Accept finished: server exiting")
|
||||
}
|
||||
|
||||
type Server struct{}
|
||||
|
||||
type Empty google.Empty
|
||||
|
||||
func (*Server) Ping(*Empty, *Empty) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*Server) Accounts(_ *Empty, out *[]string) error {
|
||||
var email []string
|
||||
for _, a := range google.Cfg.Account {
|
||||
email = append(email, a.Email)
|
||||
}
|
||||
*out = email
|
||||
return nil
|
||||
}
|
||||
181
vendor/github.com/mattermost/rsc/google/main.go
сгенерированный
поставляемый
181
vendor/github.com/mattermost/rsc/google/main.go
сгенерированный
поставляемый
@@ -1,181 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// TODO: Something about redialing.
|
||||
|
||||
package google
|
||||
|
||||
import (
|
||||
// "flag"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/rpc"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Dir() string {
|
||||
dir := os.Getenv("HOME") + "/.goog"
|
||||
st, err := os.Stat(dir)
|
||||
if err != nil {
|
||||
if err := os.Mkdir(dir, 0700); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
st, err = os.Stat(dir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if !st.IsDir() {
|
||||
log.Fatalf("%s exists but is not a directory", dir)
|
||||
}
|
||||
if st.Mode()&0077 != 0 {
|
||||
log.Fatalf("%s exists but allows group or other permissions: %#o", dir, st.Mode()&0777)
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
func Dial() (*Client, error) {
|
||||
socket := Dir() + "/socket"
|
||||
c, err := net.Dial("unix", socket)
|
||||
if err == nil {
|
||||
return &Client{rpc.NewClient(c)}, nil
|
||||
}
|
||||
log.Print("starting server")
|
||||
os.Remove(socket)
|
||||
runServer()
|
||||
for i := 0; i < 50; i++ {
|
||||
c, err = net.Dial("unix", socket)
|
||||
if err == nil {
|
||||
return &Client{rpc.NewClient(c)}, nil
|
||||
}
|
||||
time.Sleep(200e6)
|
||||
if i == 0 {
|
||||
log.Print("waiting for server...")
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
client *rpc.Client
|
||||
}
|
||||
|
||||
type Empty struct{}
|
||||
|
||||
func (g *Client) Ping() error {
|
||||
return g.client.Call("goog.Ping", &Empty{}, &Empty{})
|
||||
}
|
||||
|
||||
func (g *Client) Accounts() ([]string, error) {
|
||||
var out []string
|
||||
if err := g.client.Call("goog.Accounts", &Empty{}, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func runServer() {
|
||||
cmd := exec.Command("googleserver", "serve")
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Account []*Account
|
||||
}
|
||||
|
||||
type Account struct {
|
||||
Email string
|
||||
Password string
|
||||
Nick string
|
||||
}
|
||||
|
||||
func (cfg *Config) AccountByEmail(email string) *Account {
|
||||
for _, a := range cfg.Account {
|
||||
if a.Email == email {
|
||||
return a
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var Cfg Config
|
||||
|
||||
func ReadConfig() {
|
||||
file := Dir() + "/config"
|
||||
st, err := os.Stat(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if st.Mode()&0077 != 0 {
|
||||
log.Fatalf("%s exists but allows group or other permissions: %#o", file, st.Mode()&0777)
|
||||
}
|
||||
data, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
Cfg = Config{}
|
||||
if err := json.Unmarshal(data, &Cfg); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func WriteConfig() {
|
||||
file := Dir() + "/config"
|
||||
st, err := os.Stat(file)
|
||||
if err != nil {
|
||||
if err := ioutil.WriteFile(file, nil, 0600); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
st, err = os.Stat(file)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if st.Mode()&0077 != 0 {
|
||||
log.Fatalf("%s exists but allows group or other permissions: %#o", file, st.Mode()&0777)
|
||||
}
|
||||
data, err := json.MarshalIndent(&Cfg, "", "\t")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := ioutil.WriteFile(file, data, 0600); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
st, err = os.Stat(file)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if st.Mode()&0077 != 0 {
|
||||
log.Fatalf("%s allows group or other permissions after writing: %#o", file, st.Mode()&0777)
|
||||
}
|
||||
}
|
||||
|
||||
func Acct(name string) Account {
|
||||
ReadConfig()
|
||||
if name == "" {
|
||||
if len(Cfg.Account) == 0 {
|
||||
fmt.Fprintf(os.Stderr, "no accounts configured\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
return *Cfg.Account[0]
|
||||
}
|
||||
|
||||
for _, a := range Cfg.Account {
|
||||
if a.Email == name || a.Nick == name {
|
||||
return *a
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "cannot find account %#q", name)
|
||||
os.Exit(2)
|
||||
panic("not reached")
|
||||
}
|
||||
440
vendor/github.com/mattermost/rsc/gtfs/gtfs.pb.go
сгенерированный
поставляемый
440
vendor/github.com/mattermost/rsc/gtfs/gtfs.pb.go
сгенерированный
поставляемый
@@ -1,440 +0,0 @@
|
||||
// Code generated by protoc-gen-go from "crashme/gtfs.proto"
|
||||
// DO NOT EDIT!
|
||||
|
||||
package gtfs
|
||||
|
||||
import proto "code.google.com/p/goprotobuf/proto"
|
||||
import "math"
|
||||
|
||||
// Reference proto, math & os imports to suppress error if they are not otherwise used.
|
||||
var _ = proto.GetString
|
||||
var _ = math.Inf
|
||||
var _ error
|
||||
|
||||
type FeedHeader_Incrementality int32
|
||||
|
||||
const (
|
||||
FeedHeader_FULL_DATASET FeedHeader_Incrementality = 0
|
||||
FeedHeader_DIFFERENTIAL FeedHeader_Incrementality = 1
|
||||
)
|
||||
|
||||
var FeedHeader_Incrementality_name = map[int32]string{
|
||||
0: "FULL_DATASET",
|
||||
1: "DIFFERENTIAL",
|
||||
}
|
||||
var FeedHeader_Incrementality_value = map[string]int32{
|
||||
"FULL_DATASET": 0,
|
||||
"DIFFERENTIAL": 1,
|
||||
}
|
||||
|
||||
func NewFeedHeader_Incrementality(x FeedHeader_Incrementality) *FeedHeader_Incrementality {
|
||||
e := FeedHeader_Incrementality(x)
|
||||
return &e
|
||||
}
|
||||
func (x FeedHeader_Incrementality) String() string {
|
||||
return proto.EnumName(FeedHeader_Incrementality_name, int32(x))
|
||||
}
|
||||
|
||||
type TripUpdate_StopTimeUpdate_ScheduleRelationship int32
|
||||
|
||||
const (
|
||||
TripUpdate_StopTimeUpdate_SCHEDULED TripUpdate_StopTimeUpdate_ScheduleRelationship = 0
|
||||
TripUpdate_StopTimeUpdate_SKIPPED TripUpdate_StopTimeUpdate_ScheduleRelationship = 1
|
||||
TripUpdate_StopTimeUpdate_NO_DATA TripUpdate_StopTimeUpdate_ScheduleRelationship = 2
|
||||
)
|
||||
|
||||
var TripUpdate_StopTimeUpdate_ScheduleRelationship_name = map[int32]string{
|
||||
0: "SCHEDULED",
|
||||
1: "SKIPPED",
|
||||
2: "NO_DATA",
|
||||
}
|
||||
var TripUpdate_StopTimeUpdate_ScheduleRelationship_value = map[string]int32{
|
||||
"SCHEDULED": 0,
|
||||
"SKIPPED": 1,
|
||||
"NO_DATA": 2,
|
||||
}
|
||||
|
||||
func NewTripUpdate_StopTimeUpdate_ScheduleRelationship(x TripUpdate_StopTimeUpdate_ScheduleRelationship) *TripUpdate_StopTimeUpdate_ScheduleRelationship {
|
||||
e := TripUpdate_StopTimeUpdate_ScheduleRelationship(x)
|
||||
return &e
|
||||
}
|
||||
func (x TripUpdate_StopTimeUpdate_ScheduleRelationship) String() string {
|
||||
return proto.EnumName(TripUpdate_StopTimeUpdate_ScheduleRelationship_name, int32(x))
|
||||
}
|
||||
|
||||
type VehiclePosition_VehicleStopStatus int32
|
||||
|
||||
const (
|
||||
VehiclePosition_INCOMING_AT VehiclePosition_VehicleStopStatus = 0
|
||||
VehiclePosition_STOPPED_AT VehiclePosition_VehicleStopStatus = 1
|
||||
VehiclePosition_IN_TRANSIT_TO VehiclePosition_VehicleStopStatus = 2
|
||||
)
|
||||
|
||||
var VehiclePosition_VehicleStopStatus_name = map[int32]string{
|
||||
0: "INCOMING_AT",
|
||||
1: "STOPPED_AT",
|
||||
2: "IN_TRANSIT_TO",
|
||||
}
|
||||
var VehiclePosition_VehicleStopStatus_value = map[string]int32{
|
||||
"INCOMING_AT": 0,
|
||||
"STOPPED_AT": 1,
|
||||
"IN_TRANSIT_TO": 2,
|
||||
}
|
||||
|
||||
func NewVehiclePosition_VehicleStopStatus(x VehiclePosition_VehicleStopStatus) *VehiclePosition_VehicleStopStatus {
|
||||
e := VehiclePosition_VehicleStopStatus(x)
|
||||
return &e
|
||||
}
|
||||
func (x VehiclePosition_VehicleStopStatus) String() string {
|
||||
return proto.EnumName(VehiclePosition_VehicleStopStatus_name, int32(x))
|
||||
}
|
||||
|
||||
type VehiclePosition_CongestionLevel int32
|
||||
|
||||
const (
|
||||
VehiclePosition_UNKNOWN_CONGESTION_LEVEL VehiclePosition_CongestionLevel = 0
|
||||
VehiclePosition_RUNNING_SMOOTHLY VehiclePosition_CongestionLevel = 1
|
||||
VehiclePosition_STOP_AND_GO VehiclePosition_CongestionLevel = 2
|
||||
VehiclePosition_CONGESTION VehiclePosition_CongestionLevel = 3
|
||||
VehiclePosition_SEVERE_CONGESTION VehiclePosition_CongestionLevel = 4
|
||||
)
|
||||
|
||||
var VehiclePosition_CongestionLevel_name = map[int32]string{
|
||||
0: "UNKNOWN_CONGESTION_LEVEL",
|
||||
1: "RUNNING_SMOOTHLY",
|
||||
2: "STOP_AND_GO",
|
||||
3: "CONGESTION",
|
||||
4: "SEVERE_CONGESTION",
|
||||
}
|
||||
var VehiclePosition_CongestionLevel_value = map[string]int32{
|
||||
"UNKNOWN_CONGESTION_LEVEL": 0,
|
||||
"RUNNING_SMOOTHLY": 1,
|
||||
"STOP_AND_GO": 2,
|
||||
"CONGESTION": 3,
|
||||
"SEVERE_CONGESTION": 4,
|
||||
}
|
||||
|
||||
func NewVehiclePosition_CongestionLevel(x VehiclePosition_CongestionLevel) *VehiclePosition_CongestionLevel {
|
||||
e := VehiclePosition_CongestionLevel(x)
|
||||
return &e
|
||||
}
|
||||
func (x VehiclePosition_CongestionLevel) String() string {
|
||||
return proto.EnumName(VehiclePosition_CongestionLevel_name, int32(x))
|
||||
}
|
||||
|
||||
type Alert_Cause int32
|
||||
|
||||
const (
|
||||
Alert_UNKNOWN_CAUSE Alert_Cause = 1
|
||||
Alert_OTHER_CAUSE Alert_Cause = 2
|
||||
Alert_TECHNICAL_PROBLEM Alert_Cause = 3
|
||||
Alert_STRIKE Alert_Cause = 4
|
||||
Alert_DEMONSTRATION Alert_Cause = 5
|
||||
Alert_ACCIDENT Alert_Cause = 6
|
||||
Alert_HOLIDAY Alert_Cause = 7
|
||||
Alert_WEATHER Alert_Cause = 8
|
||||
Alert_MAINTENANCE Alert_Cause = 9
|
||||
Alert_CONSTRUCTION Alert_Cause = 10
|
||||
Alert_POLICE_ACTIVITY Alert_Cause = 11
|
||||
Alert_MEDICAL_EMERGENCY Alert_Cause = 12
|
||||
)
|
||||
|
||||
var Alert_Cause_name = map[int32]string{
|
||||
1: "UNKNOWN_CAUSE",
|
||||
2: "OTHER_CAUSE",
|
||||
3: "TECHNICAL_PROBLEM",
|
||||
4: "STRIKE",
|
||||
5: "DEMONSTRATION",
|
||||
6: "ACCIDENT",
|
||||
7: "HOLIDAY",
|
||||
8: "WEATHER",
|
||||
9: "MAINTENANCE",
|
||||
10: "CONSTRUCTION",
|
||||
11: "POLICE_ACTIVITY",
|
||||
12: "MEDICAL_EMERGENCY",
|
||||
}
|
||||
var Alert_Cause_value = map[string]int32{
|
||||
"UNKNOWN_CAUSE": 1,
|
||||
"OTHER_CAUSE": 2,
|
||||
"TECHNICAL_PROBLEM": 3,
|
||||
"STRIKE": 4,
|
||||
"DEMONSTRATION": 5,
|
||||
"ACCIDENT": 6,
|
||||
"HOLIDAY": 7,
|
||||
"WEATHER": 8,
|
||||
"MAINTENANCE": 9,
|
||||
"CONSTRUCTION": 10,
|
||||
"POLICE_ACTIVITY": 11,
|
||||
"MEDICAL_EMERGENCY": 12,
|
||||
}
|
||||
|
||||
func NewAlert_Cause(x Alert_Cause) *Alert_Cause {
|
||||
e := Alert_Cause(x)
|
||||
return &e
|
||||
}
|
||||
func (x Alert_Cause) String() string {
|
||||
return proto.EnumName(Alert_Cause_name, int32(x))
|
||||
}
|
||||
|
||||
type Alert_Effect int32
|
||||
|
||||
const (
|
||||
Alert_NO_SERVICE Alert_Effect = 1
|
||||
Alert_REDUCED_SERVICE Alert_Effect = 2
|
||||
Alert_SIGNIFICANT_DELAYS Alert_Effect = 3
|
||||
Alert_DETOUR Alert_Effect = 4
|
||||
Alert_ADDITIONAL_SERVICE Alert_Effect = 5
|
||||
Alert_MODIFIED_SERVICE Alert_Effect = 6
|
||||
Alert_OTHER_EFFECT Alert_Effect = 7
|
||||
Alert_UNKNOWN_EFFECT Alert_Effect = 8
|
||||
Alert_STOP_MOVED Alert_Effect = 9
|
||||
)
|
||||
|
||||
var Alert_Effect_name = map[int32]string{
|
||||
1: "NO_SERVICE",
|
||||
2: "REDUCED_SERVICE",
|
||||
3: "SIGNIFICANT_DELAYS",
|
||||
4: "DETOUR",
|
||||
5: "ADDITIONAL_SERVICE",
|
||||
6: "MODIFIED_SERVICE",
|
||||
7: "OTHER_EFFECT",
|
||||
8: "UNKNOWN_EFFECT",
|
||||
9: "STOP_MOVED",
|
||||
}
|
||||
var Alert_Effect_value = map[string]int32{
|
||||
"NO_SERVICE": 1,
|
||||
"REDUCED_SERVICE": 2,
|
||||
"SIGNIFICANT_DELAYS": 3,
|
||||
"DETOUR": 4,
|
||||
"ADDITIONAL_SERVICE": 5,
|
||||
"MODIFIED_SERVICE": 6,
|
||||
"OTHER_EFFECT": 7,
|
||||
"UNKNOWN_EFFECT": 8,
|
||||
"STOP_MOVED": 9,
|
||||
}
|
||||
|
||||
func NewAlert_Effect(x Alert_Effect) *Alert_Effect {
|
||||
e := Alert_Effect(x)
|
||||
return &e
|
||||
}
|
||||
func (x Alert_Effect) String() string {
|
||||
return proto.EnumName(Alert_Effect_name, int32(x))
|
||||
}
|
||||
|
||||
type TripDescriptor_ScheduleRelationship int32
|
||||
|
||||
const (
|
||||
TripDescriptor_SCHEDULED TripDescriptor_ScheduleRelationship = 0
|
||||
TripDescriptor_ADDED TripDescriptor_ScheduleRelationship = 1
|
||||
TripDescriptor_UNSCHEDULED TripDescriptor_ScheduleRelationship = 2
|
||||
TripDescriptor_CANCELED TripDescriptor_ScheduleRelationship = 3
|
||||
TripDescriptor_REPLACEMENT TripDescriptor_ScheduleRelationship = 5
|
||||
)
|
||||
|
||||
var TripDescriptor_ScheduleRelationship_name = map[int32]string{
|
||||
0: "SCHEDULED",
|
||||
1: "ADDED",
|
||||
2: "UNSCHEDULED",
|
||||
3: "CANCELED",
|
||||
5: "REPLACEMENT",
|
||||
}
|
||||
var TripDescriptor_ScheduleRelationship_value = map[string]int32{
|
||||
"SCHEDULED": 0,
|
||||
"ADDED": 1,
|
||||
"UNSCHEDULED": 2,
|
||||
"CANCELED": 3,
|
||||
"REPLACEMENT": 5,
|
||||
}
|
||||
|
||||
func NewTripDescriptor_ScheduleRelationship(x TripDescriptor_ScheduleRelationship) *TripDescriptor_ScheduleRelationship {
|
||||
e := TripDescriptor_ScheduleRelationship(x)
|
||||
return &e
|
||||
}
|
||||
func (x TripDescriptor_ScheduleRelationship) String() string {
|
||||
return proto.EnumName(TripDescriptor_ScheduleRelationship_name, int32(x))
|
||||
}
|
||||
|
||||
type FeedMessage struct {
|
||||
Header *FeedHeader `protobuf:"bytes,1,req,name=header" json:"header"`
|
||||
Entity []*FeedEntity `protobuf:"bytes,2,rep,name=entity" json:"entity"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *FeedMessage) Reset() { *this = FeedMessage{} }
|
||||
func (this *FeedMessage) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type FeedHeader struct {
|
||||
GtfsRealtimeVersion *string `protobuf:"bytes,1,req,name=gtfs_realtime_version" json:"gtfs_realtime_version"`
|
||||
Incrementality *FeedHeader_Incrementality `protobuf:"varint,2,opt,name=incrementality,enum=transit_realtime.FeedHeader_Incrementality,def=0" json:"incrementality"`
|
||||
Timestamp *uint64 `protobuf:"varint,3,opt,name=timestamp" json:"timestamp"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *FeedHeader) Reset() { *this = FeedHeader{} }
|
||||
func (this *FeedHeader) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
const Default_FeedHeader_Incrementality FeedHeader_Incrementality = FeedHeader_FULL_DATASET
|
||||
|
||||
type FeedEntity struct {
|
||||
Id *string `protobuf:"bytes,1,req,name=id" json:"id"`
|
||||
IsDeleted *bool `protobuf:"varint,2,opt,name=is_deleted,def=0" json:"is_deleted"`
|
||||
TripUpdate *TripUpdate `protobuf:"bytes,3,opt,name=trip_update" json:"trip_update"`
|
||||
Vehicle *VehiclePosition `protobuf:"bytes,4,opt,name=vehicle" json:"vehicle"`
|
||||
Alert *Alert `protobuf:"bytes,5,opt,name=alert" json:"alert"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *FeedEntity) Reset() { *this = FeedEntity{} }
|
||||
func (this *FeedEntity) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
const Default_FeedEntity_IsDeleted bool = false
|
||||
|
||||
type TripUpdate struct {
|
||||
Trip *TripDescriptor `protobuf:"bytes,1,req,name=trip" json:"trip"`
|
||||
Vehicle *VehicleDescriptor `protobuf:"bytes,3,opt,name=vehicle" json:"vehicle"`
|
||||
StopTimeUpdate []*TripUpdate_StopTimeUpdate `protobuf:"bytes,2,rep,name=stop_time_update" json:"stop_time_update"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *TripUpdate) Reset() { *this = TripUpdate{} }
|
||||
func (this *TripUpdate) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type TripUpdate_StopTimeEvent struct {
|
||||
Delay *int32 `protobuf:"varint,1,opt,name=delay" json:"delay"`
|
||||
Time *int64 `protobuf:"varint,2,opt,name=time" json:"time"`
|
||||
Uncertainty *int32 `protobuf:"varint,3,opt,name=uncertainty" json:"uncertainty"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *TripUpdate_StopTimeEvent) Reset() { *this = TripUpdate_StopTimeEvent{} }
|
||||
func (this *TripUpdate_StopTimeEvent) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type TripUpdate_StopTimeUpdate struct {
|
||||
StopSequence *uint32 `protobuf:"varint,1,opt,name=stop_sequence" json:"stop_sequence"`
|
||||
StopId *string `protobuf:"bytes,4,opt,name=stop_id" json:"stop_id"`
|
||||
Arrival *TripUpdate_StopTimeEvent `protobuf:"bytes,2,opt,name=arrival" json:"arrival"`
|
||||
Departure *TripUpdate_StopTimeEvent `protobuf:"bytes,3,opt,name=departure" json:"departure"`
|
||||
ScheduleRelationship *TripUpdate_StopTimeUpdate_ScheduleRelationship `protobuf:"varint,5,opt,name=schedule_relationship,enum=transit_realtime.TripUpdate_StopTimeUpdate_ScheduleRelationship,def=0" json:"schedule_relationship"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *TripUpdate_StopTimeUpdate) Reset() { *this = TripUpdate_StopTimeUpdate{} }
|
||||
func (this *TripUpdate_StopTimeUpdate) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
const Default_TripUpdate_StopTimeUpdate_ScheduleRelationship TripUpdate_StopTimeUpdate_ScheduleRelationship = TripUpdate_StopTimeUpdate_SCHEDULED
|
||||
|
||||
type VehiclePosition struct {
|
||||
Trip *TripDescriptor `protobuf:"bytes,1,opt,name=trip" json:"trip"`
|
||||
Vehicle *VehicleDescriptor `protobuf:"bytes,8,opt,name=vehicle" json:"vehicle"`
|
||||
Position *Position `protobuf:"bytes,2,opt,name=position" json:"position"`
|
||||
CurrentStopSequence *uint32 `protobuf:"varint,3,opt,name=current_stop_sequence" json:"current_stop_sequence"`
|
||||
StopId *string `protobuf:"bytes,7,opt,name=stop_id" json:"stop_id"`
|
||||
CurrentStatus *VehiclePosition_VehicleStopStatus `protobuf:"varint,4,opt,name=current_status,enum=transit_realtime.VehiclePosition_VehicleStopStatus,def=2" json:"current_status"`
|
||||
Timestamp *uint64 `protobuf:"varint,5,opt,name=timestamp" json:"timestamp"`
|
||||
CongestionLevel *VehiclePosition_CongestionLevel `protobuf:"varint,6,opt,name=congestion_level,enum=transit_realtime.VehiclePosition_CongestionLevel" json:"congestion_level"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *VehiclePosition) Reset() { *this = VehiclePosition{} }
|
||||
func (this *VehiclePosition) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
const Default_VehiclePosition_CurrentStatus VehiclePosition_VehicleStopStatus = VehiclePosition_IN_TRANSIT_TO
|
||||
|
||||
type Alert struct {
|
||||
ActivePeriod []*TimeRange `protobuf:"bytes,1,rep,name=active_period" json:"active_period"`
|
||||
InformedEntity []*EntitySelector `protobuf:"bytes,5,rep,name=informed_entity" json:"informed_entity"`
|
||||
Cause *Alert_Cause `protobuf:"varint,6,opt,name=cause,enum=transit_realtime.Alert_Cause,def=1" json:"cause"`
|
||||
Effect *Alert_Effect `protobuf:"varint,7,opt,name=effect,enum=transit_realtime.Alert_Effect,def=8" json:"effect"`
|
||||
Url *TranslatedString `protobuf:"bytes,8,opt,name=url" json:"url"`
|
||||
HeaderText *TranslatedString `protobuf:"bytes,10,opt,name=header_text" json:"header_text"`
|
||||
DescriptionText *TranslatedString `protobuf:"bytes,11,opt,name=description_text" json:"description_text"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *Alert) Reset() { *this = Alert{} }
|
||||
func (this *Alert) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
const Default_Alert_Cause Alert_Cause = Alert_UNKNOWN_CAUSE
|
||||
const Default_Alert_Effect Alert_Effect = Alert_UNKNOWN_EFFECT
|
||||
|
||||
type TimeRange struct {
|
||||
Start *uint64 `protobuf:"varint,1,opt,name=start" json:"start"`
|
||||
End *uint64 `protobuf:"varint,2,opt,name=end" json:"end"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *TimeRange) Reset() { *this = TimeRange{} }
|
||||
func (this *TimeRange) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type Position struct {
|
||||
Latitude *float32 `protobuf:"fixed32,1,req,name=latitude" json:"latitude"`
|
||||
Longitude *float32 `protobuf:"fixed32,2,req,name=longitude" json:"longitude"`
|
||||
Bearing *float32 `protobuf:"fixed32,3,opt,name=bearing" json:"bearing"`
|
||||
Odometer *float64 `protobuf:"fixed64,4,opt,name=odometer" json:"odometer"`
|
||||
Speed *float32 `protobuf:"fixed32,5,opt,name=speed" json:"speed"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *Position) Reset() { *this = Position{} }
|
||||
func (this *Position) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type TripDescriptor struct {
|
||||
TripId *string `protobuf:"bytes,1,opt,name=trip_id" json:"trip_id"`
|
||||
RouteId *string `protobuf:"bytes,5,opt,name=route_id" json:"route_id"`
|
||||
StartTime *string `protobuf:"bytes,2,opt,name=start_time" json:"start_time"`
|
||||
StartDate *string `protobuf:"bytes,3,opt,name=start_date" json:"start_date"`
|
||||
ScheduleRelationship *TripDescriptor_ScheduleRelationship `protobuf:"varint,4,opt,name=schedule_relationship,enum=transit_realtime.TripDescriptor_ScheduleRelationship" json:"schedule_relationship"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *TripDescriptor) Reset() { *this = TripDescriptor{} }
|
||||
func (this *TripDescriptor) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type VehicleDescriptor struct {
|
||||
Id *string `protobuf:"bytes,1,opt,name=id" json:"id"`
|
||||
Label *string `protobuf:"bytes,2,opt,name=label" json:"label"`
|
||||
LicensePlate *string `protobuf:"bytes,3,opt,name=license_plate" json:"license_plate"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *VehicleDescriptor) Reset() { *this = VehicleDescriptor{} }
|
||||
func (this *VehicleDescriptor) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type EntitySelector struct {
|
||||
AgencyId *string `protobuf:"bytes,1,opt,name=agency_id" json:"agency_id"`
|
||||
RouteId *string `protobuf:"bytes,2,opt,name=route_id" json:"route_id"`
|
||||
RouteType *int32 `protobuf:"varint,3,opt,name=route_type" json:"route_type"`
|
||||
Trip *TripDescriptor `protobuf:"bytes,4,opt,name=trip" json:"trip"`
|
||||
StopId *string `protobuf:"bytes,5,opt,name=stop_id" json:"stop_id"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *EntitySelector) Reset() { *this = EntitySelector{} }
|
||||
func (this *EntitySelector) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type TranslatedString struct {
|
||||
Translation []*TranslatedString_Translation `protobuf:"bytes,1,rep,name=translation" json:"translation"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *TranslatedString) Reset() { *this = TranslatedString{} }
|
||||
func (this *TranslatedString) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
type TranslatedString_Translation struct {
|
||||
Text *string `protobuf:"bytes,1,req,name=text" json:"text"`
|
||||
Language *string `protobuf:"bytes,2,opt,name=language" json:"language"`
|
||||
XXX_unrecognized []byte
|
||||
}
|
||||
|
||||
func (this *TranslatedString_Translation) Reset() { *this = TranslatedString_Translation{} }
|
||||
func (this *TranslatedString_Translation) String() string { return proto.CompactTextString(this) }
|
||||
|
||||
func init() {
|
||||
proto.RegisterEnum("transit_realtime.FeedHeader_Incrementality", FeedHeader_Incrementality_name, FeedHeader_Incrementality_value)
|
||||
proto.RegisterEnum("transit_realtime.TripUpdate_StopTimeUpdate_ScheduleRelationship", TripUpdate_StopTimeUpdate_ScheduleRelationship_name, TripUpdate_StopTimeUpdate_ScheduleRelationship_value)
|
||||
proto.RegisterEnum("transit_realtime.VehiclePosition_VehicleStopStatus", VehiclePosition_VehicleStopStatus_name, VehiclePosition_VehicleStopStatus_value)
|
||||
proto.RegisterEnum("transit_realtime.VehiclePosition_CongestionLevel", VehiclePosition_CongestionLevel_name, VehiclePosition_CongestionLevel_value)
|
||||
proto.RegisterEnum("transit_realtime.Alert_Cause", Alert_Cause_name, Alert_Cause_value)
|
||||
proto.RegisterEnum("transit_realtime.Alert_Effect", Alert_Effect_name, Alert_Effect_value)
|
||||
proto.RegisterEnum("transit_realtime.TripDescriptor_ScheduleRelationship", TripDescriptor_ScheduleRelationship_name, TripDescriptor_ScheduleRelationship_value)
|
||||
}
|
||||
15
vendor/github.com/mattermost/rsc/imap/Makefile
сгенерированный
поставляемый
15
vendor/github.com/mattermost/rsc/imap/Makefile
сгенерированный
поставляемый
@@ -1,15 +0,0 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
# TARG=code.google.com/p/rsc/imap
|
||||
|
||||
TARG=rsc.googlecode.com/hg/imap
|
||||
GOFILES=\
|
||||
decode.go\
|
||||
imap.go\
|
||||
mail.go\
|
||||
sx.go\
|
||||
tcs.go\
|
||||
|
||||
GCIMPORTS=-I$(GOPATH)/pkg/$(GOOS)_$(GOARCH)
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
||||
227
vendor/github.com/mattermost/rsc/imap/decode.go
сгенерированный
поставляемый
227
vendor/github.com/mattermost/rsc/imap/decode.go
сгенерированный
поставляемый
@@ -1,227 +0,0 @@
|
||||
package imap
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
func decode2047chunk(s string) (conv []byte, rest string, ok bool) {
|
||||
// s is =?...
|
||||
// and should be =?charset?e?text?=
|
||||
j := strings.Index(s[2:], "?")
|
||||
if j < 0 {
|
||||
return
|
||||
}
|
||||
j += 2
|
||||
if j+2 >= len(s) || s[j+2] != '?' {
|
||||
return
|
||||
}
|
||||
k := strings.Index(s[j+3:], "?=")
|
||||
if k < 0 {
|
||||
return
|
||||
}
|
||||
k += j + 3
|
||||
|
||||
charset, enc, text, rest := s[2:j], s[j+1], s[j+3:k], s[k+2:]
|
||||
var encoding string
|
||||
switch enc {
|
||||
default:
|
||||
return
|
||||
case 'q', 'Q':
|
||||
encoding = "quoted-printable"
|
||||
case 'b', 'B':
|
||||
encoding = "base64"
|
||||
}
|
||||
|
||||
dat := decodeText([]byte(text), encoding, charset, true)
|
||||
if dat == nil {
|
||||
return
|
||||
}
|
||||
return dat, rest, true
|
||||
}
|
||||
|
||||
func decodeQP(dat []byte, underscore bool) []byte {
|
||||
out := make([]byte, len(dat))
|
||||
w := 0
|
||||
for i := 0; i < len(dat); i++ {
|
||||
c := dat[i]
|
||||
if underscore && c == '_' {
|
||||
out[w] = ' '
|
||||
w++
|
||||
continue
|
||||
}
|
||||
if c == '\r' {
|
||||
continue
|
||||
}
|
||||
if c == '=' {
|
||||
if i+1 < len(dat) && dat[i+1] == '\n' {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if i+2 < len(dat) && dat[i+1] == '\r' && dat[i+2] == '\n' {
|
||||
i += 2
|
||||
continue
|
||||
}
|
||||
if i+2 < len(dat) {
|
||||
v := unhex(dat[i+1])<<4 | unhex(dat[i+2])
|
||||
if v >= 0 {
|
||||
out[w] = byte(v)
|
||||
w++
|
||||
i += 2
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
out[w] = c
|
||||
w++
|
||||
}
|
||||
return out[:w]
|
||||
}
|
||||
|
||||
func nocrnl(dat []byte) []byte {
|
||||
w := 0
|
||||
for _, c := range dat {
|
||||
if c != '\r' && c != '\n' {
|
||||
dat[w] = c
|
||||
w++
|
||||
}
|
||||
}
|
||||
return dat[:w]
|
||||
}
|
||||
|
||||
func decode64(dat []byte) []byte {
|
||||
out := make([]byte, len(dat))
|
||||
copy(out, dat)
|
||||
out = nocrnl(out)
|
||||
n, err := base64.StdEncoding.Decode(out, out)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return out[:n]
|
||||
}
|
||||
|
||||
func decodeText(dat []byte, encoding, charset string, underscore bool) []byte {
|
||||
odat := dat
|
||||
switch strlwr(encoding) {
|
||||
case "quoted-printable":
|
||||
dat = decodeQP(dat, underscore)
|
||||
case "base64":
|
||||
dat = decode64(dat)
|
||||
}
|
||||
if dat == nil {
|
||||
return nil
|
||||
}
|
||||
if bytes.IndexByte(dat, '\r') >= 0 {
|
||||
if &odat[0] == &dat[0] {
|
||||
dat = append([]byte(nil), dat...)
|
||||
}
|
||||
dat = nocr(dat)
|
||||
}
|
||||
|
||||
charset = strlwr(charset)
|
||||
if charset == "utf-8" || charset == "us-ascii" {
|
||||
return dat
|
||||
}
|
||||
if charset == "iso-8859-1" {
|
||||
// Avoid allocation for iso-8859-1 that is really just ascii.
|
||||
for _, c := range dat {
|
||||
if c >= 0x80 {
|
||||
goto NeedConv
|
||||
}
|
||||
}
|
||||
return dat
|
||||
NeedConv:
|
||||
}
|
||||
|
||||
// TODO: big5, iso-2022-jp
|
||||
|
||||
tab := convtab[charset]
|
||||
if tab == nil {
|
||||
return dat
|
||||
}
|
||||
var b bytes.Buffer
|
||||
for _, c := range dat {
|
||||
if tab[c] < 0 {
|
||||
b.WriteRune(unicode.ReplacementChar)
|
||||
} else {
|
||||
b.WriteRune(tab[c])
|
||||
}
|
||||
}
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
var convtab = map[string]*[256]rune{
|
||||
"iso-8859-1": &tab_iso8859_1,
|
||||
"iso-8859-2": &tab_iso8859_2,
|
||||
"iso-8859-3": &tab_iso8859_3,
|
||||
"iso-8859-4": &tab_iso8859_4,
|
||||
"iso-8859-5": &tab_iso8859_5,
|
||||
"iso-8859-6": &tab_iso8859_6,
|
||||
"iso-8859-7": &tab_iso8859_7,
|
||||
"iso-8859-8": &tab_iso8859_8,
|
||||
"iso-8859-9": &tab_iso8859_9,
|
||||
"iso-8859-10": &tab_iso8859_10,
|
||||
"iso-8859-15": &tab_iso8859_15,
|
||||
"koi8-r": &tab_koi8,
|
||||
"windows-1250": &tab_cp1250,
|
||||
"windows-1251": &tab_cp1251,
|
||||
"windows-1252": &tab_cp1252,
|
||||
"windows-1253": &tab_cp1253,
|
||||
"windows-1254": &tab_cp1254,
|
||||
"windows-1255": &tab_cp1255,
|
||||
"windows-1256": &tab_cp1256,
|
||||
"windows-1257": &tab_cp1257,
|
||||
"windows-1258": &tab_cp1258,
|
||||
}
|
||||
|
||||
func unrfc2047(s string) string {
|
||||
if !strings.Contains(s, "=?") {
|
||||
return s
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
for {
|
||||
// =?charset?e?text?=
|
||||
i := strings.Index(s, "=?")
|
||||
if i < 0 {
|
||||
break
|
||||
}
|
||||
conv, rest, ok := decode2047chunk(s[i:])
|
||||
if !ok {
|
||||
buf.WriteString(s[:i+2])
|
||||
s = s[i+2:]
|
||||
continue
|
||||
}
|
||||
buf.WriteString(s[:i])
|
||||
buf.Write(conv)
|
||||
s = rest
|
||||
}
|
||||
buf.WriteString(s)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func lwr(c rune) rune {
|
||||
if 'A' <= c && c <= 'Z' {
|
||||
return c + 'a' - 'A'
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func strlwr(s string) string {
|
||||
return strings.Map(lwr, s)
|
||||
}
|
||||
|
||||
func unhex(c byte) int {
|
||||
switch {
|
||||
case '0' <= c && c <= '9':
|
||||
return int(c) - '0'
|
||||
case 'a' <= c && c <= 'f':
|
||||
return int(c) - 'a' + 10
|
||||
case 'A' <= c && c <= 'F':
|
||||
return int(c) - 'A' + 10
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// TODO: Will need modified UTF-7 eventually.
|
||||
26
vendor/github.com/mattermost/rsc/imap/decode_test.go
сгенерированный
поставляемый
26
vendor/github.com/mattermost/rsc/imap/decode_test.go
сгенерированный
поставляемый
@@ -1,26 +0,0 @@
|
||||
package imap
|
||||
|
||||
import "testing"
|
||||
|
||||
var unrfc2047Tests = []struct {
|
||||
in, out string
|
||||
}{
|
||||
{"hello world", "hello world"},
|
||||
{"hello =?iso-8859-1?q?this is some text?=", "hello this is some text"},
|
||||
{"=?US-ASCII?Q?Keith_Moore?=", "Keith Moore"},
|
||||
{"=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?=", "Keld Jørn Simonsen"},
|
||||
{"=?ISO-8859-1?Q?Andr=E9?= Pirard", "André Pirard"},
|
||||
{"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=", "If you can read this yo"},
|
||||
{"=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=", "u understand the example."},
|
||||
{"=?ISO-8859-1?Q?Olle_J=E4rnefors?=", "Olle Järnefors"},
|
||||
// {"=?iso-2022-jp?B?GyRCTTVKISRKP006SiRyS34kPyQ3JEZKcz03JCIkahsoQg==?=", ""},
|
||||
{"=?UTF-8?B?Ik5pbHMgTy4gU2Vsw6VzZGFsIg==?=", `"Nils O. Selåsdal"`},
|
||||
}
|
||||
|
||||
func TestUnrfc2047(t *testing.T) {
|
||||
for _, tt := range unrfc2047Tests {
|
||||
if out := unrfc2047(tt.in); out != tt.out {
|
||||
t.Errorf("unrfc2047(%#q) = %#q, want %#q", tt.in, out, tt.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
1110
vendor/github.com/mattermost/rsc/imap/imap.go
сгенерированный
поставляемый
1110
vendor/github.com/mattermost/rsc/imap/imap.go
сгенерированный
поставляемый
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
433
vendor/github.com/mattermost/rsc/imap/imap_test.go
сгенерированный
поставляемый
433
vendor/github.com/mattermost/rsc/imap/imap_test.go
сгенерированный
поставляемый
@@ -1,433 +0,0 @@
|
||||
package imap
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/rsc/google"
|
||||
)
|
||||
|
||||
// NOTE: web address is https://mail.google.com/mail/b/rsc@swtch.com/?shva=1#inbox/132e5fd3a6a3c17b
|
||||
// where the last is the hex for the thread id.
|
||||
// have to have the #inbox part right too. #label/Hello+World/...
|
||||
// or #all as a fallback
|
||||
|
||||
// TODO: ID command support (RFC 2971)
|
||||
|
||||
const mock = true
|
||||
|
||||
var user = "rsc@swtch.com"
|
||||
var pw, _ = ioutil.ReadFile("/Users/rsc/.swtchpass")
|
||||
|
||||
func TestImap(t *testing.T) {
|
||||
var user, pw string
|
||||
if mock {
|
||||
testDial = fakeDial
|
||||
user = "gre@host.com"
|
||||
pw = "password"
|
||||
} else {
|
||||
acct := google.Acct("rsc@swtch.com")
|
||||
user = acct.Email
|
||||
pw = acct.Password
|
||||
}
|
||||
c, err := NewClient(TLS, "imap.gmail.com", user, pw, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
inbox := c.Inbox()
|
||||
msgs := inbox.Msgs()
|
||||
|
||||
for _, m := range msgs {
|
||||
if m.UID == 611764547<<32|57046 {
|
||||
// c.io.lock()
|
||||
// c.cmd(c.boxByName[`[Gmail]/All Mail`], `UID SEARCH X-GM-RAW "label:russcox@gmail.com in:inbox in:unread -in:muted"`)
|
||||
// c.cmd(c.inbox, `UID SEARCH X-GM-RAW "label:russcox@gmail.com in:inbox in:unread -in:muted"`)
|
||||
// c.cmd(c.boxByName[`To Read`], `UID SEARCH X-GM-RAW "label:russcox@gmail.com in:inbox in:unread -in:muted"`)
|
||||
// c.cmd(c.boxByName[`[Gmail]/All Mail`], `UID SEARCH X-GM-RAW "label:russcox@gmail.com in:inbox in:unread -in:muted"`)
|
||||
// c.fetch(m.Root.Child[0], "")
|
||||
// c.io.unlock()
|
||||
fmt.Println("--")
|
||||
fmt.Println("From:", m.Hdr.From)
|
||||
fmt.Println("To:", m.Hdr.To)
|
||||
fmt.Println("Subject:", m.Hdr.Subject)
|
||||
fmt.Println("M-Date:", time.Unix(m.Date, 0))
|
||||
fmt.Println("Date:", m.Hdr.Date)
|
||||
fmt.Println()
|
||||
fmt.Println(string(m.Root.Child[0].Text()))
|
||||
fmt.Println("--")
|
||||
}
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
|
||||
func fakeDial(server string, mode Mode) (io.ReadWriteCloser, error) {
|
||||
r1, w1 := io.Pipe()
|
||||
r2, w2 := io.Pipe()
|
||||
go fakeServer(&pipe2{r1, w2})
|
||||
return &pipe2{r2, w1}, nil
|
||||
}
|
||||
|
||||
func fakeServer(rw io.ReadWriteCloser) {
|
||||
b := bufio.NewReader(rw)
|
||||
rw.Write([]byte(fakeReply[""]))
|
||||
for {
|
||||
line, err := b.ReadString('\n')
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
reply := fakeReply[strings.TrimSpace(line)]
|
||||
if reply == "" {
|
||||
rw.Write([]byte("* BYE\r\n"))
|
||||
break
|
||||
}
|
||||
rw.Write([]byte(reply))
|
||||
}
|
||||
rw.Close()
|
||||
}
|
||||
|
||||
var fakeReply = map[string]string{
|
||||
``: "* OK Gimap ready for requests from 71.232.17.63 k7if4537693qcx.66\r\n",
|
||||
`# LOGIN gre@host.com password`: "* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE\r\n" +
|
||||
"# OK gre@host.com Grace Emlin authenticated (Success)\r\n",
|
||||
`# XLIST "" INBOX`: `* XLIST (\HasNoChildren \Inbox) "/" "Inbox"` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# XLIST "" *`: `* XLIST (\HasNoChildren \Inbox) "/" "Inbox"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren) "/" "Someday"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren) "/" "To Read"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren) "/" "Waiting"` + "\r\n" +
|
||||
`* XLIST (\Noselect \HasChildren) "/" "[Gmail]"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren \AllMail) "/" "[Gmail]/All Mail"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren \Drafts) "/" "[Gmail]/Drafts"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren \Important) "/" "[Gmail]/Important"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren \Sent) "/" "[Gmail]/Sent Mail"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren \Spam) "/" "[Gmail]/Spam"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren \Starred) "/" "[Gmail]/Starred"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren \Trash) "/" "[Gmail]/Trash"` + "\r\n" +
|
||||
`* XLIST (\HasNoChildren) "/" "russcox@gmail.com"` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# LIST "" INBOX`: `* LIST (\HasNoChildren) "/" "INBOX"` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# LIST "" *`: `* LIST (\HasNoChildren) "/" "INBOX"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "Someday"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "To Read"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "Waiting"` + "\r\n" +
|
||||
`* LIST (\Noselect \HasChildren) "/" "[Gmail]"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "[Gmail]/All Mail"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "[Gmail]/Drafts"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "[Gmail]/Important"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "[Gmail]/Sent Mail"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "[Gmail]/Spam"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "[Gmail]/Starred"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "[Gmail]/Trash"` + "\r\n" +
|
||||
`* LIST (\HasNoChildren) "/" "russcox@gmail.com"` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# SELECT inbox`: `* FLAGS (\Answered \Flagged \Draft \Deleted \Seen)` + "\r\n" +
|
||||
`* OK [PERMANENTFLAGS (\Answered \Flagged \Draft \Deleted \Seen \*)] Flags permitted.` + "\r\n" +
|
||||
`* OK [UIDVALIDITY 611764547] UIDs valid.` + "\r\n" +
|
||||
`* 9 EXISTS` + "\r\n" +
|
||||
`* 0 RECENT` + "\r\n" +
|
||||
`* OK [UIDNEXT 57027] Predicted next UID.` + "\r\n" +
|
||||
"# OK [READ-WRITE] inbox selected. (Success)\r\n",
|
||||
`# UID FETCH 1:* (FLAGS)`: `* 1 FETCH (UID 46074 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 2 FETCH (UID 49094 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 3 FETCH (UID 49317 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 4 FETCH (UID 49424 FLAGS (\Flagged \Seen))` + "\r\n" +
|
||||
`* 5 FETCH (UID 49595 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 6 FETCH (UID 49810 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 7 FETCH (UID 50579 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 8 FETCH (UID 50597 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 9 FETCH (UID 50598 FLAGS (\Seen))` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# FETCH 1:* (UID FLAGS)`: `* 1 FETCH (UID 46074 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 2 FETCH (UID 49094 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 3 FETCH (UID 49317 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 4 FETCH (UID 49424 FLAGS (\Flagged \Seen))` + "\r\n" +
|
||||
`* 5 FETCH (UID 49595 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 6 FETCH (UID 49810 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 7 FETCH (UID 50579 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 8 FETCH (UID 50597 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 9 FETCH (UID 50598 FLAGS (\Seen))` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# NOOP`: "# OK Success\r\n",
|
||||
`# UID FETCH 1:* (FLAGS X-GM-MSGID X-GM-THRID)`: `* 1 FETCH (X-GM-THRID 1371690017835349492 X-GM-MSGID 1371690017835349492 UID 46074 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 2 FETCH (X-GM-THRID 1370053443095117076 X-GM-MSGID 1374032778063810116 UID 49094 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 3 FETCH (X-GM-THRID 1370053443095117076 X-GM-MSGID 1374171123044094435 UID 49317 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 4 FETCH (X-GM-THRID 1374260005724669308 X-GM-MSGID 1374260005724669308 UID 49424 FLAGS (\Flagged \Seen))` + "\r\n" +
|
||||
`* 5 FETCH (X-GM-THRID 1374399840419707240 X-GM-MSGID 1374399840419707240 UID 49595 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 6 FETCH (X-GM-THRID 1374564698687599195 X-GM-MSGID 1374564698687599195 UID 49810 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 7 FETCH (X-GM-THRID 1353701773219222407 X-GM-MSGID 1375207927094695931 UID 50579 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 8 FETCH (X-GM-THRID 1375017086705541883 X-GM-MSGID 1375220323861690146 UID 50597 FLAGS (\Seen))` + "\r\n" +
|
||||
`* 9 FETCH (X-GM-THRID 1353701773219222407 X-GM-MSGID 1375220551142026521 UID 50598 FLAGS (\Seen))` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 1:* (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE X-GM-MSGID X-GM-THRID)`: `* 1 FETCH (X-GM-THRID 1371690017835349492 X-GM-MSGID 1371690017835349492 UID 46074 RFC822.SIZE 5700 INTERNALDATE "15-Jun-2011 13:45:39 +0000" FLAGS (\Seen) ENVELOPE ("Wed, 15 Jun 2011 13:45:35 +0000" "[re2-dev] Issue 40 in re2: Please make RE2::Rewrite public" ((NIL NIL "re2" "googlecode.com")) ((NIL NIL "re2-dev" "googlegroups.com")) ((NIL NIL "codesite-noreply" "google.com")) ((NIL NIL "re2-dev" "googlegroups.com")) NIL NIL NIL "<0-13244084390050003171-8842966241254494762-re2=googlecode.com@googlecode.com>"))` + "\r\n" +
|
||||
`* 2 FETCH (X-GM-THRID 1370053443095117076 X-GM-MSGID 1374032778063810116 UID 49094 RFC822.SIZE 3558 INTERNALDATE "11-Jul-2011 10:22:49 +0000" FLAGS (\Seen) ENVELOPE ("Mon, 11 Jul 2011 12:22:46 +0200" "Re: [re2-dev] Re: Issue 39 in re2: Eiffel wrapper for RE2" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Russ Cox" NIL "rsc" "swtch.com")) NIL NIL "<CADSkJJWthFb61R1tqJxZP1SxTPuwY_BBW5ToLuzX2UpHSvsy9w@mail.gmail.com>" "<4E1ACEF6.4060609@gmail.com>"))` + "\r\n" +
|
||||
`* 3 FETCH (X-GM-THRID 1370053443095117076 X-GM-MSGID 1374171123044094435 UID 49317 RFC822.SIZE 3323 INTERNALDATE "12-Jul-2011 23:01:46 +0000" FLAGS (\Seen) ENVELOPE ("Wed, 13 Jul 2011 01:01:41 +0200" "Re: [re2-dev] Re: Issue 39 in re2: Eiffel wrapper for RE2" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Russ Cox" NIL "rsc" "swtch.com")) NIL NIL "<CADSkJJV+E-0Xtm=dpiSHLbwkZjZ=zDDoE1t1w0CiGYa+pVz66g@mail.gmail.com>" "<4E1CD255.6060807@gmail.com>"))` + "\r\n" +
|
||||
`* 4 FETCH (X-GM-THRID 1374260005724669308 X-GM-MSGID 1374260005724669308 UID 49424 RFC822.SIZE 2681 INTERNALDATE "13-Jul-2011 22:34:31 +0000" FLAGS (\Flagged \Seen) ENVELOPE ("Wed, 13 Jul 2011 16:33:43 -0600" "Minor correction for venti(8) user manual for running plan9port on Linux" (("Xing" NIL "xinglin" "cs.utah.edu")) (("Xing" NIL "xinglin" "cs.utah.edu")) (("Xing" NIL "xinglin" "cs.utah.edu")) ((NIL NIL "rsc" "swtch.com")) (("Xing Lin" NIL "xinglin" "cs.utah.edu") ("Raghuveer Pullakandam" NIL "rgv" "cs.utah.edu") ("Robert Ricci" NIL "ricci" "cs.utah.edu") ("Eric Eide" NIL "eeide" "cs.utah.edu")) NIL NIL "<1310596423.3866.11.camel@xing-utah-cs>"))` + "\r\n" +
|
||||
`* 5 FETCH (X-GM-THRID 1374399840419707240 X-GM-MSGID 1374399840419707240 UID 49595 RFC822.SIZE 6496 INTERNALDATE "15-Jul-2011 11:37:07 +0000" FLAGS (\Seen) ENVELOPE ("Fri, 15 Jul 2011 13:36:54 +0200" "[re2-dev] MSVC not exporting VariadicFunction2<.. FullMatchN>::operator()(..) but VariadicFunction2<.. PartialMatchN>::operator()(..)" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) ((NIL NIL "re2-dev" "googlegroups.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) ((NIL NIL "re2-dev" "googlegroups.com")) NIL NIL NIL "<4E202656.7010408@gmail.com>"))` + "\r\n" +
|
||||
`* 6 FETCH (X-GM-THRID 1374564698687599195 X-GM-MSGID 1374564698687599195 UID 49810 RFC822.SIZE 5485 INTERNALDATE "17-Jul-2011 07:17:29 +0000" FLAGS (\Seen) ENVELOPE ("Sun, 17 Jul 2011 00:17:28 -0700" "Acme IRC client patch" (("Ethan Burns" NIL "burns.ethan" "gmail.com")) (("Ethan Burns" NIL "burns.ethan" "gmail.com")) (("Ethan Burns" NIL "burns.ethan" "gmail.com")) ((NIL NIL "rsc" "swtch.com")) NIL NIL NIL "<CAGE=Ei0bmAjsYYDxCgtDObuxX_tCU18RcWTe6siwemXAuKqDfg@mail.gmail.com>"))` + "\r\n" +
|
||||
`* 7 FETCH (X-GM-THRID 1353701773219222407 X-GM-MSGID 1375207927094695931 UID 50579 RFC822.SIZE 4049 INTERNALDATE "24-Jul-2011 09:41:19 +0000" FLAGS (\Seen) ENVELOPE ("Sun, 24 Jul 2011 02:41:14 -0700 (PDT)" "Re: [re2-dev] Re: MSVC build" ((NIL NIL "talgil" "gmail.com")) ((NIL NIL "re2-dev" "googlegroups.com")) ((NIL NIL "re2-dev" "googlegroups.com")) ((NIL NIL "re2-dev" "googlegroups.com")) (("ioannis" NIL "ioannis.e" "gmail.com")) NIL "<AANLkTin8_-yDr8tcb9SosfQ_iAM6RmfzpLQB0gX0vv6w@mail.gmail.com>" "<24718992.6777.1311500475040.JavaMail.geo-discussion-forums@yqyy3>"))` + "\r\n" +
|
||||
`* 8 FETCH (X-GM-THRID 1375017086705541883 X-GM-MSGID 1375220323861690146 UID 50597 RFC822.SIZE 3070 INTERNALDATE "24-Jul-2011 12:58:22 +0000" FLAGS (\Seen) ENVELOPE ("Sun, 24 Jul 2011 14:58:15 +0200" "Re: [re2-dev] Rearranging platform dependant features" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Russ Cox" NIL "rsc" "swtch.com")) NIL NIL "<CADSkJJV+eCPkkhsepo5k0w+dqVo0fQOana2bWp4BexGOrCSSUQ@mail.gmail.com>" "<4E2C16E7.3060500@gmail.com>"))` + "\r\n" +
|
||||
`* 9 FETCH (X-GM-THRID 1353701773219222407 X-GM-MSGID 1375220551142026521 UID 50598 RFC822.SIZE 5744 INTERNALDATE "24-Jul-2011 13:01:59 +0000" FLAGS (\Seen) ENVELOPE ("Sun, 24 Jul 2011 15:01:49 +0200" "Re: [re2-dev] Re: MSVC build" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) ((NIL NIL "re2-dev" "googlegroups.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) ((NIL NIL "re2-dev" "googlegroups.com")) NIL NIL "<24718992.6777.1311500475040.JavaMail.geo-discussion-forums@yqyy3>" "<4E2C17BD.6000702@gmail.com>"))` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57047:* (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY X-GM-MSGID X-GM-THRID X-GM-LABELS)`: `* 9 FETCH (X-GM-THRID 1382192619814696847 X-GM-MSGID 1382192619814696847 X-GM-LABELS ("\\Important" russcox@gmail.com) UID 57046 RFC822.SIZE 4170 INTERNALDATE "09-Oct-2011 12:00:02 +0000" FLAGS () ENVELOPE ("Sun, 09 Oct 2011 12:00:02 +0000" "You have no events scheduled today." (("Google Calendar" NIL "calendar-notification" "google.com")) (("Google Calendar" NIL "calendar-notification" "google.com")) (("Russ Cox" NIL "russcox" "gmail.com")) (("Russ Cox" NIL "russcox" "gmail.com")) NIL NIL NIL "<bcaec501c5be15fc7204aedc6af6@google.com>") BODY (("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1" "DELSP" "yes" "FORMAT" "flowed") NIL NIL "7BIT" 465 11)("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 914 12) "ALTERNATIVE"))` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 1:* (FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY X-GM-MSGID X-GM-THRID X-GM-LABELS)`: `* 1 FETCH (X-GM-THRID 1371690017835349492 X-GM-MSGID 1371690017835349492 X-GM-LABELS () UID 46074 RFC822.SIZE 5700 INTERNALDATE "15-Jun-2011 13:45:39 +0000" FLAGS (\Seen) ENVELOPE ("Wed, 15 Jun 2011 13:45:35 +0000" "[re2-dev] Issue 40 in re2: Please make RE2::Rewrite public" ((NIL NIL "re2" "googlecode.com")) ((NIL NIL "re2-dev" "googlegroups.com")) ((NIL NIL "codesite-noreply" "google.com")) ((NIL NIL "re2-dev" "googlegroups.com")) NIL NIL NIL "<0-13244084390050003171-8842966241254494762-re2=googlecode.com@googlecode.com>") BODY ("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1" "DELSP" "yes" "FORMAT" "flowed") NIL NIL "7BIT" 389 11))` + "\r\n" +
|
||||
`* 2 FETCH (X-GM-THRID 1370053443095117076 X-GM-MSGID 1374032778063810116 X-GM-LABELS ("\\Important") UID 49094 RFC822.SIZE 3558 INTERNALDATE "11-Jul-2011 10:22:49 +0000" FLAGS (\Seen) ENVELOPE ("Mon, 11 Jul 2011 12:22:46 +0200" "Re: [re2-dev] Re: Issue 39 in re2: Eiffel wrapper for RE2" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Russ Cox" NIL "rsc" "swtch.com")) NIL NIL "<CADSkJJWthFb61R1tqJxZP1SxTPuwY_BBW5ToLuzX2UpHSvsy9w@mail.gmail.com>" "<4E1ACEF6.4060609@gmail.com>") BODY ("TEXT" "PLAIN" ("CHARSET" "UTF-8" "FORMAT" "flowed") NIL NIL "7BIT" 766 24))` + "\r\n" +
|
||||
`* 3 FETCH (X-GM-THRID 1370053443095117076 X-GM-MSGID 1374171123044094435 X-GM-LABELS ("\\Important") UID 49317 RFC822.SIZE 3323 INTERNALDATE "12-Jul-2011 23:01:46 +0000" FLAGS (\Seen) ENVELOPE ("Wed, 13 Jul 2011 01:01:41 +0200" "Re: [re2-dev] Re: Issue 39 in re2: Eiffel wrapper for RE2" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Russ Cox" NIL "rsc" "swtch.com")) NIL NIL "<CADSkJJV+E-0Xtm=dpiSHLbwkZjZ=zDDoE1t1w0CiGYa+pVz66g@mail.gmail.com>" "<4E1CD255.6060807@gmail.com>") BODY ("TEXT" "PLAIN" ("CHARSET" "UTF-8" "FORMAT" "flowed") NIL NIL "7BIT" 435 12))` + "\r\n" +
|
||||
`* 4 FETCH (X-GM-THRID 1374260005724669308 X-GM-MSGID 1374260005724669308 X-GM-LABELS ("\\Important" "\\Starred") UID 49424 RFC822.SIZE 2681 INTERNALDATE "13-Jul-2011 22:34:31 +0000" FLAGS (\Flagged \Seen) ENVELOPE ("Wed, 13 Jul 2011 16:33:43 -0600" "Minor correction for venti(8) user manual for running plan9port on Linux" (("Xing" NIL "xinglin" "cs.utah.edu")) (("Xing" NIL "xinglin" "cs.utah.edu")) (("Xing" NIL "xinglin" "cs.utah.edu")) ((NIL NIL "rsc" "swtch.com")) (("Xing Lin" NIL "xinglin" "cs.utah.edu") ("Raghuveer Pullakandam" NIL "rgv" "cs.utah.edu") ("Robert Ricci" NIL "ricci" "cs.utah.edu") ("Eric Eide" NIL "eeide" "cs.utah.edu")) NIL NIL "<1310596423.3866.11.camel@xing-utah-cs>") BODY ("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "8BIT" 789 25))` + "\r\n" +
|
||||
`* 5 FETCH (X-GM-THRID 1374399840419707240 X-GM-MSGID 1374399840419707240 X-GM-LABELS ("\\Important") UID 49595 RFC822.SIZE 6496 INTERNALDATE "15-Jul-2011 11:37:07 +0000" FLAGS (\Seen) ENVELOPE ("Fri, 15 Jul 2011 13:36:54 +0200" "[re2-dev] MSVC not exporting VariadicFunction2<.. FullMatchN>::operator()(..) but VariadicFunction2<.. PartialMatchN>::operator()(..)" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) ((NIL NIL "re2-dev" "googlegroups.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) ((NIL NIL "re2-dev" "googlegroups.com")) NIL NIL NIL "<4E202656.7010408@gmail.com>") BODY ("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1" "FORMAT" "flowed") NIL NIL "7BIT" 1660 34))` + "\r\n" +
|
||||
`* 6 FETCH (X-GM-THRID 1374564698687599195 X-GM-MSGID 1374564698687599195 X-GM-LABELS ("\\Important") UID 49810 RFC822.SIZE 5485 INTERNALDATE "17-Jul-2011 07:17:29 +0000" FLAGS (\Seen) ENVELOPE ("Sun, 17 Jul 2011 00:17:28 -0700" "Acme IRC client patch" (("Ethan Burns" NIL "burns.ethan" "gmail.com")) (("Ethan Burns" NIL "burns.ethan" "gmail.com")) (("Ethan Burns" NIL "burns.ethan" "gmail.com")) ((NIL NIL "rsc" "swtch.com")) NIL NIL NIL "<CAGE=Ei0bmAjsYYDxCgtDObuxX_tCU18RcWTe6siwemXAuKqDfg@mail.gmail.com>") BODY (("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1") NIL NIL "7BIT" 443 13)("TEXT" "X-PATCH" ("CHARSET" "US-ASCII" "NAME" "emote.patch") NIL NIL "BASE64" 2774 35) "MIXED"))` + "\r\n" +
|
||||
`* 7 FETCH (X-GM-THRID 1353701773219222407 X-GM-MSGID 1375207927094695931 X-GM-LABELS ("\\Important") UID 50579 RFC822.SIZE 4049 INTERNALDATE "24-Jul-2011 09:41:19 +0000" FLAGS (\Seen) ENVELOPE ("Sun, 24 Jul 2011 02:41:14 -0700 (PDT)" "Re: [re2-dev] Re: MSVC build" ((NIL NIL "talgil" "gmail.com")) ((NIL NIL "re2-dev" "googlegroups.com")) ((NIL NIL "re2-dev" "googlegroups.com")) ((NIL NIL "re2-dev" "googlegroups.com")) (("ioannis" NIL "ioannis.e" "gmail.com")) NIL "<AANLkTin8_-yDr8tcb9SosfQ_iAM6RmfzpLQB0gX0vv6w@mail.gmail.com>" "<24718992.6777.1311500475040.JavaMail.geo-discussion-forums@yqyy3>") BODY (("TEXT" "PLAIN" ("CHARSET" "UTF-8") NIL NIL "7BIT" 133 8)("TEXT" "HTML" ("CHARSET" "UTF-8") NIL NIL "7BIT" 211 0) "ALTERNATIVE"))` + "\r\n" +
|
||||
`* 8 FETCH (X-GM-THRID 1375017086705541883 X-GM-MSGID 1375220323861690146 X-GM-LABELS ("\\Important") UID 50597 RFC822.SIZE 3070 INTERNALDATE "24-Jul-2011 12:58:22 +0000" FLAGS (\Seen) ENVELOPE ("Sun, 24 Jul 2011 14:58:15 +0200" "Re: [re2-dev] Rearranging platform dependant features" (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Pontus Carlsson" NIL "pontusjoncarlsson" "gmail.com")) (("Russ Cox" NIL "rsc" "swtch.com")) NIL NIL "<CADSkJJV+eCPkkhsepo5k0w+dqVo0fQOana2bWp4BexGOrCSSUQ@mail.gmail.com>" "<4E2C16E7.3060500@gmail.com>") BODY ("TEXT" "PLAIN" ("CHARSET" "UTF-8" "FORMAT" "flowed") NIL NIL "7BIT" 450 10))` + "\r\n" +
|
||||
`* 9 FETCH (X-GM-THRID 1382192619814696847 X-GM-MSGID 1382192619814696847 X-GM-LABELS ("\\Important" russcox@gmail.com) UID 57046 RFC822.SIZE 4170 INTERNALDATE "09-Oct-2011 12:00:02 +0000" FLAGS () ENVELOPE ("Sun, 09 Oct 2011 12:00:02 +0000" "You have no events scheduled today." (("Google Calendar" NIL "calendar-notification" "google.com")) (("Google Calendar" NIL "calendar-notification" "google.com")) (("Russ Cox" NIL "russcox" "gmail.com")) (("Russ Cox" NIL "russcox" "gmail.com")) NIL NIL NIL "<bcaec501c5be15fc7204aedc6af6@google.com>") BODY (("TEXT" "PLAIN" ("CHARSET" "ISO-8859-1" "DELSP" "yes" "FORMAT" "flowed") NIL NIL "7BIT" 465 11)("TEXT" "HTML" ("CHARSET" "ISO-8859-1") NIL NIL "QUOTED-PRINTABLE" 914 12) "ALTERNATIVE"))` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[1]`: `* 9 FETCH (UID 57046 BODY[1] {465}` + "\r\n" +
|
||||
`russcox@gmail.com, you have no events scheduled today Sun Oct 9, 2011.` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`View your calendar at https://www.google.com/calendar/` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`You are receiving this email at the account russcox@gmail.com because you ` + "\r\n" +
|
||||
`are subscribed to receive daily agendas for the following calendars: Russ ` + "\r\n" +
|
||||
`Cox.` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`To change which calendars you receive daily agendas for, please log in to ` + "\r\n" +
|
||||
`https://www.google.com/calendar/ and change your notification settings for ` + "\r\n" +
|
||||
`each calendar.` + "\r\n" +
|
||||
`)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[1.TEXT]`: `* 9 FETCH (UID 57046 BODY[1.TEXT] NIL)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[1.HEADER]`: `* 9 FETCH (UID 57046 BODY[1.HEADER] NIL)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[1.MIME]`: `* 146 FETCH (UID 57046 BODY[1.MIME] {74}` + "\r\n" +
|
||||
`Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[2]`: `* 146 FETCH (UID 57046 BODY[2] {914}` + "\r\n" +
|
||||
`<div style=3D"padding:10px 7px;font-size:14px;line-height:1.4;font-family:A=` + "\r\n" +
|
||||
`rial,Sans-serif;text-align:left;bgcolor=3D#ffffff"><a href=3D"https://www.g=` + "\r\n" +
|
||||
`oogle.com/calendar/"><img style=3D"border-width:0" src=3D"https://www.googl=` + "\r\n" +
|
||||
`e.com/calendar/images/calendar_logo_sm_en.gif" alt=3D"Google Calendar"></a>` + "\r\n" +
|
||||
`<p style=3D"margin:0;color:#0">russcox@gmail.com, you have no events s=` + "\r\n" +
|
||||
`cheduled today <b>Sun Oct 9, 2011</b></p>` + "\r\n" +
|
||||
`<p style=3D"font-family:Arial,Sans-serif;color:#666;font-size:11px">You are=` + "\r\n" +
|
||||
` receiving this email at the account russcox@gmail.com because you are subs=` + "\r\n" +
|
||||
`cribed to receive daily agendas for the following calendars: Russ Cox.</p>` + "\r\n" +
|
||||
`<p style=3D"font-family:Arial,Sans-serif;color:#666;font-size:11px">To chan=` + "\r\n" +
|
||||
`ge which calendars you receive daily agendas for, please log in to https://=` + "\r\n" +
|
||||
`www.google.com/calendar/ and change your notification settings for each cal=` + "\r\n" +
|
||||
`endar.</p></div>)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[2.TEXT]`: `* 9 FETCH (UID 57046 BODY[2.TEXT] NIL)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[2.HEADER]`: `* 9 FETCH (UID 57046 BODY[2.HEADER] NIL)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[2.MIME]`: `* 146 FETCH (UID 57046 BODY[2.MIME] {92}` + "\r\n" +
|
||||
`Content-Type: text/html; charset=ISO-8859-1` + "\r\n" +
|
||||
`Content-Transfer-Encoding: quoted-printable` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[]`: `* 146 FETCH (UID 57046 BODY[] {4170}` + "\r\n" +
|
||||
`Delivered-To: rsc@swtch.com` + "\r\n" +
|
||||
`Received: by 10.216.54.148 with SMTP id i20cs32329wec;` + "\r\n" +
|
||||
` Sun, 9 Oct 2011 05:00:30 -0700 (PDT)` + "\r\n" +
|
||||
`Received: by 10.227.11.2 with SMTP id r2mr4751812wbr.43.1318161630585;` + "\r\n" +
|
||||
` Sun, 09 Oct 2011 05:00:30 -0700 (PDT)` + "\r\n" +
|
||||
`DomainKey-Status: good` + "\r\n" +
|
||||
`Received-SPF: softfail (google.com: best guess record for domain of transitioning 3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com does not designate <unknown> as permitted sender)` + "\r\n" +
|
||||
`Received: by 10.241.227.90 with POP3 id 26mf2646912wyj.48;` + "\r\n" +
|
||||
` Sun, 09 Oct 2011 05:00:29 -0700 (PDT)` + "\r\n" +
|
||||
`X-Gmail-Fetch-Info: russcox@gmail.com 1 smtp.gmail.com 995 russcox` + "\r\n" +
|
||||
`Delivered-To: russcox@gmail.com` + "\r\n" +
|
||||
`Received: by 10.142.76.10 with SMTP id y10cs75487wfa;` + "\r\n" +
|
||||
` Sun, 9 Oct 2011 05:00:08 -0700 (PDT)` + "\r\n" +
|
||||
`Return-Path: <3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com>` + "\r\n" +
|
||||
`Received-SPF: pass (google.com: domain of 3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com designates 10.52.73.100 as permitted sender) client-ip=10.52.73.100;` + "\r\n" +
|
||||
`Authentication-Results: mr.google.com; spf=pass (google.com: domain of 3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com designates 10.52.73.100 as permitted sender) smtp.mail=3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com; dkim=pass header.i=3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com` + "\r\n" +
|
||||
`Received: from mr.google.com ([10.52.73.100])` + "\r\n" +
|
||||
` by 10.52.73.100 with SMTP id k4mr8053242vdv.5.1318161606360 (num_hops = 1);` + "\r\n" +
|
||||
` Sun, 09 Oct 2011 05:00:06 -0700 (PDT)` + "\r\n" +
|
||||
`DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;` + "\r\n" +
|
||||
` d=google.com; s=beta;` + "\r\n" +
|
||||
` h=mime-version:reply-to:auto-submitted:message-id:date:subject:from` + "\r\n" +
|
||||
` :to:content-type;` + "\r\n" +
|
||||
` bh=SGjz0F4q+eFVkoC4yzLKQKvlxTKiUsYbO/KPI+3KOE8=;` + "\r\n" +
|
||||
` b=LRBkWBW7ZZ4UJYa7b92zfHa0ZM1K1d0wP/jbgmDw2OZTWtgDICZb30dzhFUfNVdxeN` + "\r\n" +
|
||||
` kdMFbRhTLP5NpSXWhbDw==` + "\r\n" +
|
||||
`MIME-Version: 1.0` + "\r\n" +
|
||||
`Received: by 10.52.73.100 with SMTP id k4mr5244039vdv.5.1318161602706; Sun, 09` + "\r\n" +
|
||||
` Oct 2011 05:00:02 -0700 (PDT)` + "\r\n" +
|
||||
`Reply-To: Russ Cox <russcox@gmail.com>` + "\r\n" +
|
||||
`Auto-Submitted: auto-generated` + "\r\n" +
|
||||
`Message-ID: <bcaec501c5be15fc7204aedc6af6@google.com>` + "\r\n" +
|
||||
`Date: Sun, 09 Oct 2011 12:00:02 +0000` + "\r\n" +
|
||||
`Subject: You have no events scheduled today.` + "\r\n" +
|
||||
`From: Google Calendar <calendar-notification@google.com>` + "\r\n" +
|
||||
`To: Russ Cox <russcox@gmail.com>` + "\r\n" +
|
||||
`Content-Type: multipart/alternative; boundary=bcaec501c5be15fc6504aedc6af3` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`--bcaec501c5be15fc6504aedc6af3` + "\r\n" +
|
||||
`Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`russcox@gmail.com, you have no events scheduled today Sun Oct 9, 2011.` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`View your calendar at https://www.google.com/calendar/` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`You are receiving this email at the account russcox@gmail.com because you ` + "\r\n" +
|
||||
`are subscribed to receive daily agendas for the following calendars: Russ ` + "\r\n" +
|
||||
`Cox.` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`To change which calendars you receive daily agendas for, please log in to ` + "\r\n" +
|
||||
`https://www.google.com/calendar/ and change your notification settings for ` + "\r\n" +
|
||||
`each calendar.` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`--bcaec501c5be15fc6504aedc6af3` + "\r\n" +
|
||||
`Content-Type: text/html; charset=ISO-8859-1` + "\r\n" +
|
||||
`Content-Transfer-Encoding: quoted-printable` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`<div style=3D"padding:10px 7px;font-size:14px;line-height:1.4;font-family:A=` + "\r\n" +
|
||||
`rial,Sans-serif;text-align:left;bgcolor=3D#ffffff"><a href=3D"https://www.g=` + "\r\n" +
|
||||
`oogle.com/calendar/"><img style=3D"border-width:0" src=3D"https://www.googl=` + "\r\n" +
|
||||
`e.com/calendar/images/calendar_logo_sm_en.gif" alt=3D"Google Calendar"></a>` + "\r\n" +
|
||||
`<p style=3D"margin:0;color:#0">russcox@gmail.com, you have no events s=` + "\r\n" +
|
||||
`cheduled today <b>Sun Oct 9, 2011</b></p>` + "\r\n" +
|
||||
`<p style=3D"font-family:Arial,Sans-serif;color:#666;font-size:11px">You are=` + "\r\n" +
|
||||
` receiving this email at the account russcox@gmail.com because you are subs=` + "\r\n" +
|
||||
`cribed to receive daily agendas for the following calendars: Russ Cox.</p>` + "\r\n" +
|
||||
`<p style=3D"font-family:Arial,Sans-serif;color:#666;font-size:11px">To chan=` + "\r\n" +
|
||||
`ge which calendars you receive daily agendas for, please log in to https://=` + "\r\n" +
|
||||
`www.google.com/calendar/ and change your notification settings for each cal=` + "\r\n" +
|
||||
`endar.</p></div>` + "\r\n" +
|
||||
`--bcaec501c5be15fc6504aedc6af3--` + "\r\n" +
|
||||
`)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[TEXT]`: `* 146 FETCH (UID 57046 BODY[TEXT] {1647}` + "\r\n" +
|
||||
`--bcaec501c5be15fc6504aedc6af3` + "\r\n" +
|
||||
`Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`russcox@gmail.com, you have no events scheduled today Sun Oct 9, 2011.` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`View your calendar at https://www.google.com/calendar/` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`You are receiving this email at the account russcox@gmail.com because you ` + "\r\n" +
|
||||
`are subscribed to receive daily agendas for the following calendars: Russ ` + "\r\n" +
|
||||
`Cox.` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`To change which calendars you receive daily agendas for, please log in to ` + "\r\n" +
|
||||
`https://www.google.com/calendar/ and change your notification settings for ` + "\r\n" +
|
||||
`each calendar.` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`--bcaec501c5be15fc6504aedc6af3` + "\r\n" +
|
||||
`Content-Type: text/html; charset=ISO-8859-1` + "\r\n" +
|
||||
`Content-Transfer-Encoding: quoted-printable` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`<div style=3D"padding:10px 7px;font-size:14px;line-height:1.4;font-family:A=` + "\r\n" +
|
||||
`rial,Sans-serif;text-align:left;bgcolor=3D#ffffff"><a href=3D"https://www.g=` + "\r\n" +
|
||||
`oogle.com/calendar/"><img style=3D"border-width:0" src=3D"https://www.googl=` + "\r\n" +
|
||||
`e.com/calendar/images/calendar_logo_sm_en.gif" alt=3D"Google Calendar"></a>` + "\r\n" +
|
||||
`<p style=3D"margin:0;color:#0">russcox@gmail.com, you have no events s=` + "\r\n" +
|
||||
`cheduled today <b>Sun Oct 9, 2011</b></p>` + "\r\n" +
|
||||
`<p style=3D"font-family:Arial,Sans-serif;color:#666;font-size:11px">You are=` + "\r\n" +
|
||||
` receiving this email at the account russcox@gmail.com because you are subs=` + "\r\n" +
|
||||
`cribed to receive daily agendas for the following calendars: Russ Cox.</p>` + "\r\n" +
|
||||
`<p style=3D"font-family:Arial,Sans-serif;color:#666;font-size:11px">To chan=` + "\r\n" +
|
||||
`ge which calendars you receive daily agendas for, please log in to https://=` + "\r\n" +
|
||||
`www.google.com/calendar/ and change your notification settings for each cal=` + "\r\n" +
|
||||
`endar.</p></div>` + "\r\n" +
|
||||
`--bcaec501c5be15fc6504aedc6af3--` + "\r\n" +
|
||||
`)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[HEADER]`: `* 146 FETCH (UID 57046 BODY[HEADER] {2453}` + "\r\n" +
|
||||
`Delivered-To: rsc@swtch.com` + "\r\n" +
|
||||
`Received: by 10.216.54.148 with SMTP id i20cs32329wec; Sun, 9 Oct 2011` + "\r\n" +
|
||||
` 05:00:30 -0700 (PDT)` + "\r\n" +
|
||||
`Received: by 10.227.11.2 with SMTP id r2mr4751812wbr.43.1318161630585; Sun, 09` + "\r\n" +
|
||||
` Oct 2011 05:00:30 -0700 (PDT)` + "\r\n" +
|
||||
`DomainKey-Status: good` + "\r\n" +
|
||||
`Received-SPF: softfail (google.com: best guess record for domain of` + "\r\n" +
|
||||
` transitioning` + "\r\n" +
|
||||
` 3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com` + "\r\n" +
|
||||
` does not designate <unknown> as permitted sender)` + "\r\n" +
|
||||
`Received: by 10.241.227.90 with POP3 id 26mf2646912wyj.48; Sun, 09 Oct 2011` + "\r\n" +
|
||||
` 05:00:29 -0700 (PDT)` + "\r\n" +
|
||||
`X-Gmail-Fetch-Info: russcox@gmail.com 1 smtp.gmail.com 995 russcox` + "\r\n" +
|
||||
`Delivered-To: russcox@gmail.com` + "\r\n" +
|
||||
`Received: by 10.142.76.10 with SMTP id y10cs75487wfa; Sun, 9 Oct 2011 05:00:08` + "\r\n" +
|
||||
` -0700 (PDT)` + "\r\n" +
|
||||
`Return-Path: <3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com>` + "\r\n" +
|
||||
`Received-SPF: pass (google.com: domain of` + "\r\n" +
|
||||
` 3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com` + "\r\n" +
|
||||
` designates 10.52.73.100 as permitted sender) client-ip=10.52.73.100;` + "\r\n" +
|
||||
`Authentication-Results: mr.google.com; spf=pass (google.com: domain of` + "\r\n" +
|
||||
` 3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com` + "\r\n" +
|
||||
` designates 10.52.73.100 as permitted sender)` + "\r\n" +
|
||||
` smtp.mail=3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com;` + "\r\n" +
|
||||
` dkim=pass` + "\r\n" +
|
||||
` header.i=3woyRTgcJB5sMPNN7JSBH5DG.7JHMPNN7JSBH5DG.7JH@calendar-server.bounces.google.com` + "\r\n" +
|
||||
`Received: from mr.google.com ([10.52.73.100]) by 10.52.73.100 with SMTP id` + "\r\n" +
|
||||
` k4mr8053242vdv.5.1318161606360 (num_hops = 1); Sun, 09 Oct 2011 05:00:06` + "\r\n" +
|
||||
` -0700 (PDT)` + "\r\n" +
|
||||
`DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=beta;` + "\r\n" +
|
||||
` h=mime-version:reply-to:auto-submitted:message-id:date:subject:from` + "\r\n" +
|
||||
` :to:content-type; bh=SGjz0F4q+eFVkoC4yzLKQKvlxTKiUsYbO/KPI+3KOE8=;` + "\r\n" +
|
||||
` b=LRBkWBW7ZZ4UJYa7b92zfHa0ZM1K1d0wP/jbgmDw2OZTWtgDICZb30dzhFUfNVdxeN` + "\r\n" +
|
||||
` kdMFbRhTLP5NpSXWhbDw==` + "\r\n" +
|
||||
`MIME-Version: 1.0` + "\r\n" +
|
||||
`Received: by 10.52.73.100 with SMTP id k4mr5244039vdv.5.1318161602706; Sun, 09` + "\r\n" +
|
||||
` Oct 2011 05:00:02 -0700 (PDT)` + "\r\n" +
|
||||
`Reply-To: Russ Cox <russcox@gmail.com>` + "\r\n" +
|
||||
`Auto-Submitted: auto-generated` + "\r\n" +
|
||||
`Message-ID: <bcaec501c5be15fc7204aedc6af6@google.com>` + "\r\n" +
|
||||
`Date: Sun, 09 Oct 2011 12:00:02 +0000` + "\r\n" +
|
||||
`Subject: You have no events scheduled today.` + "\r\n" +
|
||||
`From: Google Calendar <calendar-notification@google.com>` + "\r\n" +
|
||||
`To: Russ Cox <russcox@gmail.com>` + "\r\n" +
|
||||
`Content-Type: multipart/alternative; boundary=bcaec501c5be15fc6504aedc6af3` + "\r\n" +
|
||||
`` + "\r\n" +
|
||||
`)` + "\r\n" +
|
||||
"# OK Success\r\n",
|
||||
`# UID FETCH 57046 BODY[MIME]`: "# BAD Could not parse command\r\n",
|
||||
}
|
||||
|
||||
/*
|
||||
mail sending
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"io/ioutil"
|
||||
"smtp"
|
||||
"time"
|
||||
)
|
||||
var pw, _ = ioutil.ReadFile("/Users/rsc/.swtchpass")
|
||||
var msg = `From: "Russ Cox" <rsc@golang.org>
|
||||
To: "Russ Cox" <rsc@google.com>
|
||||
Subject: test from Go
|
||||
|
||||
This is a message sent from Go
|
||||
`
|
||||
|
||||
BUG: Does not *REQUIRE* auth. Should.
|
||||
|
||||
func main() {
|
||||
auth := smtp.PlainAuth(
|
||||
"",
|
||||
"rsc@swtch.com",
|
||||
string(pw),
|
||||
"smtp.gmail.com",
|
||||
)
|
||||
if err := smtp.SendMail("smtp.gmail.com:587", auth, "rsc@swtch.com", []string{"rsc@google.com"}, []byte(msg+time.LocalTime().String())); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
println("SENT")
|
||||
}
|
||||
*/
|
||||
468
vendor/github.com/mattermost/rsc/imap/mail.go
сгенерированный
поставляемый
468
vendor/github.com/mattermost/rsc/imap/mail.go
сгенерированный
поставляемый
@@ -1,468 +0,0 @@
|
||||
package imap
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Flags uint32
|
||||
|
||||
const (
|
||||
FlagJunk Flags = 1 << iota
|
||||
FlagNonJunk
|
||||
FlagReplied
|
||||
FlagFlagged
|
||||
FlagDeleted
|
||||
FlagDraft
|
||||
FlagRecent
|
||||
FlagSeen
|
||||
FlagNoInferiors
|
||||
FlagNoSelect
|
||||
FlagMarked
|
||||
FlagUnMarked
|
||||
FlagHasChildren
|
||||
FlagHasNoChildren
|
||||
FlagInbox // Gmail extension
|
||||
FlagAllMail // Gmail extension
|
||||
FlagDrafts // Gmail extension
|
||||
FlagSent // Gmail extension
|
||||
FlagSpam // Gmail extension
|
||||
FlagStarred // Gmail extension
|
||||
FlagTrash // Gmail extension
|
||||
FlagImportant // Gmail extension
|
||||
)
|
||||
|
||||
var flagNames = []string{
|
||||
"Junk",
|
||||
"NonJunk",
|
||||
"\\Answered",
|
||||
"\\Flagged",
|
||||
"\\Deleted",
|
||||
"\\Draft",
|
||||
"\\Recent",
|
||||
"\\Seen",
|
||||
"\\NoInferiors",
|
||||
"\\NoSelect",
|
||||
"\\Marked",
|
||||
"\\UnMarked",
|
||||
"\\HasChildren",
|
||||
"\\HasNoChildren",
|
||||
"\\Inbox",
|
||||
"\\AllMail",
|
||||
"\\Drafts",
|
||||
"\\Sent",
|
||||
"\\Spam",
|
||||
"\\Starred",
|
||||
"\\Trash",
|
||||
"\\Important",
|
||||
}
|
||||
|
||||
// A Box represents an IMAP mailbox.
|
||||
type Box struct {
|
||||
Name string // name of mailbox
|
||||
Elem string // last element in name
|
||||
Client *Client
|
||||
|
||||
parent *Box // parent in hierarchy
|
||||
child []*Box // child boxes
|
||||
dead bool // box no longer exists
|
||||
inbox bool // box is inbox
|
||||
flags Flags // allowed flags
|
||||
permFlags Flags // client-modifiable permanent flags
|
||||
readOnly bool // box is read-only
|
||||
|
||||
exists int // number of messages in box (according to server)
|
||||
maxSeen int // maximum message number seen (for polling)
|
||||
unseen int // number of first unseen message
|
||||
validity uint32 // UID validity base number
|
||||
load bool // if false, don't track full set of messages
|
||||
firstNum int // 0 means box not loaded
|
||||
msgByNum []*Msg
|
||||
msgByUID map[uint64]*Msg
|
||||
}
|
||||
|
||||
func (c *Client) Boxes() []*Box {
|
||||
c.data.lock()
|
||||
defer c.data.unlock()
|
||||
|
||||
box := make([]*Box, len(c.allBox))
|
||||
copy(box, c.allBox)
|
||||
return box
|
||||
}
|
||||
|
||||
func (c *Client) Box(name string) *Box {
|
||||
c.data.lock()
|
||||
defer c.data.unlock()
|
||||
|
||||
return c.boxByName[name]
|
||||
}
|
||||
|
||||
func (c *Client) Inbox() *Box {
|
||||
c.data.lock()
|
||||
defer c.data.unlock()
|
||||
|
||||
return c.inbox
|
||||
}
|
||||
|
||||
func (c *Client) newBox(name, sep string, inbox bool) *Box {
|
||||
c.data.mustBeLocked()
|
||||
if b := c.boxByName[name]; b != nil {
|
||||
return b
|
||||
}
|
||||
|
||||
b := &Box{
|
||||
Name: name,
|
||||
Elem: name,
|
||||
Client: c,
|
||||
inbox: inbox,
|
||||
}
|
||||
if !inbox {
|
||||
b.parent = c.rootBox
|
||||
}
|
||||
if !inbox && sep != "" && name != c.root {
|
||||
if i := strings.LastIndex(name, sep); i >= 0 {
|
||||
b.Elem = name[i+len(sep):]
|
||||
b.parent = c.newBox(name[:i], sep, false)
|
||||
}
|
||||
}
|
||||
c.allBox = append(c.allBox, b)
|
||||
c.boxByName[name] = b
|
||||
if b.parent != nil {
|
||||
b.parent.child = append(b.parent.child, b)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// A Msg represents an IMAP message.
|
||||
type Msg struct {
|
||||
Box *Box // box containing message
|
||||
Date time.Time // date
|
||||
Flags Flags // message flags
|
||||
Bytes int64 // size in bytes
|
||||
Lines int64 // number of lines
|
||||
Hdr *MsgHdr // MIME header
|
||||
Root MsgPart // top-level message part
|
||||
GmailID uint64 // Gmail message id
|
||||
GmailThread uint64 // Gmail thread id
|
||||
UID uint64 // unique id for this message
|
||||
|
||||
deleted bool
|
||||
dead bool
|
||||
num int // message number in box (changes)
|
||||
}
|
||||
|
||||
// TODO: Return os.Error too
|
||||
|
||||
type byUID []*Msg
|
||||
|
||||
func (x byUID) Len() int { return len(x) }
|
||||
func (x byUID) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||
func (x byUID) Less(i, j int) bool { return x[i].UID < x[j].UID }
|
||||
|
||||
func (b *Box) Msgs() []*Msg {
|
||||
b.Client.data.lock()
|
||||
defer b.Client.data.unlock()
|
||||
|
||||
msgs := make([]*Msg, len(b.msgByUID))
|
||||
n := 0
|
||||
for _, m := range b.msgByUID {
|
||||
msgs[n] = m
|
||||
n++
|
||||
}
|
||||
sort.Sort(byUID(msgs))
|
||||
return msgs
|
||||
}
|
||||
|
||||
func (b *Box) newMsg(uid uint64, id int) *Msg {
|
||||
b.Client.data.mustBeLocked()
|
||||
if m := b.msgByUID[uid]; m != nil {
|
||||
return m
|
||||
}
|
||||
if b.msgByUID == nil {
|
||||
b.msgByUID = map[uint64]*Msg{}
|
||||
}
|
||||
m := &Msg{
|
||||
UID: uid,
|
||||
Box: b,
|
||||
num: id,
|
||||
}
|
||||
m.Root.Msg = m
|
||||
if b.load {
|
||||
if b.firstNum == 0 {
|
||||
b.firstNum = id
|
||||
}
|
||||
if id < b.firstNum {
|
||||
log.Printf("warning: unexpected id %d < %d", id, b.firstNum)
|
||||
byNum := make([]*Msg, len(b.msgByNum)+b.firstNum-id)
|
||||
copy(byNum[b.firstNum-id:], b.msgByNum)
|
||||
b.msgByNum = byNum
|
||||
b.firstNum = id
|
||||
}
|
||||
if id-b.firstNum < len(b.msgByNum) {
|
||||
b.msgByNum[id-b.firstNum] = m
|
||||
} else {
|
||||
if id-b.firstNum > len(b.msgByNum) {
|
||||
log.Printf("warning: unexpected id %d > %d", id, b.firstNum+len(b.msgByNum))
|
||||
byNum := make([]*Msg, id-b.firstNum)
|
||||
copy(byNum, b.msgByNum)
|
||||
b.msgByNum = byNum
|
||||
}
|
||||
b.msgByNum = append(b.msgByNum, m)
|
||||
}
|
||||
}
|
||||
b.msgByUID[uid] = m
|
||||
return m
|
||||
}
|
||||
|
||||
func (b *Box) Delete(msgs []*Msg) error {
|
||||
for _, m := range msgs {
|
||||
if m.Box != b {
|
||||
return fmt.Errorf("messages not from this box")
|
||||
}
|
||||
}
|
||||
b.Client.io.lock()
|
||||
defer b.Client.io.unlock()
|
||||
err := b.Client.deleteList(msgs)
|
||||
if err == nil {
|
||||
b.Client.data.lock()
|
||||
defer b.Client.data.unlock()
|
||||
for _, m := range msgs {
|
||||
if m.Flags&FlagDeleted != 0 {
|
||||
delete(b.msgByUID, m.UID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *Box) Copy(msgs []*Msg) error {
|
||||
if len(msgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
src := msgs[0].Box
|
||||
for _, m := range msgs {
|
||||
if m.Box != src {
|
||||
return fmt.Errorf("messages span boxes: %q and %q", src.Name, m.Box.Name)
|
||||
}
|
||||
}
|
||||
b.Client.io.lock()
|
||||
defer b.Client.io.unlock()
|
||||
return b.Client.copyList(b, src, msgs)
|
||||
}
|
||||
|
||||
func (b *Box) Mute(msgs []*Msg) error {
|
||||
if len(msgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
for _, m := range msgs {
|
||||
if m.Box != b {
|
||||
return fmt.Errorf("messages not from this box")
|
||||
}
|
||||
}
|
||||
b.Client.io.lock()
|
||||
defer b.Client.io.unlock()
|
||||
return b.Client.muteList(b, msgs)
|
||||
}
|
||||
|
||||
func (b *Box) Check() error {
|
||||
b.Client.io.lock()
|
||||
defer b.Client.io.unlock()
|
||||
|
||||
return b.Client.check(b)
|
||||
}
|
||||
|
||||
func (m *Msg) Deleted() bool {
|
||||
// Racy but okay. Can add a lock later if it matters.
|
||||
return m.Flags&FlagDeleted != 0
|
||||
}
|
||||
|
||||
// A Hdr represents a message header.
|
||||
type MsgHdr struct {
|
||||
Date string
|
||||
Subject string
|
||||
From []Addr
|
||||
Sender []Addr
|
||||
ReplyTo []Addr
|
||||
To []Addr
|
||||
CC []Addr
|
||||
BCC []Addr
|
||||
InReplyTo string
|
||||
MessageID string
|
||||
Digest string
|
||||
}
|
||||
|
||||
// An Addr represents a single, named email address.
|
||||
// If Name is empty, only the email address is known.
|
||||
// If Email is empty, the Addr represents an unspecified (but named) group.
|
||||
type Addr struct {
|
||||
Name string
|
||||
Email string
|
||||
}
|
||||
|
||||
func (a Addr) String() string {
|
||||
if a.Email == "" {
|
||||
return a.Name
|
||||
}
|
||||
if a.Name == "" {
|
||||
return a.Email
|
||||
}
|
||||
return a.Name + " <" + a.Email + ">"
|
||||
}
|
||||
|
||||
// A MsgPart represents a single part of a MIME-encoded message.
|
||||
type MsgPart struct {
|
||||
Msg *Msg // containing message
|
||||
Type string
|
||||
ContentID string
|
||||
Desc string
|
||||
Encoding string
|
||||
Bytes int64
|
||||
Lines int64
|
||||
Charset string
|
||||
Name string
|
||||
Hdr *MsgHdr
|
||||
ID string
|
||||
Child []*MsgPart
|
||||
|
||||
raw []byte // raw message
|
||||
rawHeader []byte // raw RFC-2822 header, for message/rfc822
|
||||
rawBody []byte // raw RFC-2822 body, for message/rfc822
|
||||
mimeHeader []byte // mime header, for attachments
|
||||
}
|
||||
|
||||
func (p *MsgPart) newPart() *MsgPart {
|
||||
p.Msg.Box.Client.data.mustBeLocked()
|
||||
dot := "."
|
||||
if p.ID == "" { // no dot at root
|
||||
dot = ""
|
||||
}
|
||||
pp := &MsgPart{
|
||||
Msg: p.Msg,
|
||||
ID: fmt.Sprint(p.ID, dot, 1+len(p.Child)),
|
||||
}
|
||||
p.Child = append(p.Child, pp)
|
||||
return pp
|
||||
}
|
||||
|
||||
func (p *MsgPart) Text() []byte {
|
||||
c := p.Msg.Box.Client
|
||||
var raw []byte
|
||||
c.data.lock()
|
||||
if p == &p.Msg.Root {
|
||||
raw = p.rawBody
|
||||
c.data.unlock()
|
||||
if raw == nil {
|
||||
c.io.lock()
|
||||
if raw = p.rawBody; raw == nil {
|
||||
c.fetch(p, "TEXT")
|
||||
raw = p.rawBody
|
||||
}
|
||||
c.io.unlock()
|
||||
}
|
||||
} else {
|
||||
raw = p.raw
|
||||
c.data.unlock()
|
||||
if raw == nil {
|
||||
c.io.lock()
|
||||
if raw = p.raw; raw == nil {
|
||||
c.fetch(p, "")
|
||||
raw = p.raw
|
||||
}
|
||||
c.io.unlock()
|
||||
}
|
||||
}
|
||||
return decodeText(raw, p.Encoding, p.Charset, false)
|
||||
}
|
||||
|
||||
func (p *MsgPart) Raw() []byte {
|
||||
c := p.Msg.Box.Client
|
||||
var raw []byte
|
||||
c.data.lock()
|
||||
raw = p.rawBody
|
||||
c.data.unlock()
|
||||
if raw == nil {
|
||||
c.io.lock()
|
||||
if raw = p.rawBody; raw == nil {
|
||||
c.fetch(p, "")
|
||||
raw = p.rawBody
|
||||
}
|
||||
c.io.unlock()
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
var sigDash = []byte("\n--\n")
|
||||
var quote = []byte("\n> ")
|
||||
var nl = []byte("\n")
|
||||
|
||||
var onwrote = regexp.MustCompile(`\A\s*On .* wrote:\s*\z`)
|
||||
|
||||
func (p *MsgPart) ShortText() []byte {
|
||||
t := p.Text()
|
||||
|
||||
return shortText(t)
|
||||
}
|
||||
|
||||
func shortText(t []byte) []byte {
|
||||
if t == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Cut signature.
|
||||
i := bytes.LastIndex(t, sigDash)
|
||||
j := bytes.LastIndex(t, quote)
|
||||
if i > j && bytes.Count(t[i+1:], nl) <= 10 {
|
||||
t = t[:i+1]
|
||||
}
|
||||
|
||||
// Cut trailing quoted text.
|
||||
for {
|
||||
rest, last := lastLine(t)
|
||||
trim := bytes.TrimSpace(last)
|
||||
if len(rest) < len(t) && (len(trim) == 0 || trim[0] == '>') {
|
||||
t = rest
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Cut 'On foo.*wrote:' line.
|
||||
rest, last := lastLine(t)
|
||||
if onwrote.Match(last) {
|
||||
t = rest
|
||||
}
|
||||
|
||||
// Cut trailing blank lines.
|
||||
for {
|
||||
rest, last := lastLine(t)
|
||||
trim := bytes.TrimSpace(last)
|
||||
if len(rest) < len(t) && len(trim) == 0 {
|
||||
t = rest
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Cut signature again.
|
||||
i = bytes.LastIndex(t, sigDash)
|
||||
j = bytes.LastIndex(t, quote)
|
||||
if i > j && bytes.Count(t[i+1:], nl) <= 10 {
|
||||
t = t[:i+1]
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func lastLine(t []byte) (rest, last []byte) {
|
||||
n := len(t)
|
||||
if n > 0 && t[n-1] == '\n' {
|
||||
n--
|
||||
}
|
||||
j := bytes.LastIndex(t[:n], nl)
|
||||
return t[:j+1], t[j+1:]
|
||||
}
|
||||
335
vendor/github.com/mattermost/rsc/imap/mail_test.go
сгенерированный
поставляемый
335
vendor/github.com/mattermost/rsc/imap/mail_test.go
сгенерированный
поставляемый
@@ -1,335 +0,0 @@
|
||||
package imap
|
||||
|
||||
import "testing"
|
||||
|
||||
var shortTextTests = []struct {
|
||||
in, out string
|
||||
}{
|
||||
{
|
||||
in: `From: Brad Fitzpatrick <bradfitz@golang.org>
|
||||
Date: Tue Oct 18 18:23:11 EDT 2011
|
||||
To: r@golang.org, golang-dev@googlegroups.com, reply@codereview.appspotmail.com
|
||||
Subject: Re: [golang-dev] code review 5307043: rpc: don't panic on write error. (issue 5307043)
|
||||
|
||||
Here's a test:
|
||||
|
||||
bradfitz@gopher:~/go/src/pkg/rpc$ hg diff
|
||||
diff -r b7f9a5e9b87f src/pkg/rpc/server_test.go
|
||||
--- a/src/pkg/rpc/server_test.go Tue Oct 18 17:01:42 2011 -0500
|
||||
+++ b/src/pkg/rpc/server_test.go Tue Oct 18 15:22:19 2011 -0700
|
||||
@@ -467,6 +467,27 @@
|
||||
fmt.Printf("mallocs per HTTP rpc round trip: %d\n",
|
||||
countMallocs(dialHTTP, t))
|
||||
}
|
||||
|
||||
+type writeCrasher struct{}
|
||||
+
|
||||
+func (writeCrasher) Close() os.Error {
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func (writeCrasher) Read(p []byte) (int, os.Error) {
|
||||
+ return 0, os.EOF
|
||||
+}
|
||||
+
|
||||
+func (writeCrasher) Write(p []byte) (int, os.Error) {
|
||||
+ return 0, os.NewError("fake write failure")
|
||||
+}
|
||||
+
|
||||
+func TestClientWriteError(t *testing.T) {
|
||||
+ c := NewClient(writeCrasher{})
|
||||
+ res := false
|
||||
+ c.Call("foo", 1, &res)
|
||||
+}
|
||||
+
|
||||
func benchmarkEndToEnd(dial func() (*Client, os.Error), b *testing.B) {
|
||||
b.StopTimer()
|
||||
once.Do(startServer)
|
||||
|
||||
|
||||
On Tue, Oct 18, 2011 at 3:12 PM, <r@golang.org> wrote:
|
||||
|
||||
> Reviewers: golang-dev_googlegroups.com,
|
||||
>
|
||||
> Message:
|
||||
> Hello golang-dev@googlegroups.com,
|
||||
>
|
||||
> I'd like you to review this change to
|
||||
> https://go.googlecode.com/hg/
|
||||
>
|
||||
>
|
||||
> Description:
|
||||
> rpc: don't panic on write error.
|
||||
> The mechanism to record the error in the call is already in place.
|
||||
> Fixes issue 2382.
|
||||
>
|
||||
> Please review this at http://codereview.appspot.com/**5307043/<http://codereview.appspot.com/5307043/>
|
||||
>
|
||||
> Affected files:
|
||||
> M src/pkg/rpc/client.go
|
||||
>
|
||||
>
|
||||
> Index: src/pkg/rpc/client.go
|
||||
> ==============================**==============================**=======
|
||||
> --- a/src/pkg/rpc/client.go
|
||||
> +++ b/src/pkg/rpc/client.go
|
||||
> @@ -85,7 +85,8 @@
|
||||
> client.request.Seq = c.seq
|
||||
> client.request.ServiceMethod = c.ServiceMethod
|
||||
> if err := client.codec.WriteRequest(&**client.request, c.Args); err
|
||||
> != nil {
|
||||
> - panic("rpc: client encode error: " + err.String())
|
||||
> + c.Error = err
|
||||
> + c.done()
|
||||
> }
|
||||
> }
|
||||
>
|
||||
> @@ -251,10 +252,10 @@
|
||||
> // the same Call object. If done is nil, Go will allocate a new channel.
|
||||
> // If non-nil, done must be buffered or Go will deliberately crash.
|
||||
> func (client *Client) Go(serviceMethod string, args interface{}, reply
|
||||
> interface{}, done chan *Call) *Call {
|
||||
> - c := new(Call)
|
||||
> - c.ServiceMethod = serviceMethod
|
||||
> - c.Args = args
|
||||
> - c.Reply = reply
|
||||
> + call := new(Call)
|
||||
> + call.ServiceMethod = serviceMethod
|
||||
> + call.Args = args
|
||||
> + call.Reply = reply
|
||||
> if done == nil {
|
||||
> done = make(chan *Call, 10) // buffered.
|
||||
> } else {
|
||||
> @@ -266,14 +267,14 @@
|
||||
> log.Panic("rpc: done channel is unbuffered")
|
||||
> }
|
||||
> }
|
||||
> - c.Done = done
|
||||
> + call.Done = done
|
||||
> if client.shutdown {
|
||||
> - c.Error = ErrShutdown
|
||||
> - c.done()
|
||||
> - return c
|
||||
> + call.Error = ErrShutdown
|
||||
> + call.done()
|
||||
> + return call
|
||||
> }
|
||||
> - client.send(c)
|
||||
> - return c
|
||||
> + client.send(call)
|
||||
> + return call
|
||||
> }
|
||||
>
|
||||
> // Call invokes the named function, waits for it to complete, and returns
|
||||
> its error status.
|
||||
>
|
||||
>
|
||||
>
|
||||
|
||||
`,
|
||||
out: `From: Brad Fitzpatrick <bradfitz@golang.org>
|
||||
Date: Tue Oct 18 18:23:11 EDT 2011
|
||||
To: r@golang.org, golang-dev@googlegroups.com, reply@codereview.appspotmail.com
|
||||
Subject: Re: [golang-dev] code review 5307043: rpc: don't panic on write error. (issue 5307043)
|
||||
|
||||
Here's a test:
|
||||
|
||||
bradfitz@gopher:~/go/src/pkg/rpc$ hg diff
|
||||
diff -r b7f9a5e9b87f src/pkg/rpc/server_test.go
|
||||
--- a/src/pkg/rpc/server_test.go Tue Oct 18 17:01:42 2011 -0500
|
||||
+++ b/src/pkg/rpc/server_test.go Tue Oct 18 15:22:19 2011 -0700
|
||||
@@ -467,6 +467,27 @@
|
||||
fmt.Printf("mallocs per HTTP rpc round trip: %d\n",
|
||||
countMallocs(dialHTTP, t))
|
||||
}
|
||||
|
||||
+type writeCrasher struct{}
|
||||
+
|
||||
+func (writeCrasher) Close() os.Error {
|
||||
+ return nil
|
||||
+}
|
||||
+
|
||||
+func (writeCrasher) Read(p []byte) (int, os.Error) {
|
||||
+ return 0, os.EOF
|
||||
+}
|
||||
+
|
||||
+func (writeCrasher) Write(p []byte) (int, os.Error) {
|
||||
+ return 0, os.NewError("fake write failure")
|
||||
+}
|
||||
+
|
||||
+func TestClientWriteError(t *testing.T) {
|
||||
+ c := NewClient(writeCrasher{})
|
||||
+ res := false
|
||||
+ c.Call("foo", 1, &res)
|
||||
+}
|
||||
+
|
||||
func benchmarkEndToEnd(dial func() (*Client, os.Error), b *testing.B) {
|
||||
b.StopTimer()
|
||||
once.Do(startServer)
|
||||
`,
|
||||
},
|
||||
{
|
||||
in: `From: David Symonds <dsymonds@golang.org>
|
||||
Date: Tue Oct 18 18:17:52 EDT 2011
|
||||
To: reply@codereview.appspotmail.com, r@golang.org, golang-dev@googlegroups.com
|
||||
Subject: Re: [golang-dev] code review 5307043: rpc: don't panic on write error. (issue 5307043)
|
||||
|
||||
LGTM
|
||||
On Oct 19, 2011 9:12 AM, <r@golang.org> wrote:
|
||||
|
||||
> Reviewers: golang-dev_googlegroups.com,
|
||||
>
|
||||
> Message:
|
||||
> Hello golang-dev@googlegroups.com,
|
||||
>
|
||||
> I'd like you to review this change to
|
||||
> https://go.googlecode.com/hg/
|
||||
>
|
||||
>
|
||||
> Description:
|
||||
> rpc: don't panic on write error.
|
||||
> The mechanism to record the error in the call is already in place.
|
||||
> Fixes issue 2382.
|
||||
>
|
||||
> Please review this at http://codereview.appspot.com/**5307043/<http://codereview.appspot.com/5307043/>
|
||||
>
|
||||
> Affected files:
|
||||
> M src/pkg/rpc/client.go
|
||||
>
|
||||
>
|
||||
> Index: src/pkg/rpc/client.go
|
||||
> ==============================**==============================**=======
|
||||
> --- a/src/pkg/rpc/client.go
|
||||
> +++ b/src/pkg/rpc/client.go
|
||||
> @@ -85,7 +85,8 @@
|
||||
> client.request.Seq = c.seq
|
||||
> client.request.ServiceMethod = c.ServiceMethod
|
||||
> if err := client.codec.WriteRequest(&**client.request, c.Args); err
|
||||
> != nil {
|
||||
> - panic("rpc: client encode error: " + err.String())
|
||||
> + c.Error = err
|
||||
> + c.done()
|
||||
> }
|
||||
> }
|
||||
>
|
||||
> @@ -251,10 +252,10 @@
|
||||
> // the same Call object. If done is nil, Go will allocate a new channel.
|
||||
> // If non-nil, done must be buffered or Go will deliberately crash.
|
||||
> func (client *Client) Go(serviceMethod string, args interface{}, reply
|
||||
> interface{}, done chan *Call) *Call {
|
||||
> - c := new(Call)
|
||||
> - c.ServiceMethod = serviceMethod
|
||||
> - c.Args = args
|
||||
> - c.Reply = reply
|
||||
> + call := new(Call)
|
||||
> + call.ServiceMethod = serviceMethod
|
||||
> + call.Args = args
|
||||
> + call.Reply = reply
|
||||
> if done == nil {
|
||||
> done = make(chan *Call, 10) // buffered.
|
||||
> } else {
|
||||
> @@ -266,14 +267,14 @@
|
||||
> log.Panic("rpc: done channel is unbuffered")
|
||||
> }
|
||||
> }
|
||||
> - c.Done = done
|
||||
> + call.Done = done
|
||||
> if client.shutdown {
|
||||
> - c.Error = ErrShutdown
|
||||
> - c.done()
|
||||
> - return c
|
||||
> + call.Error = ErrShutdown
|
||||
> + call.done()
|
||||
> + return call
|
||||
> }
|
||||
> - client.send(c)
|
||||
> - return c
|
||||
> + client.send(call)
|
||||
> + return call
|
||||
> }
|
||||
>
|
||||
> // Call invokes the named function, waits for it to complete, and returns
|
||||
> its error status.
|
||||
>
|
||||
>
|
||||
>
|
||||
|
||||
`,
|
||||
out: `From: David Symonds <dsymonds@golang.org>
|
||||
Date: Tue Oct 18 18:17:52 EDT 2011
|
||||
To: reply@codereview.appspotmail.com, r@golang.org, golang-dev@googlegroups.com
|
||||
Subject: Re: [golang-dev] code review 5307043: rpc: don't panic on write error. (issue 5307043)
|
||||
|
||||
LGTM
|
||||
`,
|
||||
},
|
||||
{
|
||||
in: `From: Brad Fitzpatrick <bradfitz@golang.org>
|
||||
Date: Tue Oct 18 23:26:07 EDT 2011
|
||||
To: rsc@golang.org, golang-dev@googlegroups.com, reply@codereview.appspotmail.com
|
||||
Subject: Re: [golang-dev] code review 5297044: gotest: use $GCFLAGS like make does (issue 5297044)
|
||||
|
||||
LGTM
|
||||
|
||||
On Tue, Oct 18, 2011 at 7:52 PM, <rsc@golang.org> wrote:
|
||||
|
||||
> Reviewers: golang-dev_googlegroups.com,
|
||||
>
|
||||
> Message:
|
||||
> Hello golang-dev@googlegroups.com,
|
||||
>
|
||||
> I'd like you to review this change to
|
||||
> https://go.googlecode.com/hg/
|
||||
>
|
||||
>
|
||||
> Description:
|
||||
> gotest: use $GCFLAGS like make does
|
||||
>
|
||||
> Please review this at http://codereview.appspot.com/**5297044/<http://codereview.appspot.com/5297044/>
|
||||
>
|
||||
> Affected files:
|
||||
> M src/cmd/gotest/gotest.go
|
||||
>
|
||||
>
|
||||
> Index: src/cmd/gotest/gotest.go
|
||||
> ==============================**==============================**=======
|
||||
> --- a/src/cmd/gotest/gotest.go
|
||||
> +++ b/src/cmd/gotest/gotest.go
|
||||
> @@ -153,8 +153,12 @@
|
||||
> if gc == "" {
|
||||
> gc = O + "g"
|
||||
> }
|
||||
> - XGC = []string{gc, "-I", "_test", "-o", "_xtest_." + O}
|
||||
> - GC = []string{gc, "-I", "_test", "_testmain.go"}
|
||||
> + var gcflags []string
|
||||
> + if gf := strings.TrimSpace(os.Getenv("**GCFLAGS")); gf != "" {
|
||||
> + gcflags = strings.Fields(gf)
|
||||
> + }
|
||||
> + XGC = append([]string{gc, "-I", "_test", "-o", "_xtest_." + O},
|
||||
> gcflags...)
|
||||
> + GC = append(append([]string{gc, "-I", "_test"}, gcflags...),
|
||||
> "_testmain.go")
|
||||
> gl := os.Getenv("GL")
|
||||
> if gl == "" {
|
||||
> gl = O + "l"
|
||||
>
|
||||
>
|
||||
>
|
||||
`,
|
||||
out: `From: Brad Fitzpatrick <bradfitz@golang.org>
|
||||
Date: Tue Oct 18 23:26:07 EDT 2011
|
||||
To: rsc@golang.org, golang-dev@googlegroups.com, reply@codereview.appspotmail.com
|
||||
Subject: Re: [golang-dev] code review 5297044: gotest: use $GCFLAGS like make does (issue 5297044)
|
||||
|
||||
LGTM
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
func TestShortText(t *testing.T) {
|
||||
for i, tt := range shortTextTests {
|
||||
if out := string(shortText([]byte(tt.in))); out != tt.out {
|
||||
t.Errorf("#%d: = %q, want %q\n", i, out, tt.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
1739
vendor/github.com/mattermost/rsc/imap/rfc2045.txt
сгенерированный
поставляемый
1739
vendor/github.com/mattermost/rsc/imap/rfc2045.txt
сгенерированный
поставляемый
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
451
vendor/github.com/mattermost/rsc/imap/rfc2971.txt
сгенерированный
поставляемый
451
vendor/github.com/mattermost/rsc/imap/rfc2971.txt
сгенерированный
поставляемый
@@ -1,451 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Network Working Group T. Showalter
|
||||
Request for Comments: 2971 Mirapoint, Inc.
|
||||
Category: Standards Track October 2000
|
||||
|
||||
|
||||
IMAP4 ID extension
|
||||
|
||||
Status of this Memo
|
||||
|
||||
This document specifies an Internet standards track protocol for the
|
||||
Internet community, and requests discussion and suggestions for
|
||||
improvements. Please refer to the current edition of the "Internet
|
||||
Official Protocol Standards" (STD 1) for the standardization state
|
||||
and status of this protocol. Distribution of this memo is unlimited.
|
||||
|
||||
Copyright Notice
|
||||
|
||||
Copyright (C) The Internet Society (2000). All Rights Reserved.
|
||||
|
||||
Abstract
|
||||
|
||||
The ID extension to the Internet Message Access Protocol - Version
|
||||
4rev1 (IMAP4rev1) protocol allows the server and client to exchange
|
||||
identification information on their implementation in order to make
|
||||
bug reports and usage statistics more complete.
|
||||
|
||||
1. Introduction
|
||||
|
||||
The IMAP4rev1 protocol described in [IMAP4rev1] provides a method for
|
||||
accessing remote mail stores, but it provides no facility to
|
||||
advertise what program a client or server uses to provide service.
|
||||
This makes it difficult for implementors to get complete bug reports
|
||||
from users, as it is frequently difficult to know what client or
|
||||
server is in use.
|
||||
|
||||
Additionally, some sites may wish to assemble usage statistics based
|
||||
on what clients are used, but in an an environment where users are
|
||||
permitted to obtain and maintain their own clients this is difficult
|
||||
to accomplish.
|
||||
|
||||
The ID command provides a facility to advertise information on what
|
||||
programs are being used along with contact information (should bugs
|
||||
ever occur).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Showalter Standards Track [Page 1]
|
||||
|
||||
RFC 2971 IMAP4 ID extension October 2000
|
||||
|
||||
|
||||
2. Conventions Used in this Document
|
||||
|
||||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
|
||||
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
|
||||
document are to be interpreted as described in [KEYWORDS].
|
||||
|
||||
The conventions used in this document are the same as specified in
|
||||
[IMAP4rev1]. In examples, "C:" and "S:" indicate lines sent by the
|
||||
client and server respectively. Line breaks have been inserted for
|
||||
readability.
|
||||
|
||||
3. Specification
|
||||
|
||||
The sole purpose of the ID extension is to enable clients and servers
|
||||
to exchange information on their implementations for the purposes of
|
||||
statistical analysis and problem determination.
|
||||
|
||||
This information is be submitted to a server by any client wishing to
|
||||
provide information for statistical purposes, provided the server
|
||||
advertises its willingness to take the information with the atom "ID"
|
||||
included in the list of capabilities returned by the CAPABILITY
|
||||
command.
|
||||
|
||||
Implementations MUST NOT make operational changes based on the data
|
||||
sent as part of the ID command or response. The ID command is for
|
||||
human consumption only, and is not to be used in improving the
|
||||
performance of clients or servers.
|
||||
|
||||
This includes, but is not limited to, the following:
|
||||
|
||||
Servers MUST NOT attempt to work around client bugs by using
|
||||
information from the ID command. Clients MUST NOT attempt to work
|
||||
around server bugs based on the ID response.
|
||||
|
||||
Servers MUST NOT provide features to a client or otherwise
|
||||
optimize for a particular client by using information from the ID
|
||||
command. Clients MUST NOT provide features to a server or
|
||||
otherwise optimize for a particular server based on the ID
|
||||
response.
|
||||
|
||||
Servers MUST NOT deny access to or refuse service for a client
|
||||
based on information from the ID command. Clients MUST NOT refuse
|
||||
to operate or limit their operation with a server based on the ID
|
||||
response.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Showalter Standards Track [Page 2]
|
||||
|
||||
RFC 2971 IMAP4 ID extension October 2000
|
||||
|
||||
|
||||
Rationale: It is imperative that this extension not supplant IMAP's
|
||||
CAPABILITY mechanism with a ad-hoc approach where implementations
|
||||
guess each other's features based on who they claim to be.
|
||||
|
||||
Implementations MUST NOT send false information in an ID command.
|
||||
|
||||
Implementations MAY send less information than they have available or
|
||||
no information at all. Such behavior may be useful to preserve user
|
||||
privacy. See Security Considerations, section 7.
|
||||
|
||||
3.1. ID Command
|
||||
|
||||
Arguments: client parameter list or NIL
|
||||
|
||||
Responses: OPTIONAL untagged response: ID
|
||||
|
||||
Result: OK identification information accepted
|
||||
BAD command unknown or arguments invalid
|
||||
|
||||
Implementation identification information is sent by the client with
|
||||
the ID command.
|
||||
|
||||
This command is valid in any state.
|
||||
|
||||
The information sent is in the form of a list of field/value pairs.
|
||||
Fields are permitted to be any IMAP4 string, and values are permitted
|
||||
to be any IMAP4 string or NIL. A value of NIL indicates that the
|
||||
client can not or will not specify this information. The client may
|
||||
also send NIL instead of the list, indicating that it wants to send
|
||||
no information, but would still accept a server response.
|
||||
|
||||
The available fields are defined in section 3.3.
|
||||
|
||||
Example: C: a023 ID ("name" "sodr" "version" "19.34" "vendor"
|
||||
"Pink Floyd Music Limited")
|
||||
S: * ID NIL
|
||||
S: a023 OK ID completed
|
||||
|
||||
3.2. ID Response
|
||||
|
||||
Contents: server parameter list
|
||||
|
||||
In response to an ID command issued by the client, the server replies
|
||||
with a tagged response containing information on its implementation.
|
||||
The format is the same as the client list.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Showalter Standards Track [Page 3]
|
||||
|
||||
RFC 2971 IMAP4 ID extension October 2000
|
||||
|
||||
|
||||
Example: C: a042 ID NIL
|
||||
S: * ID ("name" "Cyrus" "version" "1.5" "os" "sunos"
|
||||
"os-version" "5.5" "support-url"
|
||||
"mailto:cyrus-bugs+@andrew.cmu.edu")
|
||||
S: a042 OK ID command completed
|
||||
|
||||
A server MUST send a tagged ID response to an ID command. However, a
|
||||
server MAY send NIL in place of the list.
|
||||
|
||||
3.3. Defined Field Values
|
||||
|
||||
Any string may be sent as a field, but the following are defined to
|
||||
describe certain values that might be sent. Implementations are free
|
||||
to send none, any, or all of these. Strings are not case-sensitive.
|
||||
Field strings MUST NOT be longer than 30 octets. Value strings MUST
|
||||
NOT be longer than 1024 octets. Implementations MUST NOT send more
|
||||
than 30 field-value pairs.
|
||||
|
||||
name Name of the program
|
||||
version Version number of the program
|
||||
os Name of the operating system
|
||||
os-version Version of the operating system
|
||||
vendor Vendor of the client/server
|
||||
support-url URL to contact for support
|
||||
address Postal address of contact/vendor
|
||||
date Date program was released, specified as a date-time
|
||||
in IMAP4rev1
|
||||
command Command used to start the program
|
||||
arguments Arguments supplied on the command line, if any
|
||||
if any
|
||||
environment Description of environment, i.e., UNIX environment
|
||||
variables or Windows registry settings
|
||||
|
||||
Implementations MUST NOT use contact information to submit automatic
|
||||
bug reports. Implementations may include information from an ID
|
||||
response in a report automatically prepared, but are prohibited from
|
||||
sending the report without user authorization.
|
||||
|
||||
It is preferable to find the name and version of the underlying
|
||||
operating system at runtime in cases where this is possible.
|
||||
|
||||
Information sent via an ID response may violate user privacy. See
|
||||
Security Considerations, section 7.
|
||||
|
||||
Implementations MUST NOT send the same field name more than once.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Showalter Standards Track [Page 4]
|
||||
|
||||
RFC 2971 IMAP4 ID extension October 2000
|
||||
|
||||
|
||||
4. Formal Syntax
|
||||
|
||||
This syntax is intended to augment the grammar specified in
|
||||
[IMAP4rev1] in order to provide for the ID command. This
|
||||
specification uses the augmented Backus-Naur Form (BNF) notation as
|
||||
used in [IMAP4rev1].
|
||||
|
||||
command_any ::= "CAPABILITY" / "LOGOUT" / "NOOP" / x_command / id
|
||||
;; adds id command to command_any in [IMAP4rev1]
|
||||
|
||||
id ::= "ID" SPACE id_params_list
|
||||
|
||||
id_response ::= "ID" SPACE id_params_list
|
||||
|
||||
id_params_list ::= "(" #(string SPACE nstring) ")" / nil
|
||||
;; list of field value pairs
|
||||
|
||||
response_data ::= "*" SPACE (resp_cond_state / resp_cond_bye /
|
||||
mailbox_data / message_data / capability_data / id_response)
|
||||
|
||||
5. Use of the ID extension with Firewalls and Other Intermediaries
|
||||
|
||||
There exist proxies, firewalls, and other intermediary systems that
|
||||
can intercept an IMAP session and make changes to the data exchanged
|
||||
in the session. Such intermediaries are not anticipated by the IMAP4
|
||||
protocol design and are not within the scope of the IMAP4 standard.
|
||||
However, in order for the ID command to be useful in the presence of
|
||||
such intermediaries, those intermediaries need to take special note
|
||||
of the ID command and response. In particular, if an intermediary
|
||||
changes any part of the IMAP session it must also change the ID
|
||||
command to advertise its presence.
|
||||
|
||||
A firewall MAY act to block transmission of specific information
|
||||
fields in the ID command and response that it believes reveal
|
||||
information that could expose a security vulnerability. However, a
|
||||
firewall SHOULD NOT disable the extension, when present, entirely,
|
||||
and SHOULD NOT unconditionally remove either the client or server
|
||||
list.
|
||||
|
||||
Finally, it should be noted that a firewall, when handling a
|
||||
CAPABILITY response, MUST NOT allow the names of extensions to be
|
||||
returned to the client that the firewall has no knowledge of.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Showalter Standards Track [Page 5]
|
||||
|
||||
RFC 2971 IMAP4 ID extension October 2000
|
||||
|
||||
|
||||
6. References
|
||||
|
||||
[KEYWORDS] Bradner, S., "Key words for use in RFCs to Indicate
|
||||
Requirement Levels", RFC 2119, March 1997.
|
||||
|
||||
[IMAP4rev1] Crispin, M., "Internet Message Access Protocol - Version
|
||||
4rev1", RFC 2060, October 1996.
|
||||
|
||||
[RFC-822] Crocker, D., "Standard for the Format of ARPA Internet
|
||||
Text Messages", STD 11, RFC 822, August 1982.
|
||||
|
||||
7. Security Considerations
|
||||
|
||||
This extension has the danger of violating the privacy of users if
|
||||
misused. Clients and servers should notify users that they implement
|
||||
and enable the ID command.
|
||||
|
||||
It is highly desirable that implementations provide a method of
|
||||
disabling ID support, perhaps by not sending ID at all, or by sending
|
||||
NIL as the argument to the ID command or response.
|
||||
|
||||
Implementors must exercise extreme care in adding fields sent as part
|
||||
of an ID command or response. Some fields, including a processor ID
|
||||
number, Ethernet address, or other unique (or mostly unique)
|
||||
identifier allow tracking of users in ways that violate user privacy
|
||||
expectations.
|
||||
|
||||
Having implementation information of a given client or server may
|
||||
make it easier for an attacker to gain unauthorized access due to
|
||||
security holes.
|
||||
|
||||
Since this command includes arbitrary data and does not require the
|
||||
user to authenticate, server implementations are cautioned to guard
|
||||
against an attacker sending arbitrary garbage data in order to fill
|
||||
up the ID log. In particular, if a server naively logs each ID
|
||||
command to disk without inspecting it, an attacker can simply fire up
|
||||
thousands of connections and send a few kilobytes of random data.
|
||||
Servers have to guard against this. Methods include truncating
|
||||
abnormally large responses; collating responses by storing only a
|
||||
single copy, then keeping a counter of the number of times that
|
||||
response has been seen; keeping only particularly interesting parts
|
||||
of responses; and only logging responses of users who actually log
|
||||
in.
|
||||
|
||||
Security is affected by firewalls which modify the IMAP protocol
|
||||
stream; see section 5, Use of the ID Extension with Firewalls and
|
||||
Other Intermediaries, for more information.
|
||||
|
||||
|
||||
|
||||
|
||||
Showalter Standards Track [Page 6]
|
||||
|
||||
RFC 2971 IMAP4 ID extension October 2000
|
||||
|
||||
|
||||
8. Author's Address
|
||||
|
||||
Tim Showalter
|
||||
Mirapoint, Inc.
|
||||
909 Hermosa Ct.
|
||||
Sunnyvale, CA 94095
|
||||
|
||||
EMail: tjs@mirapoint.com
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Showalter Standards Track [Page 7]
|
||||
|
||||
RFC 2971 IMAP4 ID extension October 2000
|
||||
|
||||
|
||||
9. Full Copyright Statement
|
||||
|
||||
Copyright (C) The Internet Society (2000). All Rights Reserved.
|
||||
|
||||
This document and translations of it may be copied and furnished to
|
||||
others, and derivative works that comment on or otherwise explain it
|
||||
or assist in its implementation may be prepared, copied, published
|
||||
and distributed, in whole or in part, without restriction of any
|
||||
kind, provided that the above copyright notice and this paragraph are
|
||||
included on all such copies and derivative works. However, this
|
||||
document itself may not be modified in any way, such as by removing
|
||||
the copyright notice or references to the Internet Society or other
|
||||
Internet organizations, except as needed for the purpose of
|
||||
developing Internet standards in which case the procedures for
|
||||
copyrights defined in the Internet Standards process must be
|
||||
followed, or as required to translate it into languages other than
|
||||
English.
|
||||
|
||||
The limited permissions granted above are perpetual and will not be
|
||||
revoked by the Internet Society or its successors or assigns.
|
||||
|
||||
This document and the information contained herein is provided on an
|
||||
"AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
|
||||
TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
|
||||
HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
Acknowledgement
|
||||
|
||||
Funding for the RFC Editor function is currently provided by the
|
||||
Internet Society.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Showalter Standards Track [Page 8]
|
||||
|
||||
6051
vendor/github.com/mattermost/rsc/imap/rfc3501.txt
сгенерированный
поставляемый
6051
vendor/github.com/mattermost/rsc/imap/rfc3501.txt
сгенерированный
поставляемый
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
350
vendor/github.com/mattermost/rsc/imap/sx.go
сгенерированный
поставляемый
350
vendor/github.com/mattermost/rsc/imap/sx.go
сгенерированный
поставляемый
@@ -1,350 +0,0 @@
|
||||
package imap
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type sxKind int
|
||||
|
||||
const (
|
||||
sxNone sxKind = iota
|
||||
sxAtom
|
||||
sxString
|
||||
sxNumber
|
||||
sxList
|
||||
)
|
||||
|
||||
type sx struct {
|
||||
kind sxKind
|
||||
data []byte
|
||||
number int64
|
||||
sx []*sx
|
||||
}
|
||||
|
||||
func rdsx(b *bufio.Reader) (*sx, error) {
|
||||
x := &sx{kind: sxList}
|
||||
for {
|
||||
xx, err := rdsx1(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if xx == nil {
|
||||
break
|
||||
}
|
||||
x.sx = append(x.sx, xx)
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
func rdsx1(b *bufio.Reader) (*sx, error) {
|
||||
c, err := b.ReadByte()
|
||||
if c == ' ' {
|
||||
c, err = b.ReadByte()
|
||||
}
|
||||
if c == '\r' {
|
||||
c, err = b.ReadByte()
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c == '\n' {
|
||||
return nil, nil
|
||||
}
|
||||
if c == ')' { // end of list
|
||||
b.UnreadByte()
|
||||
return nil, nil
|
||||
}
|
||||
if c == '(' { // parenthesized list
|
||||
x, err := rdsx(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c, err = b.ReadByte()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c != ')' {
|
||||
// oops! not good
|
||||
b.UnreadByte()
|
||||
}
|
||||
return x, nil
|
||||
}
|
||||
if c == '{' { // length-prefixed string
|
||||
n := 0
|
||||
for {
|
||||
c, _ = b.ReadByte()
|
||||
if c < '0' || c > '9' {
|
||||
break
|
||||
}
|
||||
n = n*10 + int(c) - '0'
|
||||
}
|
||||
if c != '}' {
|
||||
// oops! not good
|
||||
b.UnreadByte()
|
||||
}
|
||||
c, err = b.ReadByte()
|
||||
if c != '\r' {
|
||||
// oops! not good
|
||||
}
|
||||
c, err = b.ReadByte()
|
||||
if c != '\n' {
|
||||
// oops! not good
|
||||
}
|
||||
data := make([]byte, n)
|
||||
if _, err := io.ReadFull(b, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &sx{kind: sxString, data: data}, nil
|
||||
}
|
||||
if c == '"' { // quoted string
|
||||
var data []byte
|
||||
for {
|
||||
c, err = b.ReadByte()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c == '"' {
|
||||
break
|
||||
}
|
||||
if c == '\\' {
|
||||
c, _ = b.ReadByte()
|
||||
}
|
||||
data = append(data, c)
|
||||
}
|
||||
return &sx{kind: sxString, data: data}, nil
|
||||
}
|
||||
if '0' <= c && c <= '9' { // number
|
||||
n := int64(c) - '0'
|
||||
for {
|
||||
c, err := b.ReadByte()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c < '0' || c > '9' {
|
||||
break
|
||||
}
|
||||
n = n*10 + int64(c) - '0'
|
||||
}
|
||||
b.UnreadByte()
|
||||
return &sx{kind: sxNumber, number: n}, nil
|
||||
}
|
||||
|
||||
// atom
|
||||
nbr := 0
|
||||
var data []byte
|
||||
data = append(data, c)
|
||||
for {
|
||||
c, err = b.ReadByte()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c <= ' ' || c == '(' || c == ')' || c == '{' || c == '}' {
|
||||
break
|
||||
}
|
||||
if c == '[' {
|
||||
// allow embedded brackets as in BODY[]
|
||||
if data[0] == '[' {
|
||||
break
|
||||
}
|
||||
nbr++
|
||||
}
|
||||
if c == ']' {
|
||||
if nbr <= 0 {
|
||||
break
|
||||
}
|
||||
nbr--
|
||||
}
|
||||
data = append(data, c)
|
||||
}
|
||||
if c != ' ' {
|
||||
b.UnreadByte()
|
||||
}
|
||||
return &sx{kind: sxAtom, data: data}, nil
|
||||
}
|
||||
|
||||
func (x *sx) ok() bool {
|
||||
return len(x.sx) >= 2 && x.sx[1].kind == sxAtom && strings.EqualFold(string(x.sx[1].data), "ok")
|
||||
}
|
||||
|
||||
func (x *sx) String() string {
|
||||
var b bytes.Buffer
|
||||
x.fmt(&b, true)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (x *sx) fmt(b *bytes.Buffer, paren bool) {
|
||||
if x == nil {
|
||||
return
|
||||
}
|
||||
switch x.kind {
|
||||
case sxAtom, sxString:
|
||||
fmt.Fprintf(b, "%q", x.data)
|
||||
case sxNumber:
|
||||
fmt.Fprintf(b, "%d", x.number)
|
||||
case sxList:
|
||||
if paren {
|
||||
b.WriteByte('(')
|
||||
}
|
||||
for i, xx := range x.sx {
|
||||
if i > 0 {
|
||||
b.WriteByte(' ')
|
||||
}
|
||||
xx.fmt(b, paren)
|
||||
}
|
||||
if paren {
|
||||
b.WriteByte(')')
|
||||
}
|
||||
default:
|
||||
b.WriteByte('?')
|
||||
}
|
||||
}
|
||||
|
||||
var bytesNIL = []byte("NIL")
|
||||
|
||||
var fmtKind = []sxKind{
|
||||
'L': sxList,
|
||||
'S': sxString,
|
||||
'N': sxNumber,
|
||||
'A': sxAtom,
|
||||
}
|
||||
|
||||
func (x *sx) match(format string) bool {
|
||||
done := false
|
||||
c := format[0]
|
||||
for i := 0; i < len(x.sx); i++ {
|
||||
if !done {
|
||||
if i >= len(format) {
|
||||
log.Printf("sxmatch: too short")
|
||||
return false
|
||||
}
|
||||
if format[i] == '*' {
|
||||
done = true
|
||||
} else {
|
||||
c = format[i]
|
||||
}
|
||||
}
|
||||
xx := x.sx[i]
|
||||
if xx.kind == sxAtom && xx.isNil() {
|
||||
if c == 'L' {
|
||||
xx.kind = sxList
|
||||
xx.data = nil
|
||||
} else if c == 'S' {
|
||||
xx.kind = sxString
|
||||
xx.data = nil
|
||||
}
|
||||
}
|
||||
if xx.kind == sxAtom && c == 'S' {
|
||||
xx.kind = sxString
|
||||
}
|
||||
if xx.kind != fmtKind[c] {
|
||||
log.Printf("sxmatch: %s not %c", xx, c)
|
||||
return false
|
||||
}
|
||||
}
|
||||
if len(format) > len(x.sx) {
|
||||
log.Printf("sxmatch: too long")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (x *sx) isAtom(name string) bool {
|
||||
if x == nil || x.kind != sxAtom {
|
||||
return false
|
||||
}
|
||||
data := x.data
|
||||
n := len(name)
|
||||
if n > 0 && name[n-1] == '[' {
|
||||
i := bytes.IndexByte(data, '[')
|
||||
if i < 0 {
|
||||
return false
|
||||
}
|
||||
data = data[:i]
|
||||
name = name[:n-1]
|
||||
}
|
||||
for i := 0; i < len(name); i++ {
|
||||
if i >= len(data) || lwr(rune(data[i])) != lwr(rune(name[i])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return len(name) == len(data)
|
||||
}
|
||||
|
||||
func (x *sx) isString() bool {
|
||||
if x.isNil() {
|
||||
return true
|
||||
}
|
||||
if x.kind == sxAtom {
|
||||
x.kind = sxString
|
||||
}
|
||||
return x.kind == sxString
|
||||
}
|
||||
|
||||
func (x *sx) isNumber() bool {
|
||||
return x.kind == sxNumber
|
||||
}
|
||||
|
||||
func (x *sx) isNil() bool {
|
||||
return x == nil ||
|
||||
x.kind == sxList && len(x.sx) == 0 ||
|
||||
x.kind == sxAtom && bytes.Equal(x.data, bytesNIL)
|
||||
}
|
||||
|
||||
func (x *sx) isList() bool {
|
||||
return x.isNil() || x.kind == sxList
|
||||
}
|
||||
|
||||
func (x *sx) parseFlags() Flags {
|
||||
if x.kind != sxList {
|
||||
log.Printf("malformed flags: %s", x)
|
||||
return 0
|
||||
}
|
||||
|
||||
f := Flags(0)
|
||||
SX:
|
||||
for _, xx := range x.sx {
|
||||
if xx.kind != sxAtom {
|
||||
continue
|
||||
}
|
||||
for i, name := range flagNames {
|
||||
if xx.isAtom(name) {
|
||||
f |= 1 << uint(i)
|
||||
continue SX
|
||||
}
|
||||
}
|
||||
if Debug {
|
||||
log.Printf("unknown flag: %v", xx)
|
||||
}
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func (x *sx) parseDate() time.Time {
|
||||
if x.kind != sxString {
|
||||
log.Printf("malformed date: %s", x)
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
t, err := time.Parse("02-Jan-2006 15:04:05 -0700", string(x.data))
|
||||
if err != nil {
|
||||
log.Printf("malformed date: %s (%s)", x, err)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (x *sx) nstring() string {
|
||||
return string(x.nbytes())
|
||||
}
|
||||
|
||||
func (x *sx) nbytes() []byte {
|
||||
if x.isNil() {
|
||||
return nil
|
||||
}
|
||||
return x.data
|
||||
}
|
||||
60
vendor/github.com/mattermost/rsc/imap/sx_test.go
сгенерированный
поставляемый
60
vendor/github.com/mattermost/rsc/imap/sx_test.go
сгенерированный
поставляемый
@@ -1,60 +0,0 @@
|
||||
package imap
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var sxTests = []struct {
|
||||
in string
|
||||
out *sx
|
||||
}{
|
||||
{"1234", &sx{kind: sxNumber, number: 1234}},
|
||||
{"hello", &sx{kind: sxAtom, data: []byte("hello")}},
|
||||
{"hello[world]", &sx{kind: sxAtom, data: []byte("hello[world]")}},
|
||||
{`"h\\ello"`, &sx{kind: sxString, data: []byte(`h\ello`)}},
|
||||
{"{6}\r\nh\\ello", &sx{kind: sxString, data: []byte(`h\ello`)}},
|
||||
{`(hello "world" (again) ())`,
|
||||
&sx{
|
||||
kind: sxList,
|
||||
sx: []*sx{
|
||||
&sx{
|
||||
kind: sxAtom,
|
||||
data: []byte("hello"),
|
||||
},
|
||||
&sx{
|
||||
kind: sxString,
|
||||
data: []byte("world"),
|
||||
},
|
||||
&sx{
|
||||
kind: sxList,
|
||||
sx: []*sx{
|
||||
&sx{
|
||||
kind: sxAtom,
|
||||
data: []byte("again"),
|
||||
},
|
||||
},
|
||||
},
|
||||
&sx{
|
||||
kind: sxList,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestSx(t *testing.T) {
|
||||
for _, tt := range sxTests {
|
||||
b := bufio.NewReader(strings.NewReader(tt.in + "\n"))
|
||||
sx, err := rdsx1(b)
|
||||
if err != nil {
|
||||
t.Errorf("parse %s: %v", tt.in, err)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(sx, tt.out) {
|
||||
t.Errorf("rdsx1(%s) = %v, want %v", tt.in, sx, tt.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
602
vendor/github.com/mattermost/rsc/imap/tcs.go
сгенерированный
поставляемый
602
vendor/github.com/mattermost/rsc/imap/tcs.go
сгенерированный
поставляемый
@@ -1,602 +0,0 @@
|
||||
package imap
|
||||
|
||||
// NOTE(rsc): These belong elsewhere but the existing charset
|
||||
// packages seem too complicated.
|
||||
|
||||
var tab_iso8859_1 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
}
|
||||
|
||||
var tab_iso8859_2 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, 0x0104, 0x02d8, 0x0141, 0x00a4, 0x013d, 0x015a, 0x00a7,
|
||||
0x00a8, 0x0160, 0x015e, 0x0164, 0x0179, 0x00ad, 0x017d, 0x017b,
|
||||
0x00b0, 0x0105, 0x02db, 0x0142, 0x00b4, 0x013e, 0x015b, 0x02c7,
|
||||
0x00b8, 0x0161, 0x015f, 0x0165, 0x017a, 0x02dd, 0x017e, 0x017c,
|
||||
0x0154, 0x00c1, 0x00c2, 0x0102, 0x00c4, 0x0139, 0x0106, 0x00c7,
|
||||
0x010c, 0x00c9, 0x0118, 0x00cb, 0x011a, 0x00cd, 0x00ce, 0x010e,
|
||||
0x0110, 0x0143, 0x0147, 0x00d3, 0x00d4, 0x0150, 0x00d6, 0x00d7,
|
||||
0x0158, 0x016e, 0x00da, 0x0170, 0x00dc, 0x00dd, 0x0162, 0x00df,
|
||||
0x0155, 0x00e1, 0x00e2, 0x0103, 0x00e4, 0x013a, 0x0107, 0x00e7,
|
||||
0x010d, 0x00e9, 0x0119, 0x00eb, 0x011b, 0x00ed, 0x00ee, 0x010f,
|
||||
0x0111, 0x0144, 0x0148, 0x00f3, 0x00f4, 0x0151, 0x00f6, 0x00f7,
|
||||
0x0159, 0x016f, 0x00fa, 0x0171, 0x00fc, 0x00fd, 0x0163, 0x02d9,
|
||||
}
|
||||
|
||||
var tab_iso8859_3 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, 0x0126, 0x02d8, 0x00a3, 0x00a4, -1, 0x0124, 0x00a7,
|
||||
0x00a8, 0x0130, 0x015e, 0x011e, 0x0134, 0x00ad, -1, 0x017b,
|
||||
0x00b0, 0x0127, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x0125, 0x00b7,
|
||||
0x00b8, 0x0131, 0x015f, 0x011f, 0x0135, 0x00bd, -1, 0x017c,
|
||||
0x00c0, 0x00c1, 0x00c2, -1, 0x00c4, 0x010a, 0x0108, 0x00c7,
|
||||
0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
|
||||
-1, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x0120, 0x00d6, 0x00d7,
|
||||
0x011c, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x016c, 0x015c, 0x00df,
|
||||
0x00e0, 0x00e1, 0x00e2, -1, 0x00e4, 0x010b, 0x0109, 0x00e7,
|
||||
0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
|
||||
-1, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x0121, 0x00f6, 0x00f7,
|
||||
0x011d, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x016d, 0x015d, 0x02d9,
|
||||
}
|
||||
|
||||
var tab_iso8859_4 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, 0x0104, 0x0138, 0x0156, 0x00a4, 0x0128, 0x013b, 0x00a7,
|
||||
0x00a8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00ad, 0x017d, 0x00af,
|
||||
0x00b0, 0x0105, 0x02db, 0x0157, 0x00b4, 0x0129, 0x013c, 0x02c7,
|
||||
0x00b8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014a, 0x017e, 0x014b,
|
||||
0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e,
|
||||
0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x012a,
|
||||
0x0110, 0x0145, 0x014c, 0x0136, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
|
||||
0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x0168, 0x016a, 0x00df,
|
||||
0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f,
|
||||
0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x012b,
|
||||
0x0111, 0x0146, 0x014d, 0x0137, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
|
||||
0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x0169, 0x016b, 0x02d9,
|
||||
}
|
||||
|
||||
var tab_iso8859_5 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407,
|
||||
0x0408, 0x0409, 0x040a, 0x040b, 0x040c, 0x00ad, 0x040e, 0x040f,
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
|
||||
0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
|
||||
0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
|
||||
0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
|
||||
0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f,
|
||||
0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457,
|
||||
0x0458, 0x0459, 0x045a, 0x045b, 0x045c, 0x00a7, 0x045e, 0x045f,
|
||||
}
|
||||
|
||||
var tab_iso8859_6 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, -1, -1, -1, 0x00a4, -1, -1, -1,
|
||||
-1, -1, -1, -1, 0x060c, 0x00ad, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 0x061b, -1, -1, -1, 0x061f,
|
||||
-1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
|
||||
0x0628, 0x0629, 0x062a, 0x062b, 0x062c, 0x062d, 0x062e, 0x062f,
|
||||
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637,
|
||||
0x0638, 0x0639, 0x063a, -1, -1, -1, -1, -1,
|
||||
0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647,
|
||||
0x0648, 0x0649, 0x064a, 0x064b, 0x064c, 0x064d, 0x064e, 0x064f,
|
||||
0x0650, 0x0651, 0x0652, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
}
|
||||
|
||||
var tab_iso8859_7 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, 0x2018, 0x2019, 0x00a3, -1, -1, 0x00a6, 0x00a7,
|
||||
0x00a8, 0x00a9, -1, 0x00ab, 0x00ac, 0x00ad, -1, 0x2015,
|
||||
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x0384, 0x0385, 0x0386, 0x00b7,
|
||||
0x0388, 0x0389, 0x038a, 0x00bb, 0x038c, 0x00bd, 0x038e, 0x038f,
|
||||
0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
|
||||
0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f,
|
||||
0x03a0, 0x03a1, -1, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7,
|
||||
0x03a8, 0x03a9, 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03ae, 0x03af,
|
||||
0x03b0, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7,
|
||||
0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
|
||||
0x03c0, 0x03c1, 0x03c2, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7,
|
||||
0x03c8, 0x03c9, 0x03ca, 0x03cb, 0x03cc, 0x03cd, 0x03ce, -1,
|
||||
}
|
||||
|
||||
var tab_iso8859_8 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, -1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
|
||||
0x00a8, 0x00a9, 0x00d7, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x203e,
|
||||
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
|
||||
0x00b8, 0x00b9, 0x00f7, 0x00bb, 0x00bc, 0x00bd, 0x00be, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 0x2017,
|
||||
0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7,
|
||||
0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df,
|
||||
0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7,
|
||||
0x05e8, 0x05e9, 0x05ea, -1, -1, -1, -1, -1,
|
||||
}
|
||||
|
||||
var tab_iso8859_9 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
|
||||
0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
|
||||
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7,
|
||||
0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
|
||||
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7,
|
||||
0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
|
||||
0x011e, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7,
|
||||
0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x0130, 0x015e, 0x00df,
|
||||
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7,
|
||||
0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
|
||||
0x011f, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7,
|
||||
0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x0131, 0x015f, 0x00ff,
|
||||
}
|
||||
|
||||
var tab_iso8859_10 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0x00a0, 0x0104, 0x0112, 0x0122, 0x012a, 0x0128, 0x0136, 0x00a7,
|
||||
0x013b, 0x0110, 0x0160, 0x0166, 0x017d, 0x00ad, 0x016a, 0x014a,
|
||||
0x00b0, 0x0105, 0x0113, 0x0123, 0x012b, 0x0129, 0x0137, 0x00b7,
|
||||
0x013c, 0x0110, 0x0161, 0x0167, 0x017e, 0x2014, 0x016b, 0x014b,
|
||||
0x0100, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x012e,
|
||||
0x010c, 0x00c9, 0x0118, 0x00cb, 0x0116, 0x00cd, 0x00ce, 0x00cf,
|
||||
0x00d0, 0x0145, 0x014c, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x0168,
|
||||
0x00d8, 0x0172, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
|
||||
0x0101, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x012f,
|
||||
0x010d, 0x00e9, 0x0119, 0x00eb, 0x0117, 0x00ed, 0x00ee, 0x00ef,
|
||||
0x00f0, 0x0146, 0x014d, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x0169,
|
||||
0x00f8, 0x0173, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x0138,
|
||||
}
|
||||
|
||||
var tab_iso8859_15 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0x20ac, 0xa5, 0x0160, 0xa7, 0x0161, 0xa9, 0xaa, 0xab, 0xac, 0xad,
|
||||
0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0x017d, 0xb5, 0xb6, 0xb7, 0x017e, 0xb9, 0xba, 0xbb,
|
||||
0x0152, 0x0153, 0x0178, 0xbf, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
|
||||
0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
|
||||
0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
|
||||
0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
}
|
||||
|
||||
var tab_koi8 = [256]rune{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
0x044e, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433,
|
||||
0x0445, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e,
|
||||
0x043f, 0x044f, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432,
|
||||
0x044c, 0x044b, 0x0437, 0x0448, 0x044d, 0x0449, 0x0447, 0x044a,
|
||||
0x042e, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413,
|
||||
0x0425, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e,
|
||||
0x041f, 0x042f, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412,
|
||||
0x042c, 0x042b, 0x0417, 0x0428, 0x042d, 0x0429, 0x0427, 0x042a,
|
||||
}
|
||||
|
||||
var tab_cp1250 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x20AC, -1, 0x201A, -1, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
-1, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
|
||||
-1, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
-1, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A,
|
||||
0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B,
|
||||
0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C,
|
||||
0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
|
||||
0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
|
||||
0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
|
||||
0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
|
||||
0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
|
||||
0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
|
||||
0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
|
||||
0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9,
|
||||
}
|
||||
var tab_cp1251 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
|
||||
0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
-1, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
|
||||
0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
|
||||
0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
|
||||
0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457,
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
|
||||
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
|
||||
0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
|
||||
0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
|
||||
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
|
||||
}
|
||||
var tab_cp1252 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x20AC, -1, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, -1, 0x017D, -1,
|
||||
-1, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, -1, 0x017E, 0x0178,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF,
|
||||
}
|
||||
var tab_cp1253 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x20AC, -1, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
-1, 0x2030, -1, 0x2039, -1, -1, -1, -1,
|
||||
-1, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
-1, 0x2122, -1, 0x203A, -1, -1, -1, -1,
|
||||
0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, -1, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
|
||||
0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
|
||||
0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
|
||||
0x03A0, 0x03A1, -1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
|
||||
0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
|
||||
0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
|
||||
0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
|
||||
0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
|
||||
0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, -1,
|
||||
}
|
||||
var tab_cp1254 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x20AC, -1, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, -1, -1, -1,
|
||||
-1, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, -1, -1, 0x0178,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0130, 0x015E, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF,
|
||||
}
|
||||
var tab_cp1255 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x20AC, -1, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, -1, 0x2039, -1, -1, -1, -1,
|
||||
-1, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x02DC, 0x2122, -1, 0x203A, -1, -1, -1, -1,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
|
||||
0x05B8, 0x05B9, -1, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
|
||||
0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
|
||||
0x05F4, -1, -1, -1, -1, -1, -1, -1,
|
||||
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
|
||||
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
|
||||
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
|
||||
0x05E8, 0x05E9, 0x05EA, -1, -1, 0x200E, 0x200F, -1,
|
||||
}
|
||||
var tab_cp1256 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
|
||||
0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,
|
||||
0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,
|
||||
0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
|
||||
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
|
||||
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,
|
||||
0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0641, 0x0642, 0x0643,
|
||||
0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
|
||||
0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
|
||||
0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2,
|
||||
}
|
||||
var tab_cp1257 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x20AC, -1, 0x201A, -1, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
-1, 0x2030, -1, 0x2039, -1, 0x00A8, 0x02C7, 0x00B8,
|
||||
-1, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
-1, 0x2122, -1, 0x203A, -1, 0x00AF, 0x02DB, -1,
|
||||
0x00A0, -1, 0x00A2, 0x00A3, 0x00A4, -1, 0x00A6, 0x00A7,
|
||||
0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00C6,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00F8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
|
||||
0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
|
||||
0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
|
||||
0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
|
||||
0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
|
||||
0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
|
||||
0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9,
|
||||
}
|
||||
var tab_cp1258 = [256]rune{
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
|
||||
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
|
||||
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
|
||||
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
|
||||
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
|
||||
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
|
||||
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
|
||||
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
|
||||
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F,
|
||||
0x20AC, -1, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
|
||||
0x02C6, 0x2030, -1, 0x2039, 0x0152, -1, -1, -1,
|
||||
-1, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
|
||||
0x02DC, 0x2122, -1, 0x203A, 0x0153, -1, -1, 0x0178,
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF,
|
||||
}
|
||||
28
vendor/github.com/mattermost/rsc/keychain/doc.go
сгенерированный
поставляемый
28
vendor/github.com/mattermost/rsc/keychain/doc.go
сгенерированный
поставляемый
@@ -1,28 +0,0 @@
|
||||
// Copyright 2012 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 keychain implements access to the passwords and other keys
|
||||
// stored in the system-provided keychain.
|
||||
package keychain
|
||||
|
||||
// BUG(rsc): Package keychain is only implemented on OS X.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// UserPasswd returns the user name and password for authenticating
|
||||
// to the named server. If the user argument is non-empty, UserPasswd
|
||||
// restricts its search to passwords for the named user.
|
||||
func UserPasswd(server, preferredUser string) (user, passwd string, err error) {
|
||||
user, passwd, err = userPasswd(server, preferredUser)
|
||||
if err != nil {
|
||||
if preferredUser != "" {
|
||||
err = fmt.Errorf("loading password for %s@%s: %v", preferredUser, server, err)
|
||||
} else {
|
||||
err = fmt.Errorf("loading password for %s: %v", server, err)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
107
vendor/github.com/mattermost/rsc/keychain/mac.go
сгенерированный
поставляемый
107
vendor/github.com/mattermost/rsc/keychain/mac.go
сгенерированный
поставляемый
@@ -1,107 +0,0 @@
|
||||
// Copyright 2012 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 keychain
|
||||
|
||||
/*
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <Security/Security.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
|
||||
#cgo LDFLAGS: -framework CoreFoundation -framework Security
|
||||
|
||||
static char*
|
||||
mac2c(CFStringRef s)
|
||||
{
|
||||
char *p;
|
||||
int n;
|
||||
|
||||
n = CFStringGetLength(s)*8;
|
||||
p = malloc(n);
|
||||
CFStringGetCString(s, p, n, kCFStringEncodingUTF8);
|
||||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
keychain_getpasswd(char *user0, char *server, char **user, char **passwd, char **error)
|
||||
{
|
||||
OSStatus st;
|
||||
UInt32 len;
|
||||
void *data;
|
||||
SecKeychainItemRef it;
|
||||
CFStringRef str;
|
||||
|
||||
*user = NULL;
|
||||
*passwd = NULL;
|
||||
*error = NULL;
|
||||
|
||||
st = SecKeychainFindInternetPassword(
|
||||
NULL, // default keychain
|
||||
strlen(server), server,
|
||||
0, NULL, // security domain
|
||||
strlen(user0), user0, // account name
|
||||
0, NULL, // path
|
||||
0, // port
|
||||
0, // protocol type
|
||||
kSecAuthenticationTypeDefault,
|
||||
&len,
|
||||
&data,
|
||||
&it);
|
||||
if(st != 0) {
|
||||
str = SecCopyErrorMessageString(st, NULL);
|
||||
*error = mac2c(str);
|
||||
CFRelease(str);
|
||||
return;
|
||||
}
|
||||
*passwd = malloc(len+1);
|
||||
memmove(*passwd, data, len);
|
||||
(*passwd)[len] = '\0';
|
||||
SecKeychainItemFreeContent(NULL, data);
|
||||
|
||||
SecKeychainAttribute attr = {kSecAccountItemAttr, 0, NULL};
|
||||
SecKeychainAttributeList attrl = {1, &attr};
|
||||
st = SecKeychainItemCopyContent(
|
||||
it,
|
||||
NULL,
|
||||
&attrl,
|
||||
0, NULL);
|
||||
if(st != 0) {
|
||||
str = SecCopyErrorMessageString(st, NULL);
|
||||
*error = mac2c(str);
|
||||
CFRelease(str);
|
||||
return;
|
||||
}
|
||||
data = attr.data;
|
||||
len = attr.length;
|
||||
*user = malloc(len+1);
|
||||
memmove(*user, data, len);
|
||||
(*user)[len] = '\0';
|
||||
SecKeychainItemFreeContent(&attrl, NULL);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func userPasswd(server, user string) (user1, passwd string, err error) {
|
||||
cServer := C.CString(server)
|
||||
cUser := C.CString(user)
|
||||
defer C.free(unsafe.Pointer(cServer))
|
||||
defer C.free(unsafe.Pointer(cUser))
|
||||
|
||||
var cPasswd, cError *C.char
|
||||
C.keychain_getpasswd(cUser, cServer, &cUser, &cPasswd, &cError)
|
||||
defer C.free(unsafe.Pointer(cUser))
|
||||
defer C.free(unsafe.Pointer(cPasswd))
|
||||
defer C.free(unsafe.Pointer(cError))
|
||||
|
||||
if cError != nil {
|
||||
return "", "", errors.New(C.GoString(cError))
|
||||
}
|
||||
|
||||
return C.GoString(cUser), C.GoString(cPasswd), nil
|
||||
}
|
||||
Двоичные данные
vendor/github.com/mattermost/rsc/mbta/Passages.pb
сгенерированный
поставляемый
Двоичные данные
vendor/github.com/mattermost/rsc/mbta/Passages.pb
сгенерированный
поставляемый
Двоичный файл не отображается.
Двоичные данные
vendor/github.com/mattermost/rsc/mbta/Vehicles.pb
сгенерированный
поставляемый
Двоичные данные
vendor/github.com/mattermost/rsc/mbta/Vehicles.pb
сгенерированный
поставляемый
Двоичный файл не отображается.
28
vendor/github.com/mattermost/rsc/mbta/mbta.go
сгенерированный
поставляемый
28
vendor/github.com/mattermost/rsc/mbta/mbta.go
сгенерированный
поставляемый
@@ -1,28 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"code.google.com/p/goprotobuf/proto"
|
||||
"github.com/mattermost/rsc/gtfs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
if len(os.Args) != 2 {
|
||||
log.Fatal("usage: mbta file.pb")
|
||||
}
|
||||
pb, err := ioutil.ReadFile(os.Args[1])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var feed gtfs.FeedMessage
|
||||
if err := proto.Unmarshal(pb, &feed); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
proto.MarshalText(os.Stdout, &feed)
|
||||
}
|
||||
51
vendor/github.com/mattermost/rsc/mkapp
сгенерированный
поставляемый
51
vendor/github.com/mattermost/rsc/mkapp
сгенерированный
поставляемый
@@ -1,51 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2012 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.
|
||||
|
||||
# Run this script in your app root directory, the one containing
|
||||
# the app.yaml file. Then point appcfg.py or dev_appserver.py
|
||||
# at './tmp' instead of '.'.
|
||||
#
|
||||
# It creates a symlink forest in a subdirectory named 'tmp' that
|
||||
# includes all the files from packages under your app root as
|
||||
# well as any packages from your $GOPATH that are needed by
|
||||
# the app packages. This makes deployment to App Engine
|
||||
# bring in just the packages you need, without manual chasing
|
||||
# of dependencies. Perhaps some day appcfg.py and dev_appserver.py
|
||||
# will work this way by default.
|
||||
|
||||
set -e
|
||||
rm -rf tmp
|
||||
dirs=$(find . -type d)
|
||||
mkdir tmp
|
||||
|
||||
for i in *
|
||||
do
|
||||
case "$i" in
|
||||
tmp | *.go)
|
||||
;;
|
||||
*)
|
||||
ln -s ../$i tmp/$i
|
||||
esac
|
||||
done
|
||||
|
||||
# Like App Engine
|
||||
export GOOS=linux
|
||||
export GOARCH=amd64
|
||||
|
||||
mkdir tmp/_go_top
|
||||
cp $(go list -f '{{range .GoFiles}}{{.}} {{end}}') tmp/_go_top
|
||||
|
||||
dirs=$(go list -e -f '{{if not .Standard}}{{.ImportPath}} {{end}}' $(go list -f '{{range .Deps}}{{.}} {{end}}' $dirs))
|
||||
for import in $dirs
|
||||
do
|
||||
case "$import" in
|
||||
appengine | appengine/*)
|
||||
;;
|
||||
*)
|
||||
mkdir -p tmp/$import
|
||||
files=$(go list -f '{{range .GoFiles}}{{$.Dir}}/{{.}} {{end}}' $import)
|
||||
ln -s $files tmp/$import 2>&1 | grep -v 'is a directory' || true # ignore subdirectory warnings
|
||||
esac
|
||||
done
|
||||
179
vendor/github.com/mattermost/rsc/plist/plist.go
сгенерированный
поставляемый
179
vendor/github.com/mattermost/rsc/plist/plist.go
сгенерированный
поставляемый
@@ -1,179 +0,0 @@
|
||||
// Copyright 2012 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 plist implements parsing of Apple plist files.
|
||||
package plist
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func next(data []byte) (skip, tag, rest []byte) {
|
||||
i := bytes.IndexByte(data, '<')
|
||||
if i < 0 {
|
||||
return data, nil, nil
|
||||
}
|
||||
j := bytes.IndexByte(data[i:], '>')
|
||||
if j < 0 {
|
||||
return data, nil, nil
|
||||
}
|
||||
j += i + 1
|
||||
return data[:i], data[i:j], data[j:]
|
||||
}
|
||||
|
||||
func Unmarshal(data []byte, v interface{}) error {
|
||||
_, tag, data := next(data)
|
||||
if !bytes.HasPrefix(tag, []byte("<plist")) {
|
||||
return fmt.Errorf("not a plist")
|
||||
}
|
||||
|
||||
data, err := unmarshalValue(data, reflect.ValueOf(v))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, tag, data = next(data)
|
||||
if !bytes.Equal(tag, []byte("</plist>")) {
|
||||
return fmt.Errorf("junk on end of plist")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalValue(data []byte, v reflect.Value) (rest []byte, err error) {
|
||||
_, tag, data := next(data)
|
||||
if tag == nil {
|
||||
return nil, fmt.Errorf("unexpected end of data")
|
||||
}
|
||||
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.IsNil() {
|
||||
v.Set(reflect.New(v.Type().Elem()))
|
||||
}
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
switch string(tag) {
|
||||
case "<dict>":
|
||||
t := v.Type()
|
||||
if v.Kind() != reflect.Struct {
|
||||
return nil, fmt.Errorf("cannot unmarshal <dict> into non-struct %s", v.Type())
|
||||
}
|
||||
Dict:
|
||||
for {
|
||||
_, tag, data = next(data)
|
||||
if len(tag) == 0 {
|
||||
return nil, fmt.Errorf("eof inside <dict>")
|
||||
}
|
||||
if string(tag) == "</dict>" {
|
||||
break
|
||||
}
|
||||
if string(tag) != "<key>" {
|
||||
return nil, fmt.Errorf("unexpected tag %s inside <dict>", tag)
|
||||
}
|
||||
var body []byte
|
||||
body, tag, data = next(data)
|
||||
if len(tag) == 0 {
|
||||
return nil, fmt.Errorf("eof inside <dict>")
|
||||
}
|
||||
if string(tag) != "</key>" {
|
||||
return nil, fmt.Errorf("unexpected tag %s inside <dict>", tag)
|
||||
}
|
||||
name := string(body)
|
||||
var i int
|
||||
for i = 0; i < t.NumField(); i++ {
|
||||
f := t.Field(i)
|
||||
if f.Name == name || f.Tag.Get("plist") == name {
|
||||
data, err = unmarshalValue(data, v.Field(i))
|
||||
continue Dict
|
||||
}
|
||||
}
|
||||
data, err = skipValue(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
|
||||
case "<array>":
|
||||
t := v.Type()
|
||||
if v.Kind() != reflect.Slice {
|
||||
return nil, fmt.Errorf("cannot unmarshal <array> into non-slice %s", v.Type())
|
||||
}
|
||||
for {
|
||||
_, tag, rest := next(data)
|
||||
if len(tag) == 0 {
|
||||
return nil, fmt.Errorf("eof inside <array>")
|
||||
}
|
||||
if string(tag) == "</array>" {
|
||||
data = rest
|
||||
break
|
||||
}
|
||||
elem := reflect.New(t.Elem()).Elem()
|
||||
data, err = unmarshalValue(data, elem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.Set(reflect.Append(v, elem))
|
||||
}
|
||||
return data, nil
|
||||
|
||||
case "<string>":
|
||||
if v.Kind() != reflect.String {
|
||||
return nil, fmt.Errorf("cannot unmarshal <string> into non-string %s", v.Type())
|
||||
}
|
||||
body, etag, data := next(data)
|
||||
if len(etag) == 0 {
|
||||
return nil, fmt.Errorf("eof inside <string>")
|
||||
}
|
||||
if string(etag) != "</string>" {
|
||||
return nil, fmt.Errorf("expected </string> but got %s", etag)
|
||||
}
|
||||
v.SetString(string(body)) // TODO: unescape
|
||||
return data, nil
|
||||
|
||||
case "<integer>":
|
||||
if v.Kind() != reflect.Int {
|
||||
return nil, fmt.Errorf("cannot unmarshal <integer> into non-int %s", v.Type())
|
||||
}
|
||||
body, etag, data := next(data)
|
||||
if len(etag) == 0 {
|
||||
return nil, fmt.Errorf("eof inside <integer>")
|
||||
}
|
||||
if string(etag) != "</integer>" {
|
||||
return nil, fmt.Errorf("expected </integer> but got %s", etag)
|
||||
}
|
||||
i, err := strconv.Atoi(string(body))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("non-integer in <integer> tag: %s", body)
|
||||
}
|
||||
v.SetInt(int64(i))
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected tag %s", tag)
|
||||
}
|
||||
|
||||
func skipValue(data []byte) (rest []byte, err error) {
|
||||
n := 0
|
||||
for {
|
||||
var tag []byte
|
||||
_, tag, data = next(data)
|
||||
if len(tag) == 0 {
|
||||
return nil, fmt.Errorf("unexpected eof")
|
||||
}
|
||||
if tag[1] == '/' {
|
||||
if n == 0 {
|
||||
return nil, fmt.Errorf("unexpected closing tag")
|
||||
}
|
||||
n--
|
||||
if n == 0 {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
n++
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
110
vendor/github.com/mattermost/rsc/plist/plist_test.go
сгенерированный
поставляемый
110
vendor/github.com/mattermost/rsc/plist/plist_test.go
сгенерированный
поставляемый
@@ -1,110 +0,0 @@
|
||||
// Copyright 2012 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 plist
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var thePlist = `<plist version="1.0">
|
||||
<dict>
|
||||
<key>BucketUUID</key>
|
||||
<string>C218A47D-DAFB-4476-9C67-597E556D7D8A</string>
|
||||
<key>BucketName</key>
|
||||
<string>rsc</string>
|
||||
<key>ComputerUUID</key>
|
||||
<string>E7859547-BB9C-41C0-871E-858A0526BAE7</string>
|
||||
<key>LocalPath</key>
|
||||
<string>/Users/rsc</string>
|
||||
<key>LocalMountPoint</key>
|
||||
<string>/Users</string>
|
||||
<key>IgnoredRelativePaths</key>
|
||||
<array>
|
||||
<string>/.Trash</string>
|
||||
<string>/go/pkg</string>
|
||||
<string>/go1/pkg</string>
|
||||
<string>/Library/Caches</string>
|
||||
</array>
|
||||
<key>Excludes</key>
|
||||
<dict>
|
||||
<key>excludes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>type</key>
|
||||
<integer>2</integer>
|
||||
<key>text</key>
|
||||
<string>.unison.</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
`
|
||||
|
||||
var plistTests = []struct {
|
||||
in string
|
||||
out interface{}
|
||||
}{
|
||||
{
|
||||
thePlist,
|
||||
&MyStruct{
|
||||
BucketUUID: "C218A47D-DAFB-4476-9C67-597E556D7D8A",
|
||||
BucketName: "rsc",
|
||||
ComputerUUID: "E7859547-BB9C-41C0-871E-858A0526BAE7",
|
||||
LocalPath: "/Users/rsc",
|
||||
LocalMountPoint: "/Users",
|
||||
IgnoredRelativePaths: []string{
|
||||
"/.Trash",
|
||||
"/go/pkg",
|
||||
"/go1/pkg",
|
||||
"/Library/Caches",
|
||||
},
|
||||
Excludes: Exclude1{
|
||||
Excludes: []Exclude2{
|
||||
{Type: 2,
|
||||
Text: ".unison.",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
thePlist,
|
||||
&struct{}{},
|
||||
},
|
||||
}
|
||||
|
||||
type MyStruct struct {
|
||||
BucketUUID string
|
||||
BucketName string
|
||||
ComputerUUID string
|
||||
LocalPath string
|
||||
LocalMountPoint string
|
||||
IgnoredRelativePaths []string
|
||||
Excludes Exclude1
|
||||
}
|
||||
|
||||
type Exclude1 struct {
|
||||
Excludes []Exclude2 `plist:"excludes"`
|
||||
}
|
||||
|
||||
type Exclude2 struct {
|
||||
Type int `plist:"type"`
|
||||
Text string `plist:"text"`
|
||||
}
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
for _, tt := range plistTests {
|
||||
v := reflect.New(reflect.ValueOf(tt.out).Type().Elem()).Interface()
|
||||
if err := Unmarshal([]byte(tt.in), v); err != nil {
|
||||
t.Errorf("%s", err)
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(tt.out, v) {
|
||||
t.Errorf("unmarshal not equal")
|
||||
}
|
||||
}
|
||||
}
|
||||
133
vendor/github.com/mattermost/rsc/qr/coding/qr_test.go
сгенерированный
поставляемый
133
vendor/github.com/mattermost/rsc/qr/coding/qr_test.go
сгенерированный
поставляемый
@@ -1,133 +0,0 @@
|
||||
// Copyright 2011 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 coding
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/rsc/gf256"
|
||||
"github.com/mattermost/rsc/qr/libqrencode"
|
||||
)
|
||||
|
||||
func test(t *testing.T, v Version, l Level, text ...Encoding) bool {
|
||||
s := ""
|
||||
ty := libqrencode.EightBit
|
||||
switch x := text[0].(type) {
|
||||
case String:
|
||||
s = string(x)
|
||||
case Alpha:
|
||||
s = string(x)
|
||||
ty = libqrencode.Alphanumeric
|
||||
case Num:
|
||||
s = string(x)
|
||||
ty = libqrencode.Numeric
|
||||
}
|
||||
key, err := libqrencode.Encode(libqrencode.Version(v), libqrencode.Level(l), ty, s)
|
||||
if err != nil {
|
||||
t.Errorf("libqrencode.Encode(%v, %v, %d, %#q): %v", v, l, ty, s, err)
|
||||
return false
|
||||
}
|
||||
mask := (^key.Pixel[8][2]&1)<<2 | (key.Pixel[8][3]&1)<<1 | (^key.Pixel[8][4] & 1)
|
||||
p, err := NewPlan(v, l, Mask(mask))
|
||||
if err != nil {
|
||||
t.Errorf("NewPlan(%v, L, %d): %v", v, err, mask)
|
||||
return false
|
||||
}
|
||||
if len(p.Pixel) != len(key.Pixel) {
|
||||
t.Errorf("%v: NewPlan uses %dx%d, libqrencode uses %dx%d", v, len(p.Pixel), len(p.Pixel), len(key.Pixel), len(key.Pixel))
|
||||
return false
|
||||
}
|
||||
c, err := p.Encode(text...)
|
||||
if err != nil {
|
||||
t.Errorf("Encode: %v", err)
|
||||
return false
|
||||
}
|
||||
badpix := 0
|
||||
Pixel:
|
||||
for y, prow := range p.Pixel {
|
||||
for x, pix := range prow {
|
||||
pix &^= Black
|
||||
if c.Black(x, y) {
|
||||
pix |= Black
|
||||
}
|
||||
|
||||
keypix := key.Pixel[y][x]
|
||||
want := Pixel(0)
|
||||
switch {
|
||||
case keypix&libqrencode.Finder != 0:
|
||||
want = Position.Pixel()
|
||||
case keypix&libqrencode.Alignment != 0:
|
||||
want = Alignment.Pixel()
|
||||
case keypix&libqrencode.Timing != 0:
|
||||
want = Timing.Pixel()
|
||||
case keypix&libqrencode.Format != 0:
|
||||
want = Format.Pixel()
|
||||
want |= OffsetPixel(pix.Offset()) // sic
|
||||
want |= pix & Invert
|
||||
case keypix&libqrencode.PVersion != 0:
|
||||
want = PVersion.Pixel()
|
||||
case keypix&libqrencode.DataECC != 0:
|
||||
if pix.Role() == Check || pix.Role() == Extra {
|
||||
want = pix.Role().Pixel()
|
||||
} else {
|
||||
want = Data.Pixel()
|
||||
}
|
||||
want |= OffsetPixel(pix.Offset())
|
||||
want |= pix & Invert
|
||||
default:
|
||||
want = Unused.Pixel()
|
||||
}
|
||||
if keypix&libqrencode.Black != 0 {
|
||||
want |= Black
|
||||
}
|
||||
if pix != want {
|
||||
t.Errorf("%v/%v: Pixel[%d][%d] = %v, want %v %#x", v, mask, y, x, pix, want, keypix)
|
||||
if badpix++; badpix >= 100 {
|
||||
t.Errorf("stopping after %d bad pixels", badpix)
|
||||
break Pixel
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return badpix == 0
|
||||
}
|
||||
|
||||
var input = []Encoding{
|
||||
String("hello"),
|
||||
Num("1"),
|
||||
Num("12"),
|
||||
Num("123"),
|
||||
Alpha("AB"),
|
||||
Alpha("ABC"),
|
||||
}
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
badvers := 0
|
||||
Version:
|
||||
for v := Version(1); v <= 40; v++ {
|
||||
for l := L; l <= H; l++ {
|
||||
for _, in := range input {
|
||||
if !test(t, v, l, in) {
|
||||
if badvers++; badvers >= 10 {
|
||||
t.Errorf("stopping after %d bad versions", badvers)
|
||||
break Version
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncode(t *testing.T) {
|
||||
data := []byte{0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11}
|
||||
check := []byte{0xa5, 0x24, 0xd4, 0xc1, 0xed, 0x36, 0xc7, 0x87, 0x2c, 0x55}
|
||||
rs := gf256.NewRSEncoder(Field, len(check))
|
||||
out := make([]byte, len(check))
|
||||
rs.ECC(data, out)
|
||||
if !bytes.Equal(out, check) {
|
||||
t.Errorf("have %x want %x", out, check)
|
||||
}
|
||||
}
|
||||
4
vendor/github.com/mattermost/rsc/qr/libqrencode/Makefile
сгенерированный
поставляемый
4
vendor/github.com/mattermost/rsc/qr/libqrencode/Makefile
сгенерированный
поставляемый
@@ -1,4 +0,0 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
TARG=rsc.googlecode.com/hg/qr/libqrencode
|
||||
CGOFILES=qrencode.go
|
||||
include $(GOROOT)/src/Make.pkg
|
||||
149
vendor/github.com/mattermost/rsc/qr/libqrencode/qrencode.go
сгенерированный
поставляемый
149
vendor/github.com/mattermost/rsc/qr/libqrencode/qrencode.go
сгенерированный
поставляемый
@@ -1,149 +0,0 @@
|
||||
// Copyright 2011 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 libqrencode wraps the C libqrencode library.
|
||||
// The qr package (in this package's parent directory)
|
||||
// does not use any C wrapping. This code is here only
|
||||
// for use during that package's tests.
|
||||
package libqrencode
|
||||
|
||||
/*
|
||||
#cgo LDFLAGS: -lqrencode
|
||||
#include <qrencode.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type Version int
|
||||
|
||||
type Mode int
|
||||
|
||||
const (
|
||||
Numeric Mode = C.QR_MODE_NUM
|
||||
Alphanumeric Mode = C.QR_MODE_AN
|
||||
EightBit Mode = C.QR_MODE_8
|
||||
)
|
||||
|
||||
type Level int
|
||||
|
||||
const (
|
||||
L Level = C.QR_ECLEVEL_L
|
||||
M Level = C.QR_ECLEVEL_M
|
||||
Q Level = C.QR_ECLEVEL_Q
|
||||
H Level = C.QR_ECLEVEL_H
|
||||
)
|
||||
|
||||
type Pixel int
|
||||
|
||||
const (
|
||||
Black Pixel = 1 << iota
|
||||
DataECC
|
||||
Format
|
||||
PVersion
|
||||
Timing
|
||||
Alignment
|
||||
Finder
|
||||
NonData
|
||||
)
|
||||
|
||||
type Code struct {
|
||||
Version int
|
||||
Width int
|
||||
Pixel [][]Pixel
|
||||
Scale int
|
||||
}
|
||||
|
||||
func (*Code) ColorModel() color.Model {
|
||||
return color.RGBAModel
|
||||
}
|
||||
|
||||
func (c *Code) Bounds() image.Rectangle {
|
||||
d := (c.Width + 8) * c.Scale
|
||||
return image.Rect(0, 0, d, d)
|
||||
}
|
||||
|
||||
var (
|
||||
white color.Color = color.RGBA{0xFF, 0xFF, 0xFF, 0xFF}
|
||||
black color.Color = color.RGBA{0x00, 0x00, 0x00, 0xFF}
|
||||
blue color.Color = color.RGBA{0x00, 0x00, 0x80, 0xFF}
|
||||
red color.Color = color.RGBA{0xFF, 0x40, 0x40, 0xFF}
|
||||
yellow color.Color = color.RGBA{0xFF, 0xFF, 0x00, 0xFF}
|
||||
gray color.Color = color.RGBA{0x80, 0x80, 0x80, 0xFF}
|
||||
green color.Color = color.RGBA{0x22, 0x8B, 0x22, 0xFF}
|
||||
)
|
||||
|
||||
func (c *Code) At(x, y int) color.Color {
|
||||
x = x/c.Scale - 4
|
||||
y = y/c.Scale - 4
|
||||
if 0 <= x && x < c.Width && 0 <= y && y < c.Width {
|
||||
switch p := c.Pixel[y][x]; {
|
||||
case p&Black == 0:
|
||||
// nothing
|
||||
case p&DataECC != 0:
|
||||
return black
|
||||
case p&Format != 0:
|
||||
return blue
|
||||
case p&PVersion != 0:
|
||||
return red
|
||||
case p&Timing != 0:
|
||||
return yellow
|
||||
case p&Alignment != 0:
|
||||
return gray
|
||||
case p&Finder != 0:
|
||||
return green
|
||||
}
|
||||
}
|
||||
return white
|
||||
}
|
||||
|
||||
type Chunk struct {
|
||||
Mode Mode
|
||||
Text string
|
||||
}
|
||||
|
||||
func Encode(version Version, level Level, mode Mode, text string) (*Code, error) {
|
||||
return EncodeChunk(version, level, Chunk{mode, text})
|
||||
}
|
||||
|
||||
func EncodeChunk(version Version, level Level, chunk ...Chunk) (*Code, error) {
|
||||
qi, err := C.QRinput_new2(C.int(version), C.QRecLevel(level))
|
||||
if qi == nil {
|
||||
return nil, fmt.Errorf("QRinput_new2: %v", err)
|
||||
}
|
||||
defer C.QRinput_free(qi)
|
||||
for _, ch := range chunk {
|
||||
data := []byte(ch.Text)
|
||||
n, err := C.QRinput_append(qi, C.QRencodeMode(ch.Mode), C.int(len(data)), (*C.uchar)(&data[0]))
|
||||
if n < 0 {
|
||||
return nil, fmt.Errorf("QRinput_append %q: %v", data, err)
|
||||
}
|
||||
}
|
||||
|
||||
qc, err := C.QRcode_encodeInput(qi)
|
||||
if qc == nil {
|
||||
return nil, fmt.Errorf("QRinput_encodeInput: %v", err)
|
||||
}
|
||||
|
||||
c := &Code{
|
||||
Version: int(qc.version),
|
||||
Width: int(qc.width),
|
||||
Scale: 16,
|
||||
}
|
||||
pix := make([]Pixel, c.Width*c.Width)
|
||||
cdat := (*[1000 * 1000]byte)(unsafe.Pointer(qc.data))[:len(pix)]
|
||||
for i := range pix {
|
||||
pix[i] = Pixel(cdat[i])
|
||||
}
|
||||
c.Pixel = make([][]Pixel, c.Width)
|
||||
for i := range c.Pixel {
|
||||
c.Pixel[i] = pix[i*c.Width : (i+1)*c.Width]
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
73
vendor/github.com/mattermost/rsc/qr/png_test.go
сгенерированный
поставляемый
73
vendor/github.com/mattermost/rsc/qr/png_test.go
сгенерированный
поставляемый
@@ -1,73 +0,0 @@
|
||||
// Copyright 2011 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 qr
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPNG(t *testing.T) {
|
||||
c, err := Encode("hello, world", L)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
pngdat := c.PNG()
|
||||
if true {
|
||||
ioutil.WriteFile("x.png", pngdat, 0666)
|
||||
}
|
||||
m, err := png.Decode(bytes.NewBuffer(pngdat))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gm := m.(*image.Gray)
|
||||
|
||||
scale := c.Scale
|
||||
siz := c.Size
|
||||
nbad := 0
|
||||
for y := 0; y < scale*(8+siz); y++ {
|
||||
for x := 0; x < scale*(8+siz); x++ {
|
||||
v := byte(255)
|
||||
if c.Black(x/scale-4, y/scale-4) {
|
||||
v = 0
|
||||
}
|
||||
if gv := gm.At(x, y).(color.Gray).Y; gv != v {
|
||||
t.Errorf("%d,%d = %d, want %d", x, y, gv, v)
|
||||
if nbad++; nbad >= 20 {
|
||||
t.Fatalf("too many bad pixels")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPNG(b *testing.B) {
|
||||
c, err := Encode("0123456789012345678901234567890123456789", L)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var bytes []byte
|
||||
for i := 0; i < b.N; i++ {
|
||||
bytes = c.PNG()
|
||||
}
|
||||
b.SetBytes(int64(len(bytes)))
|
||||
}
|
||||
|
||||
func BenchmarkImagePNG(b *testing.B) {
|
||||
c, err := Encode("0123456789012345678901234567890123456789", L)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf.Reset()
|
||||
png.Encode(&buf, c.Image())
|
||||
}
|
||||
b.SetBytes(int64(buf.Len()))
|
||||
}
|
||||
506
vendor/github.com/mattermost/rsc/qr/web/pic.go
сгенерированный
поставляемый
506
vendor/github.com/mattermost/rsc/qr/web/pic.go
сгенерированный
поставляемый
@@ -1,506 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.google.com/p/freetype-go/freetype"
|
||||
"github.com/mattermost/rsc/appfs/fs"
|
||||
"github.com/mattermost/rsc/qr"
|
||||
"github.com/mattermost/rsc/qr/coding"
|
||||
)
|
||||
|
||||
func makeImage(req *http.Request, caption, font string, pt, size, border, scale int, f func(x, y int) uint32) *image.RGBA {
|
||||
d := (size + 2*border) * scale
|
||||
csize := 0
|
||||
if caption != "" {
|
||||
if pt == 0 {
|
||||
pt = 11
|
||||
}
|
||||
csize = pt * 2
|
||||
}
|
||||
c := image.NewRGBA(image.Rect(0, 0, d, d+csize))
|
||||
|
||||
// white
|
||||
u := &image.Uniform{C: color.White}
|
||||
draw.Draw(c, c.Bounds(), u, image.ZP, draw.Src)
|
||||
|
||||
for y := 0; y < size; y++ {
|
||||
for x := 0; x < size; x++ {
|
||||
r := image.Rect((x+border)*scale, (y+border)*scale, (x+border+1)*scale, (y+border+1)*scale)
|
||||
rgba := f(x, y)
|
||||
u.C = color.RGBA{byte(rgba >> 24), byte(rgba >> 16), byte(rgba >> 8), byte(rgba)}
|
||||
draw.Draw(c, r, u, image.ZP, draw.Src)
|
||||
}
|
||||
}
|
||||
|
||||
if csize != 0 {
|
||||
if font == "" {
|
||||
font = "data/luxisr.ttf"
|
||||
}
|
||||
ctxt := fs.NewContext(req)
|
||||
dat, _, err := ctxt.Read(font)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tfont, err := freetype.ParseFont(dat)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ft := freetype.NewContext()
|
||||
ft.SetDst(c)
|
||||
ft.SetDPI(100)
|
||||
ft.SetFont(tfont)
|
||||
ft.SetFontSize(float64(pt))
|
||||
ft.SetSrc(image.NewUniform(color.Black))
|
||||
ft.SetClip(image.Rect(0, 0, 0, 0))
|
||||
wid, err := ft.DrawString(caption, freetype.Pt(0, 0))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
p := freetype.Pt(d, d+3*pt/2)
|
||||
p.X -= wid.X
|
||||
p.X /= 2
|
||||
ft.SetClip(c.Bounds())
|
||||
ft.DrawString(caption, p)
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func makeFrame(req *http.Request, font string, pt, vers, l, scale, dots int) image.Image {
|
||||
lev := coding.Level(l)
|
||||
p, err := coding.NewPlan(coding.Version(vers), lev, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
nd := p.DataBytes / p.Blocks
|
||||
nc := p.CheckBytes / p.Blocks
|
||||
extra := p.DataBytes - nd*p.Blocks
|
||||
|
||||
cap := fmt.Sprintf("QR v%d, %s", vers, lev)
|
||||
if dots > 0 {
|
||||
cap = fmt.Sprintf("QR v%d order, from bottom right", vers)
|
||||
}
|
||||
m := makeImage(req, cap, font, pt, len(p.Pixel), 0, scale, func(x, y int) uint32 {
|
||||
pix := p.Pixel[y][x]
|
||||
switch pix.Role() {
|
||||
case coding.Data:
|
||||
if dots > 0 {
|
||||
return 0xffffffff
|
||||
}
|
||||
off := int(pix.Offset() / 8)
|
||||
nd := nd
|
||||
var i int
|
||||
for i = 0; i < p.Blocks; i++ {
|
||||
if i == extra {
|
||||
nd++
|
||||
}
|
||||
if off < nd {
|
||||
break
|
||||
}
|
||||
off -= nd
|
||||
}
|
||||
return blockColors[i%len(blockColors)]
|
||||
case coding.Check:
|
||||
if dots > 0 {
|
||||
return 0xffffffff
|
||||
}
|
||||
i := (int(pix.Offset()/8) - p.DataBytes) / nc
|
||||
return dark(blockColors[i%len(blockColors)])
|
||||
}
|
||||
if pix&coding.Black != 0 {
|
||||
return 0x000000ff
|
||||
}
|
||||
return 0xffffffff
|
||||
})
|
||||
|
||||
if dots > 0 {
|
||||
b := m.Bounds()
|
||||
for y := 0; y <= len(p.Pixel); y++ {
|
||||
for x := 0; x < b.Dx(); x++ {
|
||||
m.SetRGBA(x, y*scale-(y/len(p.Pixel)), color.RGBA{127, 127, 127, 255})
|
||||
}
|
||||
}
|
||||
for x := 0; x <= len(p.Pixel); x++ {
|
||||
for y := 0; y < b.Dx(); y++ {
|
||||
m.SetRGBA(x*scale-(x/len(p.Pixel)), y, color.RGBA{127, 127, 127, 255})
|
||||
}
|
||||
}
|
||||
order := make([]image.Point, (p.DataBytes+p.CheckBytes)*8+1)
|
||||
for y, row := range p.Pixel {
|
||||
for x, pix := range row {
|
||||
if r := pix.Role(); r != coding.Data && r != coding.Check {
|
||||
continue
|
||||
}
|
||||
// draw.Draw(m, m.Bounds().Add(image.Pt(x*scale, y*scale)), dot, image.ZP, draw.Over)
|
||||
order[pix.Offset()] = image.Point{x*scale + scale/2, y*scale + scale/2}
|
||||
}
|
||||
}
|
||||
|
||||
for mode := 0; mode < 2; mode++ {
|
||||
for i, p := range order {
|
||||
q := order[i+1]
|
||||
if q.X == 0 {
|
||||
break
|
||||
}
|
||||
line(m, p, q, mode)
|
||||
}
|
||||
}
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func line(m *image.RGBA, p, q image.Point, mode int) {
|
||||
x := 0
|
||||
y := 0
|
||||
dx := q.X - p.X
|
||||
dy := q.Y - p.Y
|
||||
xsign := +1
|
||||
ysign := +1
|
||||
if dx < 0 {
|
||||
xsign = -1
|
||||
dx = -dx
|
||||
}
|
||||
if dy < 0 {
|
||||
ysign = -1
|
||||
dy = -dy
|
||||
}
|
||||
pt := func() {
|
||||
switch mode {
|
||||
case 0:
|
||||
for dx := -2; dx <= 2; dx++ {
|
||||
for dy := -2; dy <= 2; dy++ {
|
||||
if dy*dx <= -4 || dy*dx >= 4 {
|
||||
continue
|
||||
}
|
||||
m.SetRGBA(p.X+x*xsign+dx, p.Y+y*ysign+dy, color.RGBA{255, 192, 192, 255})
|
||||
}
|
||||
}
|
||||
|
||||
case 1:
|
||||
m.SetRGBA(p.X+x*xsign, p.Y+y*ysign, color.RGBA{128, 0, 0, 255})
|
||||
}
|
||||
}
|
||||
if dx > dy {
|
||||
for x < dx || y < dy {
|
||||
pt()
|
||||
x++
|
||||
if float64(x)*float64(dy)/float64(dx)-float64(y) > 0.5 {
|
||||
y++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for x < dx || y < dy {
|
||||
pt()
|
||||
y++
|
||||
if float64(y)*float64(dx)/float64(dy)-float64(x) > 0.5 {
|
||||
x++
|
||||
}
|
||||
}
|
||||
}
|
||||
pt()
|
||||
}
|
||||
|
||||
func pngEncode(c image.Image) []byte {
|
||||
var b bytes.Buffer
|
||||
png.Encode(&b, c)
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
// Frame handles a request for a single QR frame.
|
||||
func Frame(w http.ResponseWriter, req *http.Request) {
|
||||
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
|
||||
v := arg("v")
|
||||
scale := arg("scale")
|
||||
if scale == 0 {
|
||||
scale = 8
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
w.Write(pngEncode(makeFrame(req, req.FormValue("font"), arg("pt"), v, arg("l"), scale, arg("dots"))))
|
||||
}
|
||||
|
||||
// Frames handles a request for multiple QR frames.
|
||||
func Frames(w http.ResponseWriter, req *http.Request) {
|
||||
vs := strings.Split(req.FormValue("v"), ",")
|
||||
|
||||
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
|
||||
scale := arg("scale")
|
||||
if scale == 0 {
|
||||
scale = 8
|
||||
}
|
||||
font := req.FormValue("font")
|
||||
pt := arg("pt")
|
||||
dots := arg("dots")
|
||||
|
||||
var images []image.Image
|
||||
l := arg("l")
|
||||
for _, v := range vs {
|
||||
l := l
|
||||
if i := strings.Index(v, "."); i >= 0 {
|
||||
l, _ = strconv.Atoi(v[i+1:])
|
||||
v = v[:i]
|
||||
}
|
||||
vv, _ := strconv.Atoi(v)
|
||||
images = append(images, makeFrame(req, font, pt, vv, l, scale, dots))
|
||||
}
|
||||
|
||||
b := images[len(images)-1].Bounds()
|
||||
|
||||
dx := arg("dx")
|
||||
if dx == 0 {
|
||||
dx = b.Dx()
|
||||
}
|
||||
x, y := 0, 0
|
||||
xmax := 0
|
||||
sep := arg("sep")
|
||||
if sep == 0 {
|
||||
sep = 10
|
||||
}
|
||||
var points []image.Point
|
||||
for i, m := range images {
|
||||
if x > 0 {
|
||||
x += sep
|
||||
}
|
||||
if x > 0 && x+m.Bounds().Dx() > dx {
|
||||
y += sep + images[i-1].Bounds().Dy()
|
||||
x = 0
|
||||
}
|
||||
points = append(points, image.Point{x, y})
|
||||
x += m.Bounds().Dx()
|
||||
if x > xmax {
|
||||
xmax = x
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
c := image.NewRGBA(image.Rect(0, 0, xmax, y+b.Dy()))
|
||||
for i, m := range images {
|
||||
draw.Draw(c, c.Bounds().Add(points[i]), m, image.ZP, draw.Src)
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
w.Write(pngEncode(c))
|
||||
}
|
||||
|
||||
// Mask handles a request for a single QR mask.
|
||||
func Mask(w http.ResponseWriter, req *http.Request) {
|
||||
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
|
||||
v := arg("v")
|
||||
m := arg("m")
|
||||
scale := arg("scale")
|
||||
if scale == 0 {
|
||||
scale = 8
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
w.Write(pngEncode(makeMask(req, req.FormValue("font"), arg("pt"), v, m, scale)))
|
||||
}
|
||||
|
||||
// Masks handles a request for multiple QR masks.
|
||||
func Masks(w http.ResponseWriter, req *http.Request) {
|
||||
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
|
||||
v := arg("v")
|
||||
scale := arg("scale")
|
||||
if scale == 0 {
|
||||
scale = 8
|
||||
}
|
||||
font := req.FormValue("font")
|
||||
pt := arg("pt")
|
||||
var mm []image.Image
|
||||
for m := 0; m < 8; m++ {
|
||||
mm = append(mm, makeMask(req, font, pt, v, m, scale))
|
||||
}
|
||||
dx := mm[0].Bounds().Dx()
|
||||
dy := mm[0].Bounds().Dy()
|
||||
|
||||
sep := arg("sep")
|
||||
if sep == 0 {
|
||||
sep = 10
|
||||
}
|
||||
c := image.NewRGBA(image.Rect(0, 0, (dx+sep)*4-sep, (dy+sep)*2-sep))
|
||||
for m := 0; m < 8; m++ {
|
||||
x := (m % 4) * (dx + sep)
|
||||
y := (m / 4) * (dy + sep)
|
||||
draw.Draw(c, c.Bounds().Add(image.Pt(x, y)), mm[m], image.ZP, draw.Src)
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
w.Write(pngEncode(c))
|
||||
}
|
||||
|
||||
var maskName = []string{
|
||||
"(x+y) % 2",
|
||||
"y % 2",
|
||||
"x % 3",
|
||||
"(x+y) % 3",
|
||||
"(y/2 + x/3) % 2",
|
||||
"xy%2 + xy%3",
|
||||
"(xy%2 + xy%3) % 2",
|
||||
"(xy%3 + (x+y)%2) % 2",
|
||||
}
|
||||
|
||||
func makeMask(req *http.Request, font string, pt int, vers, mask, scale int) image.Image {
|
||||
p, err := coding.NewPlan(coding.Version(vers), coding.L, coding.Mask(mask))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
m := makeImage(req, maskName[mask], font, pt, len(p.Pixel), 0, scale, func(x, y int) uint32 {
|
||||
pix := p.Pixel[y][x]
|
||||
switch pix.Role() {
|
||||
case coding.Data, coding.Check:
|
||||
if pix&coding.Invert != 0 {
|
||||
return 0x000000ff
|
||||
}
|
||||
}
|
||||
return 0xffffffff
|
||||
})
|
||||
return m
|
||||
}
|
||||
|
||||
var blockColors = []uint32{
|
||||
0x7777ffff,
|
||||
0xffff77ff,
|
||||
0xff7777ff,
|
||||
0x77ffffff,
|
||||
0x1e90ffff,
|
||||
0xffffe0ff,
|
||||
0x8b6969ff,
|
||||
0x77ff77ff,
|
||||
0x9b30ffff,
|
||||
0x00bfffff,
|
||||
0x90e890ff,
|
||||
0xfff68fff,
|
||||
0xffec8bff,
|
||||
0xffa07aff,
|
||||
0xffa54fff,
|
||||
0xeee8aaff,
|
||||
0x98fb98ff,
|
||||
0xbfbfbfff,
|
||||
0x54ff9fff,
|
||||
0xffaeb9ff,
|
||||
0xb23aeeff,
|
||||
0xbbffffff,
|
||||
0x7fffd4ff,
|
||||
0xff7a7aff,
|
||||
0x00007fff,
|
||||
}
|
||||
|
||||
func dark(x uint32) uint32 {
|
||||
r, g, b, a := byte(x>>24), byte(x>>16), byte(x>>8), byte(x)
|
||||
r = r/2 + r/4
|
||||
g = g/2 + g/4
|
||||
b = b/2 + b/4
|
||||
return uint32(r)<<24 | uint32(g)<<16 | uint32(b)<<8 | uint32(a)
|
||||
}
|
||||
|
||||
func clamp(x int) byte {
|
||||
if x < 0 {
|
||||
return 0
|
||||
}
|
||||
if x > 255 {
|
||||
return 255
|
||||
}
|
||||
return byte(x)
|
||||
}
|
||||
|
||||
func max(x, y int) int {
|
||||
if x > y {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
// Arrow handles a request for an arrow pointing in a given direction.
|
||||
func Arrow(w http.ResponseWriter, req *http.Request) {
|
||||
arg := func(s string) int { x, _ := strconv.Atoi(req.FormValue(s)); return x }
|
||||
dir := arg("dir")
|
||||
size := arg("size")
|
||||
if size == 0 {
|
||||
size = 50
|
||||
}
|
||||
del := size / 10
|
||||
|
||||
m := image.NewRGBA(image.Rect(0, 0, size, size))
|
||||
|
||||
if dir == 4 {
|
||||
draw.Draw(m, m.Bounds(), image.Black, image.ZP, draw.Src)
|
||||
draw.Draw(m, image.Rect(5, 5, size-5, size-5), image.White, image.ZP, draw.Src)
|
||||
}
|
||||
|
||||
pt := func(x, y int, c color.RGBA) {
|
||||
switch dir {
|
||||
case 0:
|
||||
m.SetRGBA(x, y, c)
|
||||
case 1:
|
||||
m.SetRGBA(y, size-1-x, c)
|
||||
case 2:
|
||||
m.SetRGBA(size-1-x, size-1-y, c)
|
||||
case 3:
|
||||
m.SetRGBA(size-1-y, x, c)
|
||||
}
|
||||
}
|
||||
|
||||
for y := 0; y < size/2; y++ {
|
||||
for x := 0; x < del && x < y; x++ {
|
||||
pt(x, y, color.RGBA{0, 0, 0, 255})
|
||||
}
|
||||
for x := del; x < y-del; x++ {
|
||||
pt(x, y, color.RGBA{128, 128, 255, 255})
|
||||
}
|
||||
for x := max(y-del, 0); x <= y; x++ {
|
||||
pt(x, y, color.RGBA{0, 0, 0, 255})
|
||||
}
|
||||
}
|
||||
for y := size / 2; y < size; y++ {
|
||||
for x := 0; x < del && x < size-1-y; x++ {
|
||||
pt(x, y, color.RGBA{0, 0, 0, 255})
|
||||
}
|
||||
for x := del; x < size-1-y-del; x++ {
|
||||
pt(x, y, color.RGBA{128, 128, 192, 255})
|
||||
}
|
||||
for x := max(size-1-y-del, 0); x <= size-1-y; x++ {
|
||||
pt(x, y, color.RGBA{0, 0, 0, 255})
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
w.Write(pngEncode(m))
|
||||
}
|
||||
|
||||
// Encode encodes a string using the given version, level, and mask.
|
||||
func Encode(w http.ResponseWriter, req *http.Request) {
|
||||
val := func(s string) int {
|
||||
v, _ := strconv.Atoi(req.FormValue(s))
|
||||
return v
|
||||
}
|
||||
|
||||
l := coding.Level(val("l"))
|
||||
v := coding.Version(val("v"))
|
||||
enc := coding.String(req.FormValue("t"))
|
||||
m := coding.Mask(val("m"))
|
||||
|
||||
p, err := coding.NewPlan(v, l, m)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cc, err := p.Encode(enc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c := &qr.Code{Bitmap: cc.Bitmap, Size: cc.Size, Stride: cc.Stride, Scale: 8}
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
w.Write(c.PNG())
|
||||
}
|
||||
|
||||
1118
vendor/github.com/mattermost/rsc/qr/web/play.go
сгенерированный
поставляемый
1118
vendor/github.com/mattermost/rsc/qr/web/play.go
сгенерированный
поставляемый
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
152
vendor/github.com/mattermost/rsc/qr/web/resize/resize.go
сгенерированный
поставляемый
152
vendor/github.com/mattermost/rsc/qr/web/resize/resize.go
сгенерированный
поставляемый
@@ -1,152 +0,0 @@
|
||||
// Copyright 2011 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 resize
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
// average convert the sums to averages and returns the result.
|
||||
func average(sum []uint64, w, h int, n uint64) *image.RGBA {
|
||||
ret := image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
for y := 0; y < h; y++ {
|
||||
for x := 0; x < w; x++ {
|
||||
index := 4 * (y*w + x)
|
||||
pix := ret.Pix[y*ret.Stride+x*4:]
|
||||
pix[0] = uint8(sum[index+0] / n)
|
||||
pix[1] = uint8(sum[index+1] / n)
|
||||
pix[2] = uint8(sum[index+2] / n)
|
||||
pix[3] = uint8(sum[index+3] / n)
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
// ResizeRGBA returns a scaled copy of the RGBA image slice r of m.
|
||||
// The returned image has width w and height h.
|
||||
func ResizeRGBA(m *image.RGBA, r image.Rectangle, w, h int) *image.RGBA {
|
||||
ww, hh := uint64(w), uint64(h)
|
||||
dx, dy := uint64(r.Dx()), uint64(r.Dy())
|
||||
// See comment in Resize.
|
||||
n, sum := dx*dy, make([]uint64, 4*w*h)
|
||||
for y := r.Min.Y; y < r.Max.Y; y++ {
|
||||
pix := m.Pix[(y-r.Min.Y)*m.Stride:]
|
||||
for x := r.Min.X; x < r.Max.X; x++ {
|
||||
// Get the source pixel.
|
||||
p := pix[(x-r.Min.X)*4:]
|
||||
r64 := uint64(p[0])
|
||||
g64 := uint64(p[1])
|
||||
b64 := uint64(p[2])
|
||||
a64 := uint64(p[3])
|
||||
// Spread the source pixel over 1 or more destination rows.
|
||||
py := uint64(y) * hh
|
||||
for remy := hh; remy > 0; {
|
||||
qy := dy - (py % dy)
|
||||
if qy > remy {
|
||||
qy = remy
|
||||
}
|
||||
// Spread the source pixel over 1 or more destination columns.
|
||||
px := uint64(x) * ww
|
||||
index := 4 * ((py/dy)*ww + (px / dx))
|
||||
for remx := ww; remx > 0; {
|
||||
qx := dx - (px % dx)
|
||||
if qx > remx {
|
||||
qx = remx
|
||||
}
|
||||
qxy := qx * qy
|
||||
sum[index+0] += r64 * qxy
|
||||
sum[index+1] += g64 * qxy
|
||||
sum[index+2] += b64 * qxy
|
||||
sum[index+3] += a64 * qxy
|
||||
index += 4
|
||||
px += qx
|
||||
remx -= qx
|
||||
}
|
||||
py += qy
|
||||
remy -= qy
|
||||
}
|
||||
}
|
||||
}
|
||||
return average(sum, w, h, n)
|
||||
}
|
||||
|
||||
// ResizeNRGBA returns a scaled copy of the RGBA image slice r of m.
|
||||
// The returned image has width w and height h.
|
||||
func ResizeNRGBA(m *image.NRGBA, r image.Rectangle, w, h int) *image.RGBA {
|
||||
ww, hh := uint64(w), uint64(h)
|
||||
dx, dy := uint64(r.Dx()), uint64(r.Dy())
|
||||
// See comment in Resize.
|
||||
n, sum := dx*dy, make([]uint64, 4*w*h)
|
||||
for y := r.Min.Y; y < r.Max.Y; y++ {
|
||||
pix := m.Pix[(y-r.Min.Y)*m.Stride:]
|
||||
for x := r.Min.X; x < r.Max.X; x++ {
|
||||
// Get the source pixel.
|
||||
p := pix[(x-r.Min.X)*4:]
|
||||
r64 := uint64(p[0])
|
||||
g64 := uint64(p[1])
|
||||
b64 := uint64(p[2])
|
||||
a64 := uint64(p[3])
|
||||
r64 = (r64 * a64) / 255
|
||||
g64 = (g64 * a64) / 255
|
||||
b64 = (b64 * a64) / 255
|
||||
// Spread the source pixel over 1 or more destination rows.
|
||||
py := uint64(y) * hh
|
||||
for remy := hh; remy > 0; {
|
||||
qy := dy - (py % dy)
|
||||
if qy > remy {
|
||||
qy = remy
|
||||
}
|
||||
// Spread the source pixel over 1 or more destination columns.
|
||||
px := uint64(x) * ww
|
||||
index := 4 * ((py/dy)*ww + (px / dx))
|
||||
for remx := ww; remx > 0; {
|
||||
qx := dx - (px % dx)
|
||||
if qx > remx {
|
||||
qx = remx
|
||||
}
|
||||
qxy := qx * qy
|
||||
sum[index+0] += r64 * qxy
|
||||
sum[index+1] += g64 * qxy
|
||||
sum[index+2] += b64 * qxy
|
||||
sum[index+3] += a64 * qxy
|
||||
index += 4
|
||||
px += qx
|
||||
remx -= qx
|
||||
}
|
||||
py += qy
|
||||
remy -= qy
|
||||
}
|
||||
}
|
||||
}
|
||||
return average(sum, w, h, n)
|
||||
}
|
||||
|
||||
// Resample returns a resampled copy of the image slice r of m.
|
||||
// The returned image has width w and height h.
|
||||
func Resample(m image.Image, r image.Rectangle, w, h int) *image.RGBA {
|
||||
if w < 0 || h < 0 {
|
||||
return nil
|
||||
}
|
||||
if w == 0 || h == 0 || r.Dx() <= 0 || r.Dy() <= 0 {
|
||||
return image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
}
|
||||
curw, curh := r.Dx(), r.Dy()
|
||||
img := image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
for y := 0; y < h; y++ {
|
||||
for x := 0; x < w; x++ {
|
||||
// Get a source pixel.
|
||||
subx := x * curw / w
|
||||
suby := y * curh / h
|
||||
r32, g32, b32, a32 := m.At(subx, suby).RGBA()
|
||||
r := uint8(r32 >> 8)
|
||||
g := uint8(g32 >> 8)
|
||||
b := uint8(b32 >> 8)
|
||||
a := uint8(a32 >> 8)
|
||||
img.SetRGBA(x, y, color.RGBA{r, g, b, a})
|
||||
}
|
||||
}
|
||||
return img
|
||||
}
|
||||
225
vendor/github.com/mattermost/rsc/regexp/regmerge/copy.go
сгенерированный
поставляемый
225
vendor/github.com/mattermost/rsc/regexp/regmerge/copy.go
сгенерированный
поставляемый
@@ -1,225 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Copied from code.google.com/p/codesearch/regexp/copy.go.
|
||||
|
||||
// Copied from Go's regexp/syntax.
|
||||
// Formatters edited to handle instByteRange.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"regexp/syntax"
|
||||
"sort"
|
||||
"strconv"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// cleanClass sorts the ranges (pairs of elements of r),
|
||||
// merges them, and eliminates duplicates.
|
||||
func cleanClass(rp *[]rune) []rune {
|
||||
|
||||
// Sort by lo increasing, hi decreasing to break ties.
|
||||
sort.Sort(ranges{rp})
|
||||
|
||||
r := *rp
|
||||
if len(r) < 2 {
|
||||
return r
|
||||
}
|
||||
|
||||
// Merge abutting, overlapping.
|
||||
w := 2 // write index
|
||||
for i := 2; i < len(r); i += 2 {
|
||||
lo, hi := r[i], r[i+1]
|
||||
if lo <= r[w-1]+1 {
|
||||
// merge with previous range
|
||||
if hi > r[w-1] {
|
||||
r[w-1] = hi
|
||||
}
|
||||
continue
|
||||
}
|
||||
// new disjoint range
|
||||
r[w] = lo
|
||||
r[w+1] = hi
|
||||
w += 2
|
||||
}
|
||||
|
||||
return r[:w]
|
||||
}
|
||||
|
||||
// appendRange returns the result of appending the range lo-hi to the class r.
|
||||
func appendRange(r []rune, lo, hi rune) []rune {
|
||||
// Expand last range or next to last range if it overlaps or abuts.
|
||||
// Checking two ranges helps when appending case-folded
|
||||
// alphabets, so that one range can be expanding A-Z and the
|
||||
// other expanding a-z.
|
||||
n := len(r)
|
||||
for i := 2; i <= 4; i += 2 { // twice, using i=2, i=4
|
||||
if n >= i {
|
||||
rlo, rhi := r[n-i], r[n-i+1]
|
||||
if lo <= rhi+1 && rlo <= hi+1 {
|
||||
if lo < rlo {
|
||||
r[n-i] = lo
|
||||
}
|
||||
if hi > rhi {
|
||||
r[n-i+1] = hi
|
||||
}
|
||||
return r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return append(r, lo, hi)
|
||||
}
|
||||
|
||||
const (
|
||||
// minimum and maximum runes involved in folding.
|
||||
// checked during test.
|
||||
minFold = 0x0041
|
||||
maxFold = 0x1044f
|
||||
)
|
||||
|
||||
// appendFoldedRange returns the result of appending the range lo-hi
|
||||
// and its case folding-equivalent runes to the class r.
|
||||
func appendFoldedRange(r []rune, lo, hi rune) []rune {
|
||||
// Optimizations.
|
||||
if lo <= minFold && hi >= maxFold {
|
||||
// Range is full: folding can't add more.
|
||||
return appendRange(r, lo, hi)
|
||||
}
|
||||
if hi < minFold || lo > maxFold {
|
||||
// Range is outside folding possibilities.
|
||||
return appendRange(r, lo, hi)
|
||||
}
|
||||
if lo < minFold {
|
||||
// [lo, minFold-1] needs no folding.
|
||||
r = appendRange(r, lo, minFold-1)
|
||||
lo = minFold
|
||||
}
|
||||
if hi > maxFold {
|
||||
// [maxFold+1, hi] needs no folding.
|
||||
r = appendRange(r, maxFold+1, hi)
|
||||
hi = maxFold
|
||||
}
|
||||
|
||||
// Brute force. Depend on appendRange to coalesce ranges on the fly.
|
||||
for c := lo; c <= hi; c++ {
|
||||
r = appendRange(r, c, c)
|
||||
f := unicode.SimpleFold(c)
|
||||
for f != c {
|
||||
r = appendRange(r, f, f)
|
||||
f = unicode.SimpleFold(f)
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// ranges implements sort.Interface on a []rune.
|
||||
// The choice of receiver type definition is strange
|
||||
// but avoids an allocation since we already have
|
||||
// a *[]rune.
|
||||
type ranges struct {
|
||||
p *[]rune
|
||||
}
|
||||
|
||||
func (ra ranges) Less(i, j int) bool {
|
||||
p := *ra.p
|
||||
i *= 2
|
||||
j *= 2
|
||||
return p[i] < p[j] || p[i] == p[j] && p[i+1] > p[j+1]
|
||||
}
|
||||
|
||||
func (ra ranges) Len() int {
|
||||
return len(*ra.p) / 2
|
||||
}
|
||||
|
||||
func (ra ranges) Swap(i, j int) {
|
||||
p := *ra.p
|
||||
i *= 2
|
||||
j *= 2
|
||||
p[i], p[i+1], p[j], p[j+1] = p[j], p[j+1], p[i], p[i+1]
|
||||
}
|
||||
|
||||
func progString(p *syntax.Prog) string {
|
||||
var b bytes.Buffer
|
||||
dumpProg(&b, p)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func instString(i *syntax.Inst) string {
|
||||
var b bytes.Buffer
|
||||
dumpInst(&b, i)
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func bw(b *bytes.Buffer, args ...string) {
|
||||
for _, s := range args {
|
||||
b.WriteString(s)
|
||||
}
|
||||
}
|
||||
|
||||
func dumpProg(b *bytes.Buffer, p *syntax.Prog) {
|
||||
for j := range p.Inst {
|
||||
i := &p.Inst[j]
|
||||
pc := strconv.Itoa(j)
|
||||
if len(pc) < 3 {
|
||||
b.WriteString(" "[len(pc):])
|
||||
}
|
||||
if j == p.Start {
|
||||
pc += "*"
|
||||
}
|
||||
bw(b, pc, "\t")
|
||||
dumpInst(b, i)
|
||||
bw(b, "\n")
|
||||
}
|
||||
}
|
||||
|
||||
func u32(i uint32) string {
|
||||
return strconv.FormatUint(uint64(i), 10)
|
||||
}
|
||||
|
||||
func dumpInst(b *bytes.Buffer, i *syntax.Inst) {
|
||||
switch i.Op {
|
||||
case syntax.InstAlt:
|
||||
bw(b, "alt -> ", u32(i.Out), ", ", u32(i.Arg))
|
||||
case syntax.InstAltMatch:
|
||||
bw(b, "altmatch -> ", u32(i.Out), ", ", u32(i.Arg))
|
||||
case syntax.InstCapture:
|
||||
bw(b, "cap ", u32(i.Arg), " -> ", u32(i.Out))
|
||||
case syntax.InstEmptyWidth:
|
||||
bw(b, "empty ", u32(i.Arg), " -> ", u32(i.Out))
|
||||
case syntax.InstMatch:
|
||||
bw(b, "match")
|
||||
case syntax.InstFail:
|
||||
bw(b, "fail")
|
||||
case syntax.InstNop:
|
||||
bw(b, "nop -> ", u32(i.Out))
|
||||
case instByteRange:
|
||||
fmt.Fprintf(b, "byte %02x-%02x", (i.Arg>>8)&0xFF, i.Arg&0xFF)
|
||||
if i.Arg&argFold != 0 {
|
||||
bw(b, "/i")
|
||||
}
|
||||
bw(b, " -> ", u32(i.Out))
|
||||
|
||||
// Should not happen
|
||||
case syntax.InstRune:
|
||||
if i.Rune == nil {
|
||||
// shouldn't happen
|
||||
bw(b, "rune <nil>")
|
||||
}
|
||||
bw(b, "rune ", strconv.QuoteToASCII(string(i.Rune)))
|
||||
if syntax.Flags(i.Arg)&syntax.FoldCase != 0 {
|
||||
bw(b, "/i")
|
||||
}
|
||||
bw(b, " -> ", u32(i.Out))
|
||||
case syntax.InstRune1:
|
||||
bw(b, "rune1 ", strconv.QuoteToASCII(string(i.Rune)), " -> ", u32(i.Out))
|
||||
case syntax.InstRuneAny:
|
||||
bw(b, "any -> ", u32(i.Out))
|
||||
case syntax.InstRuneAnyNotNL:
|
||||
bw(b, "anynotnl -> ", u32(i.Out))
|
||||
}
|
||||
}
|
||||
96
vendor/github.com/mattermost/rsc/regexp/regmerge/main.go
сгенерированный
поставляемый
96
vendor/github.com/mattermost/rsc/regexp/regmerge/main.go
сгенерированный
поставляемый
@@ -1,96 +0,0 @@
|
||||
// Copyright 2012 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 main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"regexp/syntax"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
var maxState = flag.Int("m", 1e5, "maximum number of states to explore")
|
||||
var cpuprof = flag.String("cpuprofile", "", "cpu profile file")
|
||||
|
||||
func main() {
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "usage: regmerge [-m maxstate] regexp [regexp2 regexp3....]\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
if len(flag.Args()) < 1 {
|
||||
flag.Usage()
|
||||
}
|
||||
|
||||
os.Exit(run(flag.Args()))
|
||||
}
|
||||
|
||||
func run(args []string) int {
|
||||
if *cpuprof != "" {
|
||||
f, err := os.Create(*cpuprof)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
m, err := compile(flag.Args()...)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
n := 100
|
||||
for ;; n *= 2 {
|
||||
if n >= *maxState {
|
||||
if n >= 2* *maxState {
|
||||
fmt.Printf("reached state limit\n")
|
||||
return 1
|
||||
}
|
||||
n = *maxState
|
||||
}
|
||||
log.Printf("try %d states...\n", n)
|
||||
s, err := m.findMatch(n)
|
||||
if err == nil {
|
||||
fmt.Printf("%q\n", s)
|
||||
return 0
|
||||
}
|
||||
if err != ErrMemory {
|
||||
fmt.Printf("failed: %s\n", err)
|
||||
return 3
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
func compile(exprs ...string) (*matcher, error) {
|
||||
var progs []*syntax.Prog
|
||||
for _, expr := range exprs {
|
||||
re, err := syntax.Parse(expr, syntax.Perl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sre := re.Simplify()
|
||||
prog, err := syntax.Compile(sre)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := toByteProg(prog); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
progs = append(progs, prog)
|
||||
}
|
||||
m := &matcher{}
|
||||
if err := m.init(joinProgs(progs), len(progs)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func bug() {
|
||||
panic("regmerge: internal error")
|
||||
}
|
||||
406
vendor/github.com/mattermost/rsc/regexp/regmerge/match.go
сгенерированный
поставляемый
406
vendor/github.com/mattermost/rsc/regexp/regmerge/match.go
сгенерированный
поставляемый
@@ -1,406 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Copied from code.google.com/p/codesearch/regexp/copy.go
|
||||
// and adapted for the problem of finding a matching string, not
|
||||
// testing whether a particular string matches.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"hash"
|
||||
"log"
|
||||
"regexp/syntax"
|
||||
)
|
||||
|
||||
// A matcher holds the state for running regular expression search.
|
||||
type matcher struct {
|
||||
buf []byte
|
||||
prog *syntax.Prog // compiled program
|
||||
dstate map[uint32]*dstate // dstate cache
|
||||
start *dstate // start state
|
||||
startLine *dstate // start state for beginning of line
|
||||
z1, z2, z3 nstate // three temporary nstates
|
||||
ids []int
|
||||
numState int
|
||||
maxState int
|
||||
numByte int
|
||||
numMatch int
|
||||
undo [256]byte
|
||||
all *dstate
|
||||
allTail **dstate
|
||||
h hash.Hash32
|
||||
}
|
||||
|
||||
// An nstate corresponds to an NFA state.
|
||||
type nstate struct {
|
||||
q Set // queue of program instructions
|
||||
flag flags // flags (TODO)
|
||||
needFlag syntax.EmptyOp
|
||||
}
|
||||
|
||||
// The flags record state about a position between bytes in the text.
|
||||
type flags uint32
|
||||
|
||||
const (
|
||||
flagBOL flags = 1 << iota // beginning of line
|
||||
flagEOL // end of line
|
||||
flagBOT // beginning of text
|
||||
flagEOT // end of text
|
||||
flagWord // last byte was word byte
|
||||
)
|
||||
|
||||
// A dstate corresponds to a DFA state.
|
||||
type dstate struct {
|
||||
enc string // encoded nstate
|
||||
nextAll *dstate
|
||||
nextHash *dstate
|
||||
prev *dstate
|
||||
prevByte int
|
||||
done bool
|
||||
}
|
||||
|
||||
func (z *nstate) String() string {
|
||||
return fmt.Sprintf("%v/%#x+%#x", z.q.Dense(), z.flag, z.needFlag)
|
||||
}
|
||||
|
||||
// enc encodes z as a string.
|
||||
func (m *matcher) enc(z *nstate) []byte {
|
||||
buf := m.buf[:0]
|
||||
buf = append(buf, byte(z.needFlag), byte(z.flag))
|
||||
ids := m.ids[:0]
|
||||
for _, id := range z.q.Dense() {
|
||||
ids = append(ids, int(id))
|
||||
}
|
||||
sortInts(ids)
|
||||
last := ^uint32(0)
|
||||
for _, id := range ids {
|
||||
x := uint32(id)-last
|
||||
last = uint32(id)
|
||||
for x >= 0x80 {
|
||||
buf = append(buf, byte(x)|0x80)
|
||||
x >>= 7
|
||||
}
|
||||
buf = append(buf, byte(x))
|
||||
}
|
||||
m.buf = buf
|
||||
return buf
|
||||
}
|
||||
|
||||
// dec decodes the encoding s into z.
|
||||
func (m *matcher) dec(z *nstate, s string) {
|
||||
b := append(m.buf[:0], s...)
|
||||
m.buf = b
|
||||
z.needFlag = syntax.EmptyOp(b[0])
|
||||
b = b[1:]
|
||||
i, n := binary.Uvarint(b)
|
||||
if n <= 0 {
|
||||
bug()
|
||||
}
|
||||
b = b[n:]
|
||||
z.flag = flags(i)
|
||||
z.q.Reset()
|
||||
last := ^uint32(0)
|
||||
for len(b) > 0 {
|
||||
i, n = binary.Uvarint(b)
|
||||
if n <= 0 {
|
||||
bug()
|
||||
}
|
||||
b = b[n:]
|
||||
last += uint32(i)
|
||||
z.q.Add(last, 0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// init initializes the matcher.
|
||||
func (m *matcher) init(prog *syntax.Prog, n int) error {
|
||||
m.prog = prog
|
||||
m.dstate = make(map[uint32]*dstate)
|
||||
m.numMatch = n
|
||||
m.maxState = 10
|
||||
m.allTail = &m.all
|
||||
m.numByte = 256
|
||||
for i := range m.undo {
|
||||
m.undo[i] = byte(i)
|
||||
}
|
||||
m.h = fnv.New32()
|
||||
|
||||
m.z1.q.Init(uint32(len(prog.Inst)))
|
||||
m.z2.q.Init(uint32(len(prog.Inst)))
|
||||
m.z3.q.Init(uint32(len(prog.Inst)))
|
||||
m.ids = make([]int, 0, len(prog.Inst))
|
||||
|
||||
m.addq(&m.z1.q, uint32(prog.Start), syntax.EmptyBeginLine|syntax.EmptyBeginText)
|
||||
m.z1.flag = flagBOL | flagBOT
|
||||
m.start = m.cache(&m.z1, nil, 0)
|
||||
|
||||
m.z1.q.Reset()
|
||||
m.addq(&m.z1.q, uint32(prog.Start), syntax.EmptyBeginLine)
|
||||
m.z1.flag = flagBOL
|
||||
m.startLine = m.cache(&m.z1, nil, 0)
|
||||
|
||||
m.crunchProg()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// stepEmpty steps runq to nextq expanding according to flag.
|
||||
func (m *matcher) stepEmpty(runq, nextq *Set, flag syntax.EmptyOp) {
|
||||
nextq.Reset()
|
||||
for _, id := range runq.Dense() {
|
||||
m.addq(nextq, id, flag)
|
||||
}
|
||||
}
|
||||
|
||||
// stepByte steps runq to nextq consuming c and then expanding according to flag.
|
||||
// It returns true if a match ends immediately before c.
|
||||
// c is either an input byte or endText.
|
||||
func (m *matcher) stepByte(runq, nextq *Set, c int, flag syntax.EmptyOp) (match bool) {
|
||||
nextq.Reset()
|
||||
m.addq(nextq, uint32(m.prog.Start), flag)
|
||||
|
||||
nmatch := 0
|
||||
for _, id := range runq.Dense() {
|
||||
i := &m.prog.Inst[id]
|
||||
switch i.Op {
|
||||
default:
|
||||
continue
|
||||
case syntax.InstMatch:
|
||||
nmatch++
|
||||
continue
|
||||
case instByteRange:
|
||||
if c == endText {
|
||||
break
|
||||
}
|
||||
lo := int((i.Arg >> 8) & 0xFF)
|
||||
hi := int(i.Arg & 0xFF)
|
||||
if i.Arg&argFold != 0 && 'a' <= c && c <= 'z' {
|
||||
c += 'A' - 'a'
|
||||
}
|
||||
if lo <= c && c <= hi {
|
||||
m.addq(nextq, i.Out, flag)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nmatch == m.numMatch
|
||||
}
|
||||
|
||||
// addq adds id to the queue, expanding according to flag.
|
||||
func (m *matcher) addq(q *Set, id uint32, flag syntax.EmptyOp) {
|
||||
if q.Has(id, 0) {
|
||||
return
|
||||
}
|
||||
q.MustAdd(id)
|
||||
i := &m.prog.Inst[id]
|
||||
switch i.Op {
|
||||
case syntax.InstCapture, syntax.InstNop:
|
||||
m.addq(q, i.Out, flag)
|
||||
case syntax.InstAlt, syntax.InstAltMatch:
|
||||
m.addq(q, i.Out, flag)
|
||||
m.addq(q, i.Arg, flag)
|
||||
case syntax.InstEmptyWidth:
|
||||
if syntax.EmptyOp(i.Arg)&^flag == 0 {
|
||||
m.addq(q, i.Out, flag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const endText = -1
|
||||
|
||||
// computeNext computes the next DFA state if we're in d reading c (an input byte or endText).
|
||||
func (m *matcher) computeNext(this, next *nstate, d *dstate, c int) bool {
|
||||
// compute flags in effect before c
|
||||
flag := syntax.EmptyOp(0)
|
||||
if this.flag&flagBOL != 0 {
|
||||
flag |= syntax.EmptyBeginLine
|
||||
}
|
||||
if this.flag&flagBOT != 0 {
|
||||
flag |= syntax.EmptyBeginText
|
||||
}
|
||||
if this.flag&flagWord != 0 {
|
||||
if !isWordByte(c) {
|
||||
flag |= syntax.EmptyWordBoundary
|
||||
} else {
|
||||
flag |= syntax.EmptyNoWordBoundary
|
||||
}
|
||||
} else {
|
||||
if isWordByte(c) {
|
||||
flag |= syntax.EmptyWordBoundary
|
||||
} else {
|
||||
flag |= syntax.EmptyNoWordBoundary
|
||||
}
|
||||
}
|
||||
if c == '\n' {
|
||||
flag |= syntax.EmptyEndLine
|
||||
}
|
||||
if c == endText {
|
||||
flag |= syntax.EmptyEndLine | syntax.EmptyEndText
|
||||
}
|
||||
|
||||
if flag &= this.needFlag; flag != 0 {
|
||||
// re-expand queue using new flags.
|
||||
// TODO: only do this when it matters
|
||||
// (something is gating on word boundaries).
|
||||
m.stepEmpty(&this.q, &next.q, flag)
|
||||
this, next = next, &m.z3
|
||||
}
|
||||
|
||||
// now compute flags after c.
|
||||
flag = 0
|
||||
next.flag = 0
|
||||
if c == '\n' {
|
||||
flag |= syntax.EmptyBeginLine
|
||||
next.flag |= flagBOL
|
||||
}
|
||||
if isWordByte(c) {
|
||||
next.flag |= flagWord
|
||||
}
|
||||
|
||||
// re-add start, process rune + expand according to flags.
|
||||
if m.stepByte(&this.q, &next.q, c, flag) {
|
||||
return true
|
||||
}
|
||||
next.needFlag = m.queueFlag(&next.q)
|
||||
if next.needFlag&syntax.EmptyBeginLine == 0 {
|
||||
next.flag &^= flagBOL
|
||||
}
|
||||
if next.needFlag&(syntax.EmptyWordBoundary|syntax.EmptyNoWordBoundary) == 0{
|
||||
next.flag &^= flagWord
|
||||
}
|
||||
|
||||
m.cache(next, d, c)
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *matcher) queueFlag(runq *Set) syntax.EmptyOp {
|
||||
var e uint32
|
||||
for _, id := range runq.Dense() {
|
||||
i := &m.prog.Inst[id]
|
||||
if i.Op == syntax.InstEmptyWidth {
|
||||
e |= i.Arg
|
||||
}
|
||||
}
|
||||
return syntax.EmptyOp(e)
|
||||
}
|
||||
|
||||
func (m *matcher) hash(enc []byte) uint32 {
|
||||
m.h.Reset()
|
||||
m.h.Write(enc)
|
||||
return m.h.Sum32()
|
||||
}
|
||||
|
||||
func (m *matcher) find(h uint32, enc []byte) *dstate {
|
||||
Search:
|
||||
for d := m.dstate[h]; d!=nil; d=d.nextHash {
|
||||
s := d.enc
|
||||
if len(s) != len(enc) {
|
||||
continue Search
|
||||
}
|
||||
for i, b := range enc {
|
||||
if s[i] != b {
|
||||
continue Search
|
||||
}
|
||||
}
|
||||
return d
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *matcher) cache(z *nstate, prev *dstate, prevByte int) *dstate {
|
||||
enc := m.enc(z)
|
||||
h := m.hash(enc)
|
||||
d := m.find(h, enc)
|
||||
if d != nil {
|
||||
return d
|
||||
}
|
||||
|
||||
if m.numState >= m.maxState {
|
||||
panic(ErrMemory)
|
||||
}
|
||||
m.numState++
|
||||
d = &dstate{
|
||||
enc: string(enc),
|
||||
prev: prev,
|
||||
prevByte: prevByte,
|
||||
nextHash: m.dstate[h],
|
||||
}
|
||||
m.dstate[h] = d
|
||||
*m.allTail = d
|
||||
m.allTail = &d.nextAll
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
// isWordByte reports whether the byte c is a word character: ASCII only.
|
||||
// This is used to implement \b and \B. This is not right for Unicode, but:
|
||||
// - it's hard to get right in a byte-at-a-time matching world
|
||||
// (the DFA has only one-byte lookahead)
|
||||
// - this crude approximation is the same one PCRE uses
|
||||
func isWordByte(c int) bool {
|
||||
return 'A' <= c && c <= 'Z' ||
|
||||
'a' <= c && c <= 'z' ||
|
||||
'0' <= c && c <= '9' ||
|
||||
c == '_'
|
||||
}
|
||||
|
||||
var ErrNoMatch = errors.New("no matching strings")
|
||||
var ErrMemory = errors.New("exhausted memory")
|
||||
|
||||
func (m *matcher) findMatch(maxState int) (s string, err error) {
|
||||
defer func() {
|
||||
switch r := recover().(type) {
|
||||
case nil:
|
||||
return
|
||||
case error:
|
||||
err = r
|
||||
return
|
||||
default:
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
|
||||
m.maxState = maxState
|
||||
numState := 0
|
||||
var d *dstate
|
||||
var c int
|
||||
for d = m.all; d != nil; d = d.nextAll {
|
||||
numState++
|
||||
if d.done {
|
||||
continue
|
||||
}
|
||||
this, next := &m.z1, &m.z2
|
||||
m.dec(this, d.enc)
|
||||
if m.computeNext(this, next, d, endText) {
|
||||
c = endText
|
||||
goto Found
|
||||
}
|
||||
for _, cb := range m.undo[:m.numByte] {
|
||||
if m.computeNext(this, next, d, int(cb)) {
|
||||
c = int(cb)
|
||||
goto Found
|
||||
}
|
||||
}
|
||||
d.done = true
|
||||
}
|
||||
log.Printf("searched %d states; queued %d states", numState, m.numState)
|
||||
return "", ErrNoMatch
|
||||
|
||||
Found:
|
||||
var buf []byte
|
||||
if c >= 0 {
|
||||
buf = append(buf, byte(c))
|
||||
}
|
||||
for d1 := d; d1.prev != nil; d1= d1.prev {
|
||||
buf = append(buf, byte(d1.prevByte))
|
||||
}
|
||||
for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
|
||||
buf[i], buf[j] = buf[j], buf[i]
|
||||
}
|
||||
log.Printf("searched %d states; queued %d states", numState, m.numState)
|
||||
return string(buf), nil
|
||||
}
|
||||
103
vendor/github.com/mattermost/rsc/regexp/regmerge/merge.go
сгенерированный
поставляемый
103
vendor/github.com/mattermost/rsc/regexp/regmerge/merge.go
сгенерированный
поставляемый
@@ -1,103 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Code to merge (join) multiple regexp progs into a single prog.
|
||||
// New code; not copied from anywhere.
|
||||
|
||||
package main
|
||||
|
||||
import "regexp/syntax"
|
||||
|
||||
func joinProgs(progs []*syntax.Prog) *syntax.Prog {
|
||||
all := &syntax.Prog{}
|
||||
for i, p := range progs {
|
||||
n := len(all.Inst)
|
||||
all.Inst = append(all.Inst, p.Inst...)
|
||||
match := shiftInst(all.Inst[n:], n)
|
||||
if match < 0 {
|
||||
// no match instruction; give up
|
||||
all.Inst = []syntax.Inst{{Op: syntax.InstFail}}
|
||||
all.Start = 0
|
||||
return all
|
||||
}
|
||||
match += n
|
||||
m := len(all.Inst)
|
||||
all.Inst = append(all.Inst,
|
||||
syntax.Inst{Op: syntax.InstAlt, Out: uint32(p.Start+n), Arg: uint32(m+1)},
|
||||
syntax.Inst{Op: instByteRange, Arg: 0x00FF, Out: uint32(m)},
|
||||
syntax.Inst{Op: instByteRange, Arg: 0x00FF, Out: uint32(match)},
|
||||
syntax.Inst{Op: syntax.InstMatch},
|
||||
)
|
||||
all.Inst[match] = syntax.Inst{Op: syntax.InstAlt, Out: uint32(m+2), Arg: uint32(m+3)}
|
||||
|
||||
if i == 0 {
|
||||
all.Start = m
|
||||
} else {
|
||||
old := all.Start
|
||||
all.Start = len(all.Inst)
|
||||
all.Inst = append(all.Inst, syntax.Inst{Op: syntax.InstAlt, Out: uint32(old), Arg: uint32(m)})
|
||||
}
|
||||
}
|
||||
|
||||
return all
|
||||
}
|
||||
|
||||
func shiftInst(inst []syntax.Inst, n int) int {
|
||||
match := -1
|
||||
for i := range inst {
|
||||
ip := &inst[i]
|
||||
ip.Out += uint32(n)
|
||||
if ip.Op == syntax.InstMatch {
|
||||
if match >= 0 {
|
||||
panic("double match")
|
||||
}
|
||||
match = i
|
||||
}
|
||||
if ip.Op == syntax.InstAlt || ip.Op == syntax.InstAltMatch {
|
||||
ip.Arg += uint32(n)
|
||||
}
|
||||
}
|
||||
return match
|
||||
}
|
||||
|
||||
func (m *matcher) crunchProg() {
|
||||
var rewrite [256]byte
|
||||
|
||||
for i := range m.prog.Inst {
|
||||
ip := &m.prog.Inst[i]
|
||||
switch ip.Op {
|
||||
case instByteRange:
|
||||
lo, hi := byte(ip.Arg>>8), byte(ip.Arg)
|
||||
rewrite[lo] = 1
|
||||
if hi < 255 {
|
||||
rewrite[hi+1] = 1
|
||||
}
|
||||
case syntax.InstEmptyWidth:
|
||||
switch op := syntax.EmptyOp(ip.Arg); {
|
||||
case op&(syntax.EmptyBeginLine|syntax.EmptyEndLine) != 0:
|
||||
rewrite['\n'] = 1
|
||||
rewrite['\n'+1] = 1
|
||||
case op&(syntax.EmptyWordBoundary|syntax.EmptyNoWordBoundary) != 0:
|
||||
rewrite['A'] = 1
|
||||
rewrite['Z'+1] = 1
|
||||
rewrite['a'] = 1
|
||||
rewrite['z'+1] = 1
|
||||
rewrite['0'] = 1
|
||||
rewrite['9'+1] = 1
|
||||
rewrite['_'] = 1
|
||||
rewrite['_'+1] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rewrite[0] = 0
|
||||
for i := 1; i < 256; i++ {
|
||||
rewrite[i] += rewrite[i-1]
|
||||
}
|
||||
m.numByte = int(rewrite[255]) + 1
|
||||
|
||||
for i := 255; i >= 0; i-- {
|
||||
m.undo[rewrite[i]] = byte(i)
|
||||
}
|
||||
}
|
||||
199
vendor/github.com/mattermost/rsc/regexp/regmerge/sort.go
сгенерированный
поставляемый
199
vendor/github.com/mattermost/rsc/regexp/regmerge/sort.go
сгенерированный
поставляемый
@@ -1,199 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// Copy of go/src/pkg/sort/sort.go, specialized for []int
|
||||
// and to remove some array indexing.
|
||||
|
||||
package main
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Insertion sort
|
||||
func insertionSort(data []int, a, b int) {
|
||||
for i := a + 1; i < b; i++ {
|
||||
for j := i; j > a && data[j] < data[j-1]; j-- {
|
||||
data[j], data[j-1] = data[j-1], data[j]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// siftDown implements the heap property on data[lo, hi).
|
||||
// first is an offset into the array where the root of the heap lies.
|
||||
func siftDown(data []int, lo, hi, first int) {
|
||||
root := lo
|
||||
for {
|
||||
child := 2*root + 1
|
||||
if child >= hi {
|
||||
break
|
||||
}
|
||||
if child+1 < hi && data[first+child] < data[first+child+1] {
|
||||
child++
|
||||
}
|
||||
if !(data[first+root] < data[first+child]) {
|
||||
return
|
||||
}
|
||||
data[first+root], data[first+child] = data[first+child], data[first+root]
|
||||
root = child
|
||||
}
|
||||
}
|
||||
|
||||
func heapSort(data []int, a, b int) {
|
||||
first := a
|
||||
lo := 0
|
||||
hi := b - a
|
||||
|
||||
// Build heap with greatest element at top.
|
||||
for i := (hi - 1) / 2; i >= 0; i-- {
|
||||
siftDown(data, i, hi, first)
|
||||
}
|
||||
|
||||
// Pop elements, largest first, into end of data.
|
||||
for i := hi - 1; i >= 0; i-- {
|
||||
data[first], data[first+i] = data[first+i], data[first]
|
||||
siftDown(data, lo, i, first)
|
||||
}
|
||||
}
|
||||
|
||||
// Quicksort, following Bentley and McIlroy,
|
||||
// ``Engineering a Sort Function,'' SP&E November 1993.
|
||||
|
||||
// medianOfThree moves the median of the three values data[a], data[b], data[c] into data[a].
|
||||
func medianOfThree(data []int, a, b, c int) {
|
||||
m0 := b
|
||||
m1 := a
|
||||
m2 := c
|
||||
// bubble sort on 3 elements
|
||||
if data[m1] < data[m0] {
|
||||
data[m1], data[m0] = data[m0], data[m1]
|
||||
}
|
||||
if data[m2] < data[m1] {
|
||||
data[m2], data[m1] = data[m1], data[m2]
|
||||
}
|
||||
if data[m1] < data[m0] {
|
||||
data[m1], data[m0] = data[m0], data[m1]
|
||||
}
|
||||
// now data[m0] <= data[m1] <= data[m2]
|
||||
}
|
||||
|
||||
func swapRange(data []int, a, b, n int) {
|
||||
for i := 0; i < n; i++ {
|
||||
data[a+i], data[b+i] = data[b+i], data[a+i]
|
||||
}
|
||||
}
|
||||
|
||||
func doPivot(data []int, lo, hi int) (midlo, midhi int) {
|
||||
m := lo + (hi-lo)/2 // Written like this to avoid integer overflow.
|
||||
if hi-lo > 40 {
|
||||
// Tukey's ``Ninther,'' median of three medians of three.
|
||||
s := (hi - lo) / 8
|
||||
medianOfThree(data, lo, lo+s, lo+2*s)
|
||||
medianOfThree(data, m, m-s, m+s)
|
||||
medianOfThree(data, hi-1, hi-1-s, hi-1-2*s)
|
||||
}
|
||||
medianOfThree(data, lo, m, hi-1)
|
||||
|
||||
// Invariants are:
|
||||
// data[lo] = pivot (set up by ChoosePivot)
|
||||
// data[lo <= i < a] = pivot
|
||||
// data[a <= i < b] < pivot
|
||||
// data[b <= i < c] is unexamined
|
||||
// data[c <= i < d] > pivot
|
||||
// data[d <= i < hi] = pivot
|
||||
//
|
||||
// Once b meets c, can swap the "= pivot" sections
|
||||
// into the middle of the slice.
|
||||
pivot := lo
|
||||
a, b, c, d := lo+1, lo+1, hi, hi
|
||||
dpivot := data[pivot]
|
||||
db, dc1 := data[b], data[c-1]
|
||||
for b < c {
|
||||
if db < dpivot { // data[b] < pivot
|
||||
b++
|
||||
if b < c {
|
||||
db = data[b]
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !(dpivot < db) { // data[b] = pivot
|
||||
data[a], data[b] = db, data[a]
|
||||
a++
|
||||
b++
|
||||
if b < c {
|
||||
db = data[b]
|
||||
}
|
||||
continue
|
||||
}
|
||||
if dpivot < dc1 { // data[c-1] > pivot
|
||||
c--
|
||||
if c > 0 {
|
||||
dc1 = data[c-1]
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !(dc1 < dpivot) { // data[c-1] = pivot
|
||||
data[c-1], data[d-1] = data[d-1], dc1
|
||||
c--
|
||||
d--
|
||||
if c > 0 {
|
||||
dc1 = data[c-1]
|
||||
}
|
||||
continue
|
||||
}
|
||||
// data[b] > pivot; data[c-1] < pivot
|
||||
data[b], data[c-1] = dc1, db
|
||||
b++
|
||||
c--
|
||||
if b < c {
|
||||
db = data[b]
|
||||
dc1 = data[c-1]
|
||||
}
|
||||
}
|
||||
|
||||
n := min(b-a, a-lo)
|
||||
swapRange(data, lo, b-n, n)
|
||||
|
||||
n = min(hi-d, d-c)
|
||||
swapRange(data, c, hi-n, n)
|
||||
|
||||
return lo + b - a, hi - (d - c)
|
||||
}
|
||||
|
||||
func quickSort(data []int, a, b, maxDepth int) {
|
||||
for b-a > 7 {
|
||||
if maxDepth == 0 {
|
||||
heapSort(data, a, b)
|
||||
return
|
||||
}
|
||||
maxDepth--
|
||||
mlo, mhi := doPivot(data, a, b)
|
||||
// Avoiding recursion on the larger subproblem guarantees
|
||||
// a stack depth of at most lg(b-a).
|
||||
if mlo-a < b-mhi {
|
||||
quickSort(data, a, mlo, maxDepth)
|
||||
a = mhi // i.e., quickSort(data, mhi, b)
|
||||
} else {
|
||||
quickSort(data, mhi, b, maxDepth)
|
||||
b = mlo // i.e., quickSort(data, a, mlo)
|
||||
}
|
||||
}
|
||||
if b-a > 1 {
|
||||
insertionSort(data, a, b)
|
||||
}
|
||||
}
|
||||
|
||||
func sortInts(data []int) {
|
||||
// Switch to heapsort if depth of 2*ceil(lg(n)) is reached.
|
||||
n := len(data)
|
||||
maxDepth := 0
|
||||
for 1<<uint(maxDepth) < n {
|
||||
maxDepth++
|
||||
}
|
||||
maxDepth *= 2
|
||||
quickSort(data, 0, n, maxDepth)
|
||||
}
|
||||
80
vendor/github.com/mattermost/rsc/regexp/regmerge/sparse.go
сгенерированный
поставляемый
80
vendor/github.com/mattermost/rsc/regexp/regmerge/sparse.go
сгенерированный
поставляемый
@@ -1,80 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Copied from code.google.com/p/codesearch/sparse/set.go,
|
||||
// tweaked for better inlinability.
|
||||
|
||||
package main
|
||||
|
||||
// For comparison: running cindex over the Linux 2.6 kernel with this
|
||||
// implementation of trigram sets takes 11 seconds. If I change it to
|
||||
// a bitmap (which must be cleared between files) it takes 25 seconds.
|
||||
|
||||
// A Set is a sparse set of uint32 values.
|
||||
// http://research.swtch.com/2008/03/using-uninitialized-memory-for-fun-and.html
|
||||
type Set struct {
|
||||
dense []uint32
|
||||
sparse []uint32
|
||||
}
|
||||
|
||||
// NewSet returns a new Set with a given maximum size.
|
||||
// The set can contain numbers in [0, max-1].
|
||||
func NewSet(max uint32) *Set {
|
||||
return &Set{
|
||||
sparse: make([]uint32, max),
|
||||
}
|
||||
}
|
||||
|
||||
// Init initializes a Set to have a given maximum size.
|
||||
// The set can contain numbers in [0, max-1].
|
||||
func (s *Set) Init(max uint32) {
|
||||
s.sparse = make([]uint32, max)
|
||||
}
|
||||
|
||||
// Reset clears (empties) the set.
|
||||
func (s *Set) Reset() {
|
||||
s.dense = s.dense[:0]
|
||||
}
|
||||
|
||||
// Add adds x to the set if it is not already there.
|
||||
//
|
||||
// TODO: The ugly additional variables v and n make the
|
||||
// function inlinable. When the 6g inliner gets better
|
||||
// they will not be necessary.
|
||||
func (s *Set) Add(x uint32, v uint32, n int) {
|
||||
v = s.sparse[x]
|
||||
if v < uint32(len(s.dense)) && s.dense[v] == x {
|
||||
return
|
||||
}
|
||||
n = len(s.dense)
|
||||
s.sparse[x] = uint32(n)
|
||||
s.dense = append(s.dense, x)
|
||||
}
|
||||
|
||||
func (s *Set) MustAdd(x uint32) {
|
||||
s.sparse[x] = uint32(len(s.dense))
|
||||
s.dense = append(s.dense, x)
|
||||
}
|
||||
|
||||
// Has reports whether x is in the set.
|
||||
//
|
||||
// TODO: The ugly additional variables v makes
|
||||
// function inlinable. When the 6g inliner gets better
|
||||
// it will not be necessary.
|
||||
func (s *Set) Has(x uint32, v uint32) bool {
|
||||
v = s.sparse[x]
|
||||
return v < uint32(len(s.dense)) && s.dense[v] == x
|
||||
}
|
||||
|
||||
// Dense returns the values in the set.
|
||||
// The values are listed in the order in which they
|
||||
// were inserted.
|
||||
func (s *Set) Dense() []uint32 {
|
||||
return s.dense
|
||||
}
|
||||
|
||||
// Len returns the number of values in the set.
|
||||
func (s *Set) Len() int {
|
||||
return len(s.dense)
|
||||
}
|
||||
270
vendor/github.com/mattermost/rsc/regexp/regmerge/utf.go
сгенерированный
поставляемый
270
vendor/github.com/mattermost/rsc/regexp/regmerge/utf.go
сгенерированный
поставляемый
@@ -1,270 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Copy of code.google.com/p/codesearch/regexp/utf.go.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"regexp/syntax"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
instFail = syntax.InstFail
|
||||
instAlt = syntax.InstAlt
|
||||
instByteRange = syntax.InstRune | 0x80 // local opcode
|
||||
|
||||
argFold = 1 << 16
|
||||
)
|
||||
|
||||
func toByteProg(prog *syntax.Prog) error {
|
||||
var b runeBuilder
|
||||
for pc := range prog.Inst {
|
||||
i := &prog.Inst[pc]
|
||||
switch i.Op {
|
||||
case syntax.InstRune, syntax.InstRune1:
|
||||
// General rune range. PIA.
|
||||
// TODO: Pick off single-byte case.
|
||||
if lo, hi, fold, ok := oneByteRange(i); ok {
|
||||
i.Op = instByteRange
|
||||
i.Arg = uint32(lo)<<8 | uint32(hi)
|
||||
if fold {
|
||||
i.Arg |= argFold
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
r := i.Rune
|
||||
if syntax.Flags(i.Arg)&syntax.FoldCase != 0 {
|
||||
// Build folded list.
|
||||
var rr []rune
|
||||
if len(r) == 1 {
|
||||
rr = appendFoldedRange(rr, r[0], r[0])
|
||||
} else {
|
||||
for j := 0; j < len(r); j += 2 {
|
||||
rr = appendFoldedRange(rr, r[j], r[j+1])
|
||||
}
|
||||
}
|
||||
r = rr
|
||||
}
|
||||
|
||||
b.init(prog, uint32(pc), i.Out)
|
||||
if len(r) == 1 {
|
||||
b.addRange(r[0], r[0], false)
|
||||
} else {
|
||||
for j := 0; j < len(r); j += 2 {
|
||||
b.addRange(r[j], r[j+1], false)
|
||||
}
|
||||
}
|
||||
|
||||
case syntax.InstRuneAny, syntax.InstRuneAnyNotNL:
|
||||
// All runes.
|
||||
// AnyNotNL should exclude \n but the line-at-a-time
|
||||
// execution takes care of that for us.
|
||||
b.init(prog, uint32(pc), i.Out)
|
||||
b.addRange(0, unicode.MaxRune, false)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func oneByteRange(i *syntax.Inst) (lo, hi byte, fold, ok bool) {
|
||||
if i.Op == syntax.InstRune1 {
|
||||
r := i.Rune[0]
|
||||
if r < utf8.RuneSelf {
|
||||
return byte(r), byte(r), false, true
|
||||
}
|
||||
}
|
||||
if i.Op != syntax.InstRune {
|
||||
return
|
||||
}
|
||||
fold = syntax.Flags(i.Arg)&syntax.FoldCase != 0
|
||||
if len(i.Rune) == 1 || len(i.Rune) == 2 && i.Rune[0] == i.Rune[1] {
|
||||
r := i.Rune[0]
|
||||
if r >= utf8.RuneSelf {
|
||||
return
|
||||
}
|
||||
if fold && !asciiFold(r) {
|
||||
return
|
||||
}
|
||||
return byte(r), byte(r), fold, true
|
||||
}
|
||||
if len(i.Rune) == 2 && i.Rune[1] < utf8.RuneSelf {
|
||||
if fold {
|
||||
for r := i.Rune[0]; r <= i.Rune[1]; r++ {
|
||||
if asciiFold(r) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
return byte(i.Rune[0]), byte(i.Rune[1]), fold, true
|
||||
}
|
||||
if len(i.Rune) == 4 && i.Rune[0] == i.Rune[1] && i.Rune[2] == i.Rune[3] && unicode.SimpleFold(i.Rune[0]) == i.Rune[2] && unicode.SimpleFold(i.Rune[2]) == i.Rune[0] {
|
||||
return byte(i.Rune[0]), byte(i.Rune[0]), true, true
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func asciiFold(r rune) bool {
|
||||
if r >= utf8.RuneSelf {
|
||||
return false
|
||||
}
|
||||
r1 := unicode.SimpleFold(r)
|
||||
if r1 >= utf8.RuneSelf {
|
||||
return false
|
||||
}
|
||||
if r1 == r {
|
||||
return true
|
||||
}
|
||||
return unicode.SimpleFold(r1) == r
|
||||
}
|
||||
|
||||
func maxRune(n int) rune {
|
||||
b := 0
|
||||
if n == 1 {
|
||||
b = 7
|
||||
} else {
|
||||
b = 8 - (n + 1) + 6*(n-1)
|
||||
}
|
||||
return 1<<uint(b) - 1
|
||||
}
|
||||
|
||||
type cacheKey struct {
|
||||
lo, hi uint8
|
||||
fold bool
|
||||
next uint32
|
||||
}
|
||||
|
||||
type runeBuilder struct {
|
||||
begin uint32
|
||||
out uint32
|
||||
cache map[cacheKey]uint32
|
||||
p *syntax.Prog
|
||||
}
|
||||
|
||||
func (b *runeBuilder) init(p *syntax.Prog, begin, out uint32) {
|
||||
// We will rewrite p.Inst[begin] to hold the accumulated
|
||||
// machine. For now, there is no match.
|
||||
p.Inst[begin].Op = instFail
|
||||
|
||||
b.begin = begin
|
||||
b.out = out
|
||||
if b.cache == nil {
|
||||
b.cache = make(map[cacheKey]uint32)
|
||||
}
|
||||
for k := range b.cache {
|
||||
delete(b.cache, k)
|
||||
}
|
||||
b.p = p
|
||||
}
|
||||
|
||||
func (b *runeBuilder) uncachedSuffix(lo, hi byte, fold bool, next uint32) uint32 {
|
||||
if next == 0 {
|
||||
next = b.out
|
||||
}
|
||||
pc := len(b.p.Inst)
|
||||
i := syntax.Inst{Op: instByteRange, Arg: uint32(lo)<<8 | uint32(hi), Out: next}
|
||||
if fold {
|
||||
i.Arg |= argFold
|
||||
}
|
||||
b.p.Inst = append(b.p.Inst, i)
|
||||
return uint32(pc)
|
||||
}
|
||||
|
||||
func (b *runeBuilder) suffix(lo, hi byte, fold bool, next uint32) uint32 {
|
||||
if lo < 0x80 || hi > 0xbf {
|
||||
// Not a continuation byte, no need to cache.
|
||||
return b.uncachedSuffix(lo, hi, fold, next)
|
||||
}
|
||||
|
||||
key := cacheKey{lo, hi, fold, next}
|
||||
if pc, ok := b.cache[key]; ok {
|
||||
return pc
|
||||
}
|
||||
|
||||
pc := b.uncachedSuffix(lo, hi, fold, next)
|
||||
b.cache[key] = pc
|
||||
return pc
|
||||
}
|
||||
|
||||
func (b *runeBuilder) addBranch(pc uint32) {
|
||||
// Add pc to the branch at the beginning.
|
||||
i := &b.p.Inst[b.begin]
|
||||
switch i.Op {
|
||||
case syntax.InstFail:
|
||||
i.Op = syntax.InstNop
|
||||
i.Out = pc
|
||||
return
|
||||
case syntax.InstNop:
|
||||
i.Op = syntax.InstAlt
|
||||
i.Arg = pc
|
||||
return
|
||||
case syntax.InstAlt:
|
||||
apc := uint32(len(b.p.Inst))
|
||||
b.p.Inst = append(b.p.Inst, syntax.Inst{Op: instAlt, Out: i.Arg, Arg: pc})
|
||||
i = &b.p.Inst[b.begin]
|
||||
i.Arg = apc
|
||||
b.begin = apc
|
||||
}
|
||||
}
|
||||
|
||||
func (b *runeBuilder) addRange(lo, hi rune, fold bool) {
|
||||
if lo > hi {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: Pick off 80-10FFFF for special handling?
|
||||
if lo == 0x80 && hi == 0x10FFFF {
|
||||
}
|
||||
|
||||
// Split range into same-length sized ranges.
|
||||
for i := 1; i < utf8.UTFMax; i++ {
|
||||
max := maxRune(i)
|
||||
if lo <= max && max < hi {
|
||||
b.addRange(lo, max, fold)
|
||||
b.addRange(max+1, hi, fold)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// ASCII range is special.
|
||||
if hi < utf8.RuneSelf {
|
||||
b.addBranch(b.suffix(byte(lo), byte(hi), fold, 0))
|
||||
return
|
||||
}
|
||||
|
||||
// Split range into sections that agree on leading bytes.
|
||||
for i := 1; i < utf8.UTFMax; i++ {
|
||||
m := rune(1)<<uint(6*i) - 1 // last i bytes of UTF-8 sequence
|
||||
if lo&^m != hi&^m {
|
||||
if lo&m != 0 {
|
||||
b.addRange(lo, lo|m, fold)
|
||||
b.addRange((lo|m)+1, hi, fold)
|
||||
return
|
||||
}
|
||||
if hi&m != m {
|
||||
b.addRange(lo, hi&^m-1, fold)
|
||||
b.addRange(hi&^m, hi, fold)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally. Generate byte matching equivalent for lo-hi.
|
||||
var ulo, uhi [utf8.UTFMax]byte
|
||||
n := utf8.EncodeRune(ulo[:], lo)
|
||||
m := utf8.EncodeRune(uhi[:], hi)
|
||||
if n != m {
|
||||
panic("codesearch/regexp: bad utf-8 math")
|
||||
}
|
||||
|
||||
pc := uint32(0)
|
||||
for i := n - 1; i >= 0; i-- {
|
||||
pc = b.suffix(ulo[i], uhi[i], false, pc)
|
||||
}
|
||||
b.addBranch(pc)
|
||||
}
|
||||
7
vendor/github.com/mattermost/rsc/rosetta/graph/Makefile
сгенерированный
поставляемый
7
vendor/github.com/mattermost/rsc/rosetta/graph/Makefile
сгенерированный
поставляемый
@@ -1,7 +0,0 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=rsc.googlecode.com/hg/rosetta/graph
|
||||
GOFILES=\
|
||||
graph.go\
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
||||
133
vendor/github.com/mattermost/rsc/rosetta/graph/graph.go
сгенерированный
поставляемый
133
vendor/github.com/mattermost/rsc/rosetta/graph/graph.go
сгенерированный
поставляемый
@@ -1,133 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Simple demonstration of a graph interface and
|
||||
// Dijkstra's algorithm built on top of that interface,
|
||||
// without using inheritance.
|
||||
|
||||
package graph
|
||||
|
||||
import "container/heap"
|
||||
|
||||
// A Graph is the interface implemented by graphs that
|
||||
// this package can run algorithms on.
|
||||
type Graph interface {
|
||||
// NumVertex returns the number of vertices in the graph.
|
||||
NumVertex() int
|
||||
|
||||
// VertexID returns a vertex ID, 0 <= ID < NumVertex(), for v.
|
||||
VertexID(v Vertex) int
|
||||
|
||||
// Neighbors returns a slice of vertices that are adjacent
|
||||
// to v in the graph.
|
||||
Neighbors(v Vertex) []Vertex
|
||||
}
|
||||
|
||||
type Vertex interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
// ShortestPath uses Dijkstra's algorithm to find the shortest
|
||||
// path from start to end in g. It returns the path as a slice of
|
||||
// vertices, with start first and end last. If there is no path,
|
||||
// ShortestPath returns nil.
|
||||
func ShortestPath(g Graph, start, end Vertex) []Vertex {
|
||||
d := newDijkstra(g)
|
||||
|
||||
d.visit(start, 1, nil)
|
||||
for !d.empty() {
|
||||
p := d.next()
|
||||
if g.VertexID(p.v) == g.VertexID(end) {
|
||||
break
|
||||
}
|
||||
for _, v := range g.Neighbors(p.v) {
|
||||
d.visit(v, p.depth+1, p)
|
||||
}
|
||||
}
|
||||
|
||||
p := d.pos(end)
|
||||
if p.depth == 0 {
|
||||
// unvisited - no path
|
||||
return nil
|
||||
}
|
||||
path := make([]Vertex, p.depth)
|
||||
for ; p != nil; p = p.parent {
|
||||
path[p.depth-1] = p.v
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// A dpos is a position in the Dijkstra traversal.
|
||||
type dpos struct {
|
||||
depth int
|
||||
heapIndex int
|
||||
v Vertex
|
||||
parent *dpos
|
||||
}
|
||||
|
||||
// A dijkstra is the Dijkstra traversal's work state.
|
||||
// It contains the heap queue and per-vertex information.
|
||||
type dijkstra struct {
|
||||
g Graph
|
||||
q []*dpos
|
||||
byID []dpos
|
||||
}
|
||||
|
||||
func newDijkstra(g Graph) *dijkstra {
|
||||
d := &dijkstra{g: g}
|
||||
d.byID = make([]dpos, g.NumVertex())
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *dijkstra) pos(v Vertex) *dpos {
|
||||
p := &d.byID[d.g.VertexID(v)]
|
||||
p.v = v // in case this is the first time we've seen it
|
||||
return p
|
||||
}
|
||||
|
||||
func (d *dijkstra) visit(v Vertex, depth int, parent *dpos) {
|
||||
p := d.pos(v)
|
||||
if p.depth == 0 {
|
||||
p.parent = parent
|
||||
p.depth = depth
|
||||
heap.Push(d, p)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *dijkstra) empty() bool {
|
||||
return len(d.q) == 0
|
||||
}
|
||||
|
||||
func (d *dijkstra) next() *dpos {
|
||||
return heap.Pop(d).(*dpos)
|
||||
}
|
||||
|
||||
// Implementation of heap.Interface
|
||||
func (d *dijkstra) Len() int {
|
||||
return len(d.q)
|
||||
}
|
||||
|
||||
func (d *dijkstra) Less(i, j int) bool {
|
||||
return d.q[i].depth < d.q[j].depth
|
||||
}
|
||||
|
||||
func (d *dijkstra) Swap(i, j int) {
|
||||
d.q[i], d.q[j] = d.q[j], d.q[i]
|
||||
d.q[i].heapIndex = i
|
||||
d.q[j].heapIndex = j
|
||||
}
|
||||
|
||||
func (d *dijkstra) Push(x interface{}) {
|
||||
p := x.(*dpos)
|
||||
p.heapIndex = len(d.q)
|
||||
d.q = append(d.q, p)
|
||||
}
|
||||
|
||||
func (d *dijkstra) Pop() interface{} {
|
||||
n := len(d.q)
|
||||
x := d.q[n-1]
|
||||
d.q = d.q[:n-1]
|
||||
x.heapIndex = -1
|
||||
return x
|
||||
}
|
||||
8
vendor/github.com/mattermost/rsc/rosetta/maze/Makefile
сгенерированный
поставляемый
8
vendor/github.com/mattermost/rsc/rosetta/maze/Makefile
сгенерированный
поставляемый
@@ -1,8 +0,0 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=maze
|
||||
GOFILES=\
|
||||
maze.go\
|
||||
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
|
||||
191
vendor/github.com/mattermost/rsc/rosetta/maze/maze.go
сгенерированный
поставляемый
191
vendor/github.com/mattermost/rsc/rosetta/maze/maze.go
сгенерированный
поставляемый
@@ -1,191 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// Rosetta Code-inspired maze generator and solver.
|
||||
// Demonstrates use of interfaces to separate algorithm
|
||||
// implementations (graph.ShortestPath, heap.*) from data.
|
||||
// (In contrast, multiple inheritance approaches require
|
||||
// you to store their data in your data structures as part
|
||||
// of the inheritance.)
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/rsc/rosetta/graph"
|
||||
)
|
||||
|
||||
type Maze struct {
|
||||
w, h int
|
||||
grid [][]walls
|
||||
}
|
||||
|
||||
type Dir uint
|
||||
|
||||
const (
|
||||
North Dir = iota
|
||||
East
|
||||
West
|
||||
South
|
||||
)
|
||||
|
||||
type walls uint8
|
||||
|
||||
const allWalls walls = 1<<North | 1<<East | 1<<South | 1<<West
|
||||
|
||||
var dirs = []struct {
|
||||
δx, δy int
|
||||
}{
|
||||
{0, -1},
|
||||
{1, 0},
|
||||
{-1, 0},
|
||||
{0, 1},
|
||||
}
|
||||
|
||||
// move returns the cell in the direction dir from position r, c.
|
||||
// It returns ok==false if there is no cell in that direction.
|
||||
func (m *Maze) move(x, y int, dir Dir) (nx, ny int, ok bool) {
|
||||
nx = x + dirs[dir].δx
|
||||
ny = y + dirs[dir].δy
|
||||
ok = 0 <= nx && nx < m.w && 0 <= ny && ny < m.h
|
||||
return
|
||||
}
|
||||
|
||||
// Move returns the cell in the direction dir from position x, y
|
||||
// It returns ok==false if there is no cell in that direction
|
||||
// or if a wall blocks movement in that direction.
|
||||
func (m *Maze) Move(x, y int, dir Dir) (nx, ny int, ok bool) {
|
||||
nx, ny, ok = m.move(x, y, dir)
|
||||
ok = ok && m.grid[y][x]&(1<<dir) == 0
|
||||
return
|
||||
}
|
||||
|
||||
// NewMaze returns a new, randomly generated maze
|
||||
// of width w and height h.
|
||||
func NewMaze(w, h int) *Maze {
|
||||
// Allocate one slice for the whole 2-d cell grid and break up into rows.
|
||||
all := make([]walls, w*h)
|
||||
for i := range all {
|
||||
all[i] = allWalls
|
||||
}
|
||||
m := &Maze{w: w, h: h, grid: make([][]walls, h)}
|
||||
for i := range m.grid {
|
||||
m.grid[i], all = all[:w], all[w:]
|
||||
}
|
||||
|
||||
// All cells start with all walls.
|
||||
m.generate(rand.Intn(w), rand.Intn(h))
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Maze) generate(x, y int) {
|
||||
i := rand.Intn(4)
|
||||
for j := 0; j < 4; j++ {
|
||||
dir := Dir(i+j) % 4
|
||||
if nx, ny, ok := m.move(x, y, dir); ok && m.grid[ny][nx] == allWalls {
|
||||
// break down wall
|
||||
m.grid[y][x] &^= 1 << dir
|
||||
m.grid[ny][nx] &^= 1 << (3 - dir)
|
||||
m.generate(nx, ny)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// String returns a multi-line string representation of the maze.
|
||||
func (m *Maze) String() string {
|
||||
return m.PathString(nil)
|
||||
}
|
||||
|
||||
// PathString returns the multi-line string representation of the
|
||||
// maze with the path marked on it.
|
||||
func (m *Maze) PathString(path []graph.Vertex) string {
|
||||
var b bytes.Buffer
|
||||
wall := func(w, m walls, ch byte) {
|
||||
if w&m != 0 {
|
||||
b.WriteByte(ch)
|
||||
} else {
|
||||
b.WriteByte(' ')
|
||||
}
|
||||
}
|
||||
for _, row := range m.grid {
|
||||
b.WriteByte('+')
|
||||
for _, cell := range row {
|
||||
wall(cell, 1<<North, '-')
|
||||
b.WriteByte('+')
|
||||
}
|
||||
b.WriteString("\n")
|
||||
for _, cell := range row {
|
||||
wall(cell, 1<<West, '|')
|
||||
b.WriteByte(' ')
|
||||
}
|
||||
b.WriteString("|\n")
|
||||
}
|
||||
for i := 0; i < m.w; i++ {
|
||||
b.WriteString("++")
|
||||
}
|
||||
b.WriteString("+")
|
||||
grid := b.Bytes()
|
||||
|
||||
// Overlay path.
|
||||
last := -1
|
||||
for _, v := range path {
|
||||
p := v.(pos)
|
||||
i := (2*m.w+2)*(2*p.y+1) + 2*p.x + 1
|
||||
grid[i] = '#'
|
||||
if last != -1 {
|
||||
grid[(i+last)/2] = '#'
|
||||
}
|
||||
last = i
|
||||
}
|
||||
|
||||
return string(grid)
|
||||
}
|
||||
|
||||
// Implement graph.Graph.
|
||||
|
||||
type pos struct {
|
||||
x, y int
|
||||
}
|
||||
|
||||
func (p pos) String() string {
|
||||
return fmt.Sprintf("%d,%d", p.x, p.y)
|
||||
}
|
||||
|
||||
func (m *Maze) Neighbors(v graph.Vertex) []graph.Vertex {
|
||||
p := v.(pos)
|
||||
var neighbors []graph.Vertex
|
||||
for dir := North; dir <= South; dir++ {
|
||||
if nx, ny, ok := m.Move(p.x, p.y, dir); ok {
|
||||
neighbors = append(neighbors, pos{nx, ny})
|
||||
}
|
||||
}
|
||||
return neighbors
|
||||
}
|
||||
|
||||
func (m *Maze) NumVertex() int {
|
||||
return m.w * m.h
|
||||
}
|
||||
|
||||
func (m *Maze) VertexID(v graph.Vertex) int {
|
||||
p := v.(pos)
|
||||
return p.y*m.w + p.x
|
||||
}
|
||||
|
||||
func (m *Maze) Vertex(x, y int) graph.Vertex {
|
||||
return pos{x, y}
|
||||
}
|
||||
|
||||
func main() {
|
||||
const w, h = 30, 10
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
m := NewMaze(w, h)
|
||||
path := graph.ShortestPath(m, m.Vertex(0, 0), m.Vertex(w-1, h-1))
|
||||
fmt.Println(m.PathString(path))
|
||||
}
|
||||
85
vendor/github.com/mattermost/rsc/s3get/main.go
сгенерированный
поставляемый
85
vendor/github.com/mattermost/rsc/s3get/main.go
сгенерированный
поставляемый
@@ -1,85 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// S3get fetches a single object from or lists the objects in an S3 bucket.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/mattermost/rsc/keychain"
|
||||
"launchpad.net/goamz/aws"
|
||||
"launchpad.net/goamz/s3"
|
||||
)
|
||||
|
||||
var list = flag.Bool("l", false, "list buckets")
|
||||
var delim = flag.String("d", "", "list delimiter")
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, `usage: s3get [-l] bucket path
|
||||
|
||||
s3get fetches a single object from or lists the objects
|
||||
in an S3 bucket.
|
||||
|
||||
The -l flag causes s3get to list available paths.
|
||||
When using -l, path may be omitted.
|
||||
Otherwise the listing begins at path.
|
||||
|
||||
s3get uses the user name and password in the local
|
||||
keychain for the server 's3.amazonaws.com' as the S3
|
||||
access key (user name) and secret key (password).
|
||||
`)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
var buck, obj string
|
||||
args := flag.Args()
|
||||
switch len(args) {
|
||||
case 1:
|
||||
buck = args[0]
|
||||
if !*list {
|
||||
fmt.Fprintf(os.Stderr, "must specify path when not using -l")
|
||||
os.Exit(2)
|
||||
}
|
||||
case 2:
|
||||
buck = args[0]
|
||||
obj = args[1]
|
||||
default:
|
||||
usage()
|
||||
}
|
||||
|
||||
access, secret, err := keychain.UserPasswd("s3.amazonaws.com", "")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
auth := aws.Auth{AccessKey: access, SecretKey: secret}
|
||||
|
||||
b := s3.New(auth, aws.USEast).Bucket(buck)
|
||||
if *list {
|
||||
objs, prefixes, err := b.List("", *delim, obj, 0)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, p := range prefixes {
|
||||
fmt.Printf("%s\n", p)
|
||||
}
|
||||
for _, obj := range objs {
|
||||
fmt.Printf("%s\n", obj.Key)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
data, err := b.Get(obj)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
os.Stdout.Write(data)
|
||||
}
|
||||
542
vendor/github.com/mattermost/rsc/smugmug/smug.go
сгенерированный
поставляемый
542
vendor/github.com/mattermost/rsc/smugmug/smug.go
сгенерированный
поставляемый
@@ -1,542 +0,0 @@
|
||||
// Copyright 2012 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 smugmug uses the SmugMug API to manipulate photo albums
|
||||
// stored on smugmug.com.
|
||||
package smugmug
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const smugUploadHost = "upload.smugmug.com"
|
||||
const smugAPI = "1.2.2"
|
||||
const smugURL = "https://secure.smugmug.com/services/api/json/" + smugAPI + "/"
|
||||
const smugURLUnencrypted = "http://api.smugmug.com/services/api/json/" + smugAPI + "/"
|
||||
|
||||
// A Conn represents an authenticated connection to the SmugMug server.
|
||||
type Conn struct {
|
||||
sessid string
|
||||
apiKey string
|
||||
|
||||
NickName string
|
||||
}
|
||||
|
||||
// A Category represents a single album category.
|
||||
type Category struct {
|
||||
ID int `json:"id"`
|
||||
Name string
|
||||
}
|
||||
|
||||
type smugResult struct {
|
||||
Stat string `json:"stat"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type loginResult struct {
|
||||
Login struct {
|
||||
Session struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
User struct {
|
||||
ID int `json:"id"`
|
||||
NickName string
|
||||
DisplayName string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Login logs into the SmugMug server with the given email address and password.
|
||||
// The apikey argument is the API Key for your application.
|
||||
// To obtain an API Key, see http://www.smugmug.com/hack/apikeys.
|
||||
func Login(email, passwd, apikey string) (*Conn, error) {
|
||||
c := &Conn{}
|
||||
var out loginResult
|
||||
if err := c.do("smugmug.login.withPassword", &out, "APIKey", apikey, "EmailAddress", email, "Password", passwd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.sessid = out.Login.Session.ID
|
||||
if c.sessid == "" {
|
||||
return nil, fmt.Errorf("SmugMug login appeared to succeed but did not return session ID")
|
||||
}
|
||||
|
||||
c.NickName = out.Login.User.NickName
|
||||
if c.NickName == "" {
|
||||
return nil, fmt.Errorf("SmugMug login appeared to succeed but did not return User NickName")
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Categories returns the album categories for the user identified by the nick name.
|
||||
func (c *Conn) Categories(nick string) ([]*Category, error) {
|
||||
var out struct {
|
||||
Categories []*Category
|
||||
}
|
||||
if err := c.do("smugmug.categories.get", &out, "NickName", nick); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Categories, nil
|
||||
}
|
||||
|
||||
// CreateCategory creates a category with the given name.
|
||||
func (c *Conn) CreateCategory(name string) (*Category, error) {
|
||||
var out struct {
|
||||
Category *Category
|
||||
}
|
||||
if err := c.do("smugmug.categories.create", &out, "Name", name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Category, nil
|
||||
}
|
||||
|
||||
// DeleteCategory deletes the category.
|
||||
func (c *Conn) DeleteCategory(cat *Category) error {
|
||||
return c.do("smugmug.categories.delete", nil, "CategoryID", strconv.Itoa(cat.ID))
|
||||
}
|
||||
|
||||
// An Album represents a single photo album.
|
||||
type Album struct {
|
||||
ID int `json:"id"`
|
||||
Key string
|
||||
Title string
|
||||
URL string
|
||||
}
|
||||
|
||||
// Albums returns the albums for the user identified by the nick name.
|
||||
// Use c.NickName for the logged-in user.
|
||||
func (c *Conn) Albums(nick string) ([]*Album, error) {
|
||||
var out struct {
|
||||
Albums []*Album
|
||||
}
|
||||
if err := c.do("smugmug.albums.get", &out, "NickName", nick); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Albums, nil
|
||||
}
|
||||
|
||||
// CreateAlbum creates a new album.
|
||||
func (c *Conn) CreateAlbum(title string) (*Album, error) {
|
||||
var out struct {
|
||||
Album *Album
|
||||
}
|
||||
if err := c.do("smugmug.albums.create", &out,
|
||||
"Title", title,
|
||||
"Public", "0",
|
||||
"WorldSearchable", "0",
|
||||
"SmugSearchable", "0",
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if out.Album == nil || out.Album.Key == "" {
|
||||
return nil, fmt.Errorf("unable to parse SmugMug result")
|
||||
}
|
||||
return out.Album, nil
|
||||
}
|
||||
|
||||
// AlbumInfo returns detailed metadata about an album.
|
||||
func (c *Conn) AlbumInfo(album *Album) (*AlbumInfo, error) {
|
||||
var out struct {
|
||||
Album *AlbumInfo
|
||||
}
|
||||
if err := c.do("smugmug.albums.getInfo", &out,
|
||||
"AlbumID", strconv.Itoa(album.ID),
|
||||
"AlbumKey", album.Key,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if out.Album == nil || out.Album.ID == 0 {
|
||||
return nil, fmt.Errorf("unable to parse SmugMug result")
|
||||
}
|
||||
return out.Album, nil
|
||||
}
|
||||
|
||||
// An AlbumInfo lists the metadata for an album.
|
||||
type AlbumInfo struct {
|
||||
ID int `json:"id"`
|
||||
Key string
|
||||
Title string
|
||||
|
||||
Backprinting string
|
||||
BoutiquePackaging int
|
||||
CanRank bool
|
||||
Category *Category
|
||||
Clean bool
|
||||
ColorCorrection int
|
||||
Comments bool
|
||||
Community struct {
|
||||
ID int `json:"id"`
|
||||
Name string
|
||||
}
|
||||
Description string
|
||||
EXIF bool
|
||||
External bool
|
||||
FamilyEdit bool
|
||||
Filenames bool
|
||||
FriendEdit bool
|
||||
Geography bool
|
||||
Header bool
|
||||
HideOwner bool
|
||||
Highlight struct {
|
||||
ID int `json:"id"`
|
||||
Key string
|
||||
Type string
|
||||
}
|
||||
ImageCount int
|
||||
InterceptShipping int
|
||||
Keywords string
|
||||
Larges bool
|
||||
LastUpdated string
|
||||
NiceName string
|
||||
Originals bool
|
||||
PackagingBranding bool
|
||||
Password string
|
||||
PasswordHint string
|
||||
Passworded bool
|
||||
Position int
|
||||
Printable bool
|
||||
Printmark struct {
|
||||
ID int `json:"id"`
|
||||
Name string
|
||||
}
|
||||
ProofDays int
|
||||
Protected bool
|
||||
Public bool
|
||||
Share bool
|
||||
SmugSearchable bool
|
||||
SortDirection bool
|
||||
SortMethod string
|
||||
SquareThumbs bool
|
||||
SubCategory *Category
|
||||
Template struct {
|
||||
ID int `json:"id"`
|
||||
}
|
||||
Theme struct {
|
||||
ID int `json:"id"`
|
||||
Key string
|
||||
Type string
|
||||
}
|
||||
URL string
|
||||
UnsharpAmount float64
|
||||
UnsharpRadius float64
|
||||
UnsharpSigma float64
|
||||
Watermark struct {
|
||||
ID int `json:"id"`
|
||||
Name string
|
||||
}
|
||||
Watermarking bool
|
||||
WorldSearchable bool
|
||||
X2Larges bool
|
||||
X3Larges bool
|
||||
XLarges bool
|
||||
}
|
||||
|
||||
// ChangeAlbum changes an album's settings.
|
||||
// The argument list is a sequence of key, value pairs.
|
||||
// The keys are the names of AlbumInfo struct fields,
|
||||
// and the values are string values. For a boolean field,
|
||||
// use "0" for false and "1" for true.
|
||||
//
|
||||
// Example:
|
||||
// c.ChangeAlbum(a, "Larges", "1", "Title", "My Album")
|
||||
//
|
||||
func (c *Conn) ChangeAlbum(album *Album, args ...string) error {
|
||||
callArgs := append([]string{"AlbumID", strconv.Itoa(album.ID)}, args...)
|
||||
return c.do("smugmug.albums.changeSettings", nil, callArgs...)
|
||||
}
|
||||
|
||||
// DeleteAlbum deletes an album.
|
||||
func (c *Conn) DeleteAlbum(album *Album) error {
|
||||
return c.do("smugmug.albums.delete", nil, "AlbumID", strconv.Itoa(album.ID))
|
||||
}
|
||||
|
||||
// An Image represents a single SmugMug image.
|
||||
type Image struct {
|
||||
ID int `json:"id"`
|
||||
Key string
|
||||
URL string
|
||||
}
|
||||
|
||||
// Images returns a list of images for an album.
|
||||
func (c *Conn) Images(album *Album) ([]*Image, error) {
|
||||
var out struct {
|
||||
Album struct {
|
||||
Images []*Image
|
||||
}
|
||||
}
|
||||
|
||||
if err := c.do("smugmug.images.get", &out,
|
||||
"AlbumID", strconv.Itoa(album.ID),
|
||||
"AlbumKey", album.Key,
|
||||
"Heavy", "1",
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return out.Album.Images, nil
|
||||
}
|
||||
|
||||
// An ImageInfo lists the metadata for an image.
|
||||
type ImageInfo struct {
|
||||
ID int `json:"id"`
|
||||
Key string
|
||||
Album *Album
|
||||
Altitude int
|
||||
Caption string
|
||||
Date string
|
||||
FileName string
|
||||
Duration int
|
||||
Format string
|
||||
Height int
|
||||
Hidden bool
|
||||
Keywords string
|
||||
LargeURL string
|
||||
LastUpdated string
|
||||
Latitude float64
|
||||
LightboxURL string
|
||||
Longitude float64
|
||||
MD5Sum string
|
||||
MediumURL string
|
||||
OriginalURL string
|
||||
Position int
|
||||
Serial int
|
||||
Size int
|
||||
SmallURL string
|
||||
ThumbURL string
|
||||
TinyURL string
|
||||
Video320URL string
|
||||
Video640URL string
|
||||
Video960URL string
|
||||
Video1280URL string
|
||||
Video1920URL string
|
||||
Width int
|
||||
X2LargeURL string
|
||||
X3LargeURL string
|
||||
XLargeURL string
|
||||
}
|
||||
|
||||
// ImageInfo returns detailed metadata about an image.
|
||||
func (c *Conn) ImageInfo(image *Image) (*ImageInfo, error) {
|
||||
var out struct {
|
||||
Image *ImageInfo
|
||||
}
|
||||
if err := c.do("smugmug.images.getInfo", &out,
|
||||
"ImageID", strconv.Itoa(image.ID),
|
||||
"ImageKey", image.Key,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if out.Image == nil || out.Image.ID == 0 {
|
||||
return nil, fmt.Errorf("unable to parse SmugMug result")
|
||||
}
|
||||
return out.Image, nil
|
||||
}
|
||||
|
||||
// ChangeImage changes an image's settings.
|
||||
// The argument list is a sequence of key, value pairs.
|
||||
// The keys are the names of ImageInfo struct fields,
|
||||
// and the values are string values. For a boolean field,
|
||||
// use "0" for false and "1" for true.
|
||||
//
|
||||
// Example:
|
||||
// c.ChangeImage(a, "Caption", "me!", "Hidden", "0")
|
||||
//
|
||||
func (c *Conn) ChangeImage(image *Image, args ...string) error {
|
||||
callArgs := append([]string{"ImageID", strconv.Itoa(image.ID)}, args...)
|
||||
return c.do("smugmug.images.changeSettings", nil, callArgs...)
|
||||
}
|
||||
|
||||
// An ImageEXIF lists the EXIF data associated with an image.
|
||||
type ImageEXIF struct {
|
||||
ID int `json:"id"`
|
||||
Key string
|
||||
Aperture string
|
||||
Brightness string
|
||||
CCDWidth string
|
||||
ColorSpace int
|
||||
CompressedBitsPerPixel string
|
||||
Contrast int
|
||||
DateTime string
|
||||
DateTimeDigitized string
|
||||
DateTimeOriginal string
|
||||
DigitalZoomRatio string
|
||||
ExposureBiasValue string
|
||||
ExposureMode int
|
||||
ExposureProgram int
|
||||
ExposureTime string
|
||||
Flash int
|
||||
FocalLength string
|
||||
FocalLengthIn35mmFilm string
|
||||
ISO int
|
||||
LightSource int
|
||||
Make string
|
||||
Metering int
|
||||
Model string
|
||||
Saturation int
|
||||
SensingMethod int
|
||||
Sharpness int
|
||||
SubjectDistance string
|
||||
SubjectDistanceRange int
|
||||
WhiteBalance int
|
||||
}
|
||||
|
||||
// ImageInfo returns the EXIF data for an image.
|
||||
func (c *Conn) ImageEXIF(image *Image) (*ImageEXIF, error) {
|
||||
var out struct {
|
||||
Image *ImageEXIF
|
||||
}
|
||||
if err := c.do("smugmug.images.getEXIF", &out,
|
||||
"ImageID", strconv.Itoa(image.ID),
|
||||
"ImageKey", image.Key,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if out.Image == nil || out.Image.ID == 0 {
|
||||
return nil, fmt.Errorf("unable to parse SmugMug result")
|
||||
}
|
||||
return out.Image, nil
|
||||
}
|
||||
|
||||
// DeleteImage deletes an image.
|
||||
func (c *Conn) DeleteImage(image *Image) error {
|
||||
return c.do("smugmug.images.delete", nil, "ImageID", strconv.Itoa(image.ID))
|
||||
}
|
||||
|
||||
// AddImage uploads a new image to an album.
|
||||
// The name is the file name that will be displayed on SmugMug.
|
||||
// The data is the raw image data.
|
||||
func (c *Conn) AddImage(name string, data []byte, a *Album) (*Image, error) {
|
||||
return c.upload(name, data, "AlbumID", a.ID)
|
||||
}
|
||||
|
||||
// ReplaceImage replaces an image.
|
||||
// The name is the file name that will be displayed on SmugMug.
|
||||
// The data is the raw image data.
|
||||
func (c *Conn) ReplaceImage(name string, data []byte, image *Image) (*Image, error) {
|
||||
return c.upload(name, data, "ImageID", image.ID)
|
||||
}
|
||||
|
||||
func (c *Conn) upload(name string, data []byte, idkind string, id int) (*Image, error) {
|
||||
h := md5.New()
|
||||
h.Write(data)
|
||||
digest := fmt.Sprintf("%x", h.Sum(nil))
|
||||
|
||||
req := &http.Request{
|
||||
Method: "PUT",
|
||||
URL: &url.URL{
|
||||
Scheme: "http",
|
||||
Host: smugUploadHost,
|
||||
Path: "/" + name,
|
||||
},
|
||||
ContentLength: int64(len(data)),
|
||||
Header: http.Header{
|
||||
"Content-MD5": {digest},
|
||||
"X-Smug-SessionID": {c.sessid},
|
||||
"X-Smug-Version": {smugAPI},
|
||||
"X-Smug-ResponseType": {"JSON"},
|
||||
"X-Smug-" + idkind: {strconv.Itoa(id)},
|
||||
"X-Smug-FileName": {name},
|
||||
},
|
||||
Body: ioutil.NopCloser(bytes.NewBuffer(data)),
|
||||
}
|
||||
|
||||
r, err := http.DefaultTransport.RoundTrip(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("upload %s: %s", name, err)
|
||||
}
|
||||
|
||||
var out struct {
|
||||
Image *Image
|
||||
}
|
||||
if err := c.parseResult("upload", r, &out); err != nil {
|
||||
return nil, fmt.Errorf("upload %s: %s", name, err)
|
||||
}
|
||||
return out.Image, nil
|
||||
}
|
||||
|
||||
func (c *Conn) do(method string, dst interface{}, args ...string) (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%s: %s", method, err)
|
||||
}
|
||||
}()
|
||||
|
||||
form := url.Values{
|
||||
"method": {method},
|
||||
"APIKey": {c.apiKey},
|
||||
"Pretty": {"1"}, // nice-looking JSON
|
||||
}
|
||||
if c.sessid != "" {
|
||||
form["SessionID"] = []string{c.sessid}
|
||||
}
|
||||
for i := 0; i < len(args); i += 2 {
|
||||
key, val := args[i], args[i+1]
|
||||
form[key] = []string{val}
|
||||
}
|
||||
|
||||
url := smugURL
|
||||
if !strings.Contains(method, "login") {
|
||||
// I'd really prefer to use HTTPS for everything,
|
||||
// but I get "invalid API key" if I do.
|
||||
url = smugURLUnencrypted
|
||||
}
|
||||
r, err := http.Post(url, "application/x-www-form-urlencoded", strings.NewReader(form.Encode()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.parseResult(method, r, dst)
|
||||
}
|
||||
|
||||
func (c *Conn) parseResult(method string, r *http.Response, dst interface{}) error {
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode != 200 {
|
||||
return fmt.Errorf("HTTP %s", r.Status)
|
||||
}
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading body: %s", err)
|
||||
}
|
||||
|
||||
var res smugResult
|
||||
if err := json.Unmarshal(data, &res); err != nil {
|
||||
return fmt.Errorf("parsing JSON result: %s", err)
|
||||
}
|
||||
|
||||
// If there are no images, that's not an error.
|
||||
// But SmugMug says it is.
|
||||
if res.Stat == "fail" && method == "smugmug.images.get" && res.Message == "empty set - no images found" {
|
||||
res.Stat = "ok"
|
||||
data = []byte(`{"Images": []}`)
|
||||
}
|
||||
|
||||
if res.Stat != "ok" {
|
||||
msg := res.Stat
|
||||
if res.Message != "" {
|
||||
msg = res.Message
|
||||
}
|
||||
return fmt.Errorf("%s", msg)
|
||||
}
|
||||
|
||||
if dst != nil {
|
||||
if err := json.Unmarshal(data, dst); err != nil {
|
||||
return fmt.Errorf("parsing JSON result: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
158
vendor/github.com/mattermost/rsc/smugmug/smugup/main.go
сгенерированный
поставляемый
158
vendor/github.com/mattermost/rsc/smugmug/smugup/main.go
сгенерированный
поставляемый
@@ -1,158 +0,0 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
// Smugup uploads a collection of photos to SmugMug.
|
||||
//
|
||||
// Run 'smugup -help' for details.
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mattermost/rsc/keychain"
|
||||
"github.com/mattermost/rsc/smugmug"
|
||||
)
|
||||
|
||||
const apiKey = "8qH4UgiunBKpsYpvcBXftbCYNEreAZ0m"
|
||||
|
||||
var usageMessage = `usage: smugup [options] 'album title' [photo.jpg ...]
|
||||
|
||||
Smugup creates a new album with the given title if one does not already exist.
|
||||
Then uploads the list of images to the album. If a particular image
|
||||
already exists in the album, the JPG replaces the album image if the
|
||||
contents differ.
|
||||
|
||||
Smugup fetches the SmugMug user name and password from the
|
||||
user's keychain.
|
||||
|
||||
By default, new albums are created as private as possible: not public,
|
||||
not world searchable, and not SmugMug-searchable.
|
||||
|
||||
Smugup prints the URL for the album when finished.
|
||||
|
||||
The options are:
|
||||
|
||||
-u user
|
||||
SmugMug user account name (email address).
|
||||
This is not typically needed, as the user name found in the keychain will be used.
|
||||
`
|
||||
|
||||
var smugUser = flag.String("u", "", "SmugMug user name")
|
||||
|
||||
func usage() {
|
||||
fmt.Fprint(os.Stderr, usageMessage)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
log.SetFlags(0)
|
||||
|
||||
args := flag.Args()
|
||||
if len(args) < 1 {
|
||||
usage()
|
||||
}
|
||||
title, files := args[0], args[1:]
|
||||
|
||||
user, passwd, err := keychain.UserPasswd("smugmug.com", *smugUser)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
smug, err := smugmug.Login(user, passwd, apiKey)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
albums, err := smug.Albums(smug.NickName)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var a *smugmug.Album
|
||||
for _, a = range albums {
|
||||
if a.Title == title {
|
||||
goto HaveAlbum
|
||||
}
|
||||
}
|
||||
|
||||
a, err = smug.CreateAlbum(title)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
HaveAlbum:
|
||||
imageFiles := map[string]*smugmug.ImageInfo{}
|
||||
if len(files) > 0 {
|
||||
images, err := smug.Images(a)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
n := 0
|
||||
c := make(chan *smugmug.ImageInfo)
|
||||
rate := make(chan bool, 4)
|
||||
for _, image := range images {
|
||||
go func(image *smugmug.Image) {
|
||||
rate <- true
|
||||
info, err := smug.ImageInfo(image)
|
||||
<-rate
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
c <- nil
|
||||
return
|
||||
}
|
||||
c <- info
|
||||
}(image)
|
||||
n++
|
||||
}
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
info := <-c
|
||||
if info == nil {
|
||||
continue
|
||||
}
|
||||
imageFiles[info.FileName] = info
|
||||
}
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
data, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
continue
|
||||
}
|
||||
_, elem := filepath.Split(file)
|
||||
info := imageFiles[elem]
|
||||
if info != nil {
|
||||
h := md5.New()
|
||||
h.Write(data)
|
||||
digest := fmt.Sprintf("%x", h.Sum(nil))
|
||||
if digest == info.MD5Sum {
|
||||
// Already have that image.
|
||||
continue
|
||||
}
|
||||
_, err = smug.ReplaceImage(file, data, &smugmug.Image{ID: info.ID})
|
||||
} else {
|
||||
_, err = smug.AddImage(file, data, a)
|
||||
}
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
info, err := smug.AlbumInfo(a)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", info.URL)
|
||||
}
|
||||
572
vendor/github.com/mattermost/rsc/xmpp/xmpp.go
сгенерированный
поставляемый
572
vendor/github.com/mattermost/rsc/xmpp/xmpp.go
сгенерированный
поставляемый
@@ -1,572 +0,0 @@
|
||||
// Copyright 2011 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.
|
||||
|
||||
// TODO(rsc):
|
||||
// More precise error handling.
|
||||
// Presence functionality.
|
||||
// TODO(mattn):
|
||||
// Add proxy authentication.
|
||||
|
||||
// Package xmpp implements a simple Google Talk client
|
||||
// using the XMPP protocol described in RFC 3920 and RFC 3921.
|
||||
package xmpp
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
nsStream = "http://etherx.jabber.org/streams"
|
||||
nsTLS = "urn:ietf:params:xml:ns:xmpp-tls"
|
||||
nsSASL = "urn:ietf:params:xml:ns:xmpp-sasl"
|
||||
nsBind = "urn:ietf:params:xml:ns:xmpp-bind"
|
||||
nsClient = "jabber:client"
|
||||
)
|
||||
|
||||
var DefaultConfig tls.Config
|
||||
|
||||
type Client struct {
|
||||
tls *tls.Conn // connection to server
|
||||
jid string // Jabber ID for our connection
|
||||
p *xml.Decoder
|
||||
}
|
||||
|
||||
// NewClient creates a new connection to a host given as "hostname" or "hostname:port".
|
||||
// If host is not specified, the DNS SRV should be used to find the host from the domainpart of the JID.
|
||||
// Default the port to 5222.
|
||||
func NewClient(host, user, passwd string) (*Client, error) {
|
||||
addr := host
|
||||
|
||||
if strings.TrimSpace(host) == "" {
|
||||
a := strings.SplitN(user, "@", 2)
|
||||
if len(a) == 2 {
|
||||
host = a[1]
|
||||
}
|
||||
}
|
||||
a := strings.SplitN(host, ":", 2)
|
||||
if len(a) == 1 {
|
||||
host += ":5222"
|
||||
}
|
||||
proxy := os.Getenv("HTTP_PROXY")
|
||||
if proxy == "" {
|
||||
proxy = os.Getenv("http_proxy")
|
||||
}
|
||||
if proxy != "" {
|
||||
url, err := url.Parse(proxy)
|
||||
if err == nil {
|
||||
addr = url.Host
|
||||
}
|
||||
}
|
||||
c, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if proxy != "" {
|
||||
fmt.Fprintf(c, "CONNECT %s HTTP/1.1\r\n", host)
|
||||
fmt.Fprintf(c, "Host: %s\r\n", host)
|
||||
fmt.Fprintf(c, "\r\n")
|
||||
br := bufio.NewReader(c)
|
||||
req, _ := http.NewRequest("CONNECT", host, nil)
|
||||
resp, err := http.ReadResponse(br, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
f := strings.SplitN(resp.Status, " ", 2)
|
||||
return nil, errors.New(f[1])
|
||||
}
|
||||
}
|
||||
|
||||
tlsconn := tls.Client(c, &DefaultConfig)
|
||||
if err = tlsconn.Handshake(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if strings.LastIndex(host, ":") > 0 {
|
||||
host = host[:strings.LastIndex(host, ":")]
|
||||
}
|
||||
if err = tlsconn.VerifyHostname(host); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
client := new(Client)
|
||||
client.tls = tlsconn
|
||||
if err := client.init(user, passwd); err != nil {
|
||||
client.Close()
|
||||
return nil, err
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func (c *Client) Close() error {
|
||||
return c.tls.Close()
|
||||
}
|
||||
|
||||
func (c *Client) init(user, passwd string) error {
|
||||
// For debugging: the following causes the plaintext of the connection to be duplicated to stdout.
|
||||
// c.p = xml.NewParser(tee{c.tls, os.Stdout});
|
||||
c.p = xml.NewDecoder(c.tls)
|
||||
|
||||
a := strings.SplitN(user, "@", 2)
|
||||
if len(a) != 2 {
|
||||
return errors.New("xmpp: invalid username (want user@domain): " + user)
|
||||
}
|
||||
user = a[0]
|
||||
domain := a[1]
|
||||
|
||||
// Declare intent to be a jabber client.
|
||||
fmt.Fprintf(c.tls, "<?xml version='1.0'?>\n"+
|
||||
"<stream:stream to='%s' xmlns='%s'\n"+
|
||||
" xmlns:stream='%s' version='1.0'>\n",
|
||||
xmlEscape(domain), nsClient, nsStream)
|
||||
|
||||
// Server should respond with a stream opening.
|
||||
se, err := nextStart(c.p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if se.Name.Space != nsStream || se.Name.Local != "stream" {
|
||||
return errors.New("xmpp: expected <stream> but got <" + se.Name.Local + "> in " + se.Name.Space)
|
||||
}
|
||||
|
||||
// Now we're in the stream and can use Unmarshal.
|
||||
// Next message should be <features> to tell us authentication options.
|
||||
// See section 4.6 in RFC 3920.
|
||||
var f streamFeatures
|
||||
if err = c.p.Decode(&f); err != nil {
|
||||
return errors.New("unmarshal <features>: " + err.Error())
|
||||
}
|
||||
havePlain := false
|
||||
for _, m := range f.Mechanisms.Mechanism {
|
||||
if m == "PLAIN" {
|
||||
havePlain = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !havePlain {
|
||||
return errors.New(fmt.Sprintf("PLAIN authentication is not an option: %v", f.Mechanisms.Mechanism))
|
||||
}
|
||||
|
||||
// Plain authentication: send base64-encoded \x00 user \x00 password.
|
||||
raw := "\x00" + user + "\x00" + passwd
|
||||
enc := make([]byte, base64.StdEncoding.EncodedLen(len(raw)))
|
||||
base64.StdEncoding.Encode(enc, []byte(raw))
|
||||
fmt.Fprintf(c.tls, "<auth xmlns='%s' mechanism='PLAIN'>%s</auth>\n",
|
||||
nsSASL, enc)
|
||||
|
||||
// Next message should be either success or failure.
|
||||
name, val, err := next(c.p)
|
||||
switch v := val.(type) {
|
||||
case *saslSuccess:
|
||||
case *saslFailure:
|
||||
// v.Any is type of sub-element in failure,
|
||||
// which gives a description of what failed.
|
||||
return errors.New("auth failure: " + v.Any.Local)
|
||||
default:
|
||||
return errors.New("expected <success> or <failure>, got <" + name.Local + "> in " + name.Space)
|
||||
}
|
||||
|
||||
// Now that we're authenticated, we're supposed to start the stream over again.
|
||||
// Declare intent to be a jabber client.
|
||||
fmt.Fprintf(c.tls, "<stream:stream to='%s' xmlns='%s'\n"+
|
||||
" xmlns:stream='%s' version='1.0'>\n",
|
||||
xmlEscape(domain), nsClient, nsStream)
|
||||
|
||||
// Here comes another <stream> and <features>.
|
||||
se, err = nextStart(c.p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if se.Name.Space != nsStream || se.Name.Local != "stream" {
|
||||
return errors.New("expected <stream>, got <" + se.Name.Local + "> in " + se.Name.Space)
|
||||
}
|
||||
if err = c.p.Decode(&f); err != nil {
|
||||
// TODO: often stream stop.
|
||||
//return os.NewError("unmarshal <features>: " + err.String())
|
||||
}
|
||||
|
||||
// Send IQ message asking to bind to the local user name.
|
||||
fmt.Fprintf(c.tls, "<iq type='set' id='x'><bind xmlns='%s'/></iq>\n", nsBind)
|
||||
var iq clientIQ
|
||||
if err = c.p.Decode(&iq); err != nil {
|
||||
return errors.New("unmarshal <iq>: " + err.Error())
|
||||
}
|
||||
if &iq.Bind == nil {
|
||||
return errors.New("<iq> result missing <bind>")
|
||||
}
|
||||
c.jid = iq.Bind.Jid // our local id
|
||||
|
||||
// We're connected and can now receive and send messages.
|
||||
c.Status(Away, "")
|
||||
return nil
|
||||
}
|
||||
|
||||
type Chat struct {
|
||||
Remote string
|
||||
Type string
|
||||
Text string
|
||||
Roster Roster
|
||||
Presence *Presence
|
||||
}
|
||||
|
||||
type Roster []Contact
|
||||
|
||||
type Contact struct {
|
||||
Remote string
|
||||
Name string
|
||||
Group []string
|
||||
}
|
||||
|
||||
type Presence struct {
|
||||
Remote string
|
||||
Status Status
|
||||
StatusMsg string
|
||||
Priority int
|
||||
}
|
||||
|
||||
func atoi(s string) int {
|
||||
if s == "" {
|
||||
return 0
|
||||
}
|
||||
n, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
n = -1
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func statusCode(s string) Status {
|
||||
for i, ss := range statusName {
|
||||
if s == ss {
|
||||
return Status(i)
|
||||
}
|
||||
}
|
||||
return Available
|
||||
}
|
||||
|
||||
// Recv wait next token of chat.
|
||||
func (c *Client) Recv() (chat Chat, err error) {
|
||||
for {
|
||||
_, val, err := next(c.p)
|
||||
if err != nil {
|
||||
return Chat{}, err
|
||||
}
|
||||
switch val := val.(type) {
|
||||
case *clientMessage:
|
||||
return Chat{Remote: val.From, Type: val.Type, Text: val.Body}, nil
|
||||
case *clientQuery:
|
||||
var r Roster
|
||||
for _, item := range val.Item {
|
||||
r = append(r, Contact{item.Jid, item.Name, item.Group})
|
||||
}
|
||||
return Chat{Type: "roster", Roster: r}, nil
|
||||
case *clientPresence:
|
||||
pr := &Presence{Remote: val.From, Status: statusCode(val.Show), StatusMsg: val.Status, Priority: atoi(val.Priority)}
|
||||
if val.Type == "unavailable" {
|
||||
pr.Status = Unavailable
|
||||
}
|
||||
return Chat{Remote: val.From, Type: "presence", Presence: pr}, nil
|
||||
default:
|
||||
//log.Printf("ignoring %T", val)
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
// Send sends message text.
|
||||
func (c *Client) Send(chat Chat) error {
|
||||
fmt.Fprintf(c.tls, "<message to='%s' from='%s' type='chat' xml:lang='en'>"+
|
||||
"<body>%s</body></message>",
|
||||
xmlEscape(chat.Remote), xmlEscape(c.jid),
|
||||
xmlEscape(chat.Text))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Roster asks for the chat roster.
|
||||
func (c *Client) Roster() error {
|
||||
fmt.Fprintf(c.tls, "<iq from='%s' type='get' id='roster1'><query xmlns='jabber:iq:roster'/></iq>\n", xmlEscape(c.jid))
|
||||
return nil
|
||||
}
|
||||
|
||||
type Status int
|
||||
|
||||
const (
|
||||
Unavailable Status = iota
|
||||
DoNotDisturb
|
||||
ExtendedAway
|
||||
Away
|
||||
Available
|
||||
)
|
||||
|
||||
var statusName = []string{
|
||||
Unavailable: "unavailable",
|
||||
DoNotDisturb: "dnd",
|
||||
ExtendedAway: "xa",
|
||||
Away: "away",
|
||||
Available: "chat",
|
||||
}
|
||||
|
||||
func (s Status) String() string {
|
||||
return statusName[s]
|
||||
}
|
||||
|
||||
func (c *Client) Status(status Status, msg string) error {
|
||||
fmt.Fprintf(c.tls, "<presence xml:lang='en'><show>%s</show><status>%s</status></presence>", status, xmlEscape(msg))
|
||||
return nil
|
||||
}
|
||||
|
||||
// RFC 3920 C.1 Streams name space
|
||||
|
||||
type streamFeatures struct {
|
||||
XMLName xml.Name `xml:"http://etherx.jabber.org/streams features"`
|
||||
StartTLS tlsStartTLS
|
||||
Mechanisms saslMechanisms
|
||||
Bind bindBind
|
||||
Session bool
|
||||
}
|
||||
|
||||
type streamError struct {
|
||||
XMLName xml.Name `xml:"http://etherx.jabber.org/streams error"`
|
||||
Any xml.Name
|
||||
Text string
|
||||
}
|
||||
|
||||
// RFC 3920 C.3 TLS name space
|
||||
|
||||
type tlsStartTLS struct {
|
||||
XMLName xml.Name `xml:":ietf:params:xml:ns:xmpp-tls starttls"`
|
||||
Required bool
|
||||
}
|
||||
|
||||
type tlsProceed struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls proceed"`
|
||||
}
|
||||
|
||||
type tlsFailure struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-tls failure"`
|
||||
}
|
||||
|
||||
// RFC 3920 C.4 SASL name space
|
||||
|
||||
type saslMechanisms struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl mechanisms"`
|
||||
Mechanism []string
|
||||
}
|
||||
|
||||
type saslAuth struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl auth"`
|
||||
Mechanism string `xml:"attr"`
|
||||
}
|
||||
|
||||
type saslChallenge string
|
||||
|
||||
type saslResponse string
|
||||
|
||||
type saslAbort struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl abort"`
|
||||
}
|
||||
|
||||
type saslSuccess struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl success"`
|
||||
}
|
||||
|
||||
type saslFailure struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-sasl failure"`
|
||||
Any xml.Name
|
||||
}
|
||||
|
||||
// RFC 3920 C.5 Resource binding name space
|
||||
|
||||
type bindBind struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:xmpp-bind bind"`
|
||||
Resource string
|
||||
Jid string
|
||||
}
|
||||
|
||||
// RFC 3921 B.1 jabber:client
|
||||
|
||||
type clientMessage struct {
|
||||
XMLName xml.Name `xml:"jabber:client message"`
|
||||
From string `xml:"attr"`
|
||||
Id string `xml:"attr"`
|
||||
To string `xml:"attr"`
|
||||
Type string `xml:"attr"` // chat, error, groupchat, headline, or normal
|
||||
|
||||
// These should technically be []clientText,
|
||||
// but string is much more convenient.
|
||||
Subject string
|
||||
Body string
|
||||
Thread string
|
||||
}
|
||||
|
||||
type clientText struct {
|
||||
Lang string `xml:"attr"`
|
||||
Body string `xml:"chardata"`
|
||||
}
|
||||
|
||||
type clientPresence struct {
|
||||
XMLName xml.Name `xml:"jabber:client presence"`
|
||||
From string `xml:"attr"`
|
||||
Id string `xml:"attr"`
|
||||
To string `xml:"attr"`
|
||||
Type string `xml:"attr"` // error, probe, subscribe, subscribed, unavailable, unsubscribe, unsubscribed
|
||||
Lang string `xml:"attr"`
|
||||
|
||||
Show string // away, chat, dnd, xa
|
||||
Status string // sb []clientText
|
||||
Priority string
|
||||
Error *clientError
|
||||
}
|
||||
|
||||
type clientIQ struct { // info/query
|
||||
XMLName xml.Name `xml:"jabber:client iq"`
|
||||
From string `xml:"attr"`
|
||||
Id string `xml:"attr"`
|
||||
To string `xml:"attr"`
|
||||
Type string `xml:"attr"` // error, get, result, set
|
||||
Error clientError
|
||||
Bind bindBind
|
||||
Query clientQuery
|
||||
}
|
||||
|
||||
type clientError struct {
|
||||
XMLName xml.Name `xml:"jabber:client error"`
|
||||
Code string `xml:"attr"`
|
||||
Type string `xml:"attr"`
|
||||
Any xml.Name
|
||||
Text string
|
||||
}
|
||||
|
||||
type clientQuery struct {
|
||||
Item []rosterItem
|
||||
}
|
||||
|
||||
type rosterItem struct {
|
||||
XMLName xml.Name `xml:"jabber:iq:roster item"`
|
||||
Jid string `xml:"attr"`
|
||||
Name string `xml:"attr"`
|
||||
Subscription string `xml:"attr"`
|
||||
Group []string
|
||||
}
|
||||
|
||||
// Scan XML token stream to find next StartElement.
|
||||
func nextStart(p *xml.Decoder) (xml.StartElement, error) {
|
||||
for {
|
||||
t, err := p.Token()
|
||||
if err != nil {
|
||||
log.Fatal("token", err)
|
||||
}
|
||||
switch t := t.(type) {
|
||||
case xml.StartElement:
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
|
||||
// Scan XML token stream for next element and save into val.
|
||||
// If val == nil, allocate new element based on proto map.
|
||||
// Either way, return val.
|
||||
func next(p *xml.Decoder) (xml.Name, interface{}, error) {
|
||||
// Read start element to find out what type we want.
|
||||
se, err := nextStart(p)
|
||||
if err != nil {
|
||||
return xml.Name{}, nil, err
|
||||
}
|
||||
|
||||
// Put it in an interface and allocate one.
|
||||
var nv interface{}
|
||||
switch se.Name.Space + " " + se.Name.Local {
|
||||
case nsStream + " features":
|
||||
nv = &streamFeatures{}
|
||||
case nsStream + " error":
|
||||
nv = &streamError{}
|
||||
case nsTLS + " starttls":
|
||||
nv = &tlsStartTLS{}
|
||||
case nsTLS + " proceed":
|
||||
nv = &tlsProceed{}
|
||||
case nsTLS + " failure":
|
||||
nv = &tlsFailure{}
|
||||
case nsSASL + " mechanisms":
|
||||
nv = &saslMechanisms{}
|
||||
case nsSASL + " challenge":
|
||||
nv = ""
|
||||
case nsSASL + " response":
|
||||
nv = ""
|
||||
case nsSASL + " abort":
|
||||
nv = &saslAbort{}
|
||||
case nsSASL + " success":
|
||||
nv = &saslSuccess{}
|
||||
case nsSASL + " failure":
|
||||
nv = &saslFailure{}
|
||||
case nsBind + " bind":
|
||||
nv = &bindBind{}
|
||||
case nsClient + " message":
|
||||
nv = &clientMessage{}
|
||||
case nsClient + " presence":
|
||||
nv = &clientPresence{}
|
||||
case nsClient + " iq":
|
||||
nv = &clientIQ{}
|
||||
case nsClient + " error":
|
||||
nv = &clientError{}
|
||||
default:
|
||||
return xml.Name{}, nil, errors.New("unexpected XMPP message " +
|
||||
se.Name.Space + " <" + se.Name.Local + "/>")
|
||||
}
|
||||
|
||||
// Unmarshal into that storage.
|
||||
if err = p.DecodeElement(nv, &se); err != nil {
|
||||
return xml.Name{}, nil, err
|
||||
}
|
||||
return se.Name, nv, err
|
||||
}
|
||||
|
||||
var xmlSpecial = map[byte]string{
|
||||
'<': "<",
|
||||
'>': ">",
|
||||
'"': """,
|
||||
'\'': "'",
|
||||
'&': "&",
|
||||
}
|
||||
|
||||
func xmlEscape(s string) string {
|
||||
var b bytes.Buffer
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := s[i]
|
||||
if s, ok := xmlSpecial[c]; ok {
|
||||
b.WriteString(s)
|
||||
} else {
|
||||
b.WriteByte(c)
|
||||
}
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
type tee struct {
|
||||
r io.Reader
|
||||
w io.Writer
|
||||
}
|
||||
|
||||
func (t tee) Read(p []byte) (n int, err error) {
|
||||
n, err = t.r.Read(p)
|
||||
if n > 0 {
|
||||
t.w.Write(p[0:n])
|
||||
}
|
||||
return
|
||||
}
|
||||
Ссылка в новой задаче
Block a user