2012-12-17 04:41:06 +00:00
|
|
|
// +build THIS_IS_BROKEN
|
|
|
|
|
2011-08-07 01:46:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"text/template"
|
2011-08-07 01:46:37 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type xmler interface {
|
|
|
|
XML(b *bytes.Buffer)
|
|
|
|
}
|
|
|
|
|
|
|
|
// See: http://www.webdav.org/specs/rfc4918.html
|
|
|
|
|
|
|
|
// 14.7 href XML Element
|
2011-08-25 15:14:47 +00:00
|
|
|
type href url.URL
|
2011-08-07 01:46:37 +00:00
|
|
|
|
|
|
|
func (h *href) XML(b *bytes.Buffer) {
|
2011-08-25 15:14:47 +00:00
|
|
|
b.WriteString("<href>" + template.HTMLEscapeString((*url.URL)(h).String()) + "</href>")
|
2011-08-07 01:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 14.16 multistatus XML Element
|
|
|
|
type multistatus []*response
|
|
|
|
|
|
|
|
func (m multistatus) XML(b *bytes.Buffer) {
|
|
|
|
b.WriteString("<multistatus xmlns='DAV:'>")
|
|
|
|
for _, r := range m {
|
|
|
|
r.XML(b)
|
|
|
|
}
|
|
|
|
b.WriteString("</multistatus>")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 14.24 response XML Element
|
|
|
|
type response struct {
|
|
|
|
href *href
|
|
|
|
body xmler // hrefsstatus OR propstats
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *response) XML(b *bytes.Buffer) {
|
|
|
|
b.WriteString("<response>")
|
|
|
|
r.href.XML(b)
|
|
|
|
r.body.XML(b)
|
|
|
|
b.WriteString("</response>")
|
|
|
|
}
|
|
|
|
|
|
|
|
// part of 14.24 response XML element
|
|
|
|
|
|
|
|
type hrefsstatus struct {
|
|
|
|
hrefs []*href
|
|
|
|
status status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (hs *hrefsstatus) XML(b *bytes.Buffer) {
|
|
|
|
for _, h := range hs.hrefs {
|
|
|
|
h.XML(b)
|
|
|
|
}
|
|
|
|
hs.status.XML(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
// part of 14.24 response element
|
|
|
|
|
|
|
|
type propstats []propstat
|
|
|
|
|
|
|
|
func (p propstats) XML(b *bytes.Buffer) {
|
|
|
|
b.WriteString("<propstat>")
|
|
|
|
for _, prop := range p {
|
|
|
|
prop.XML(b)
|
|
|
|
}
|
|
|
|
b.WriteString("</propstat>")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 14.22 propstat XML Element
|
|
|
|
type propstat struct {
|
|
|
|
props []xmler
|
|
|
|
status status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *propstat) XML(b *bytes.Buffer) {
|
|
|
|
b.WriteString("<prop>")
|
|
|
|
for _, prop := range p.props {
|
|
|
|
prop.XML(b)
|
|
|
|
}
|
|
|
|
b.WriteString("</prop>")
|
|
|
|
p.status.XML(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 14.28 status XML element
|
|
|
|
type status int
|
|
|
|
|
|
|
|
func (s status) XML(b *bytes.Buffer) {
|
|
|
|
b.WriteString(fmt.Sprintf("<status>HTTP/1.1 %d %s</status>", s, template.HTMLEscapeString(http.StatusText(int(s)))))
|
|
|
|
}
|
|
|
|
|
|
|
|
// 15.1 creationdate Property
|
|
|
|
type creationdate uint64 // seconds from unix epoch
|
|
|
|
|
|
|
|
func (c creationdate) XML(b *bytes.Buffer) {
|
|
|
|
b.WriteString("<creationdate>")
|
|
|
|
b.WriteString(epochToXMLTime(int64(c)))
|
|
|
|
b.WriteString("</creationdate>")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 15.4 getcontentlength Property
|
|
|
|
type getcontentlength uint64
|
|
|
|
|
|
|
|
func (l getcontentlength) XML(b *bytes.Buffer) {
|
|
|
|
|
|
|
|
b.WriteString("<getcontentlength>")
|
|
|
|
b.WriteString(fmt.Sprint(l))
|
|
|
|
b.WriteString("</getcontentlength>")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 15.7 getlastmodified Property
|
|
|
|
type getlastmodified uint64 // seconds from unix epoch
|
|
|
|
func (g getlastmodified) XML(b *bytes.Buffer) {
|
|
|
|
b.WriteString("<getlastmodified>")
|
|
|
|
b.WriteString(epochToXMLTime(int64(g)))
|
|
|
|
b.WriteString("</getlastmodified>")
|
|
|
|
}
|
|
|
|
|
|
|
|
// 15.9 resourcetype Property
|
|
|
|
type resourcetype bool // true if collection (directory), false otherwise
|
|
|
|
|
|
|
|
func (r resourcetype) XML(b *bytes.Buffer) {
|
|
|
|
b.WriteString("<resourcetype>")
|
|
|
|
if r {
|
|
|
|
b.WriteString("<collection/>")
|
|
|
|
}
|
|
|
|
b.WriteString("</resourcetype>")
|
|
|
|
}
|
|
|
|
|
|
|
|
// helpers
|
|
|
|
func epochToXMLTime(sec int64) string {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
return template.HTMLEscapeString(time.Unix(sec, 0).UTC().Format(time.RFC3339))
|
2011-08-07 01:46:37 +00:00
|
|
|
}
|