Move dav to tool dir.

This commit is contained in:
zicla 2019-04-26 03:11:15 +08:00
parent c5de9ce9eb
commit 16749d1fa1
8 changed files with 42 additions and 42 deletions

View File

@ -5,8 +5,8 @@ import (
"net/http"
"path"
"strconv"
"tank/code/dav"
"tank/code/dav/xml"
dav2 "tank/code/tool/dav"
xml2 "tank/code/tool/dav/xml"
)
//访问前缀,这个是特殊入口
@ -19,7 +19,7 @@ type LiveProp struct {
}
//所有的动态属性定义及其值的获取方式
var LivePropMap = map[xml.Name]LiveProp{
var LivePropMap = map[xml2.Name]LiveProp{
{Space: "DAV:", Local: "resourcetype"}: {
findFn: func(user *User, matter *Matter) string {
if matter.Dir {
@ -35,7 +35,7 @@ var LivePropMap = map[xml.Name]LiveProp{
if path.Clean("/"+matter.Name) == "/" {
return ""
} else {
return dav.EscapeXML(matter.Name)
return dav2.EscapeXML(matter.Name)
}
},
dir: true,
@ -72,7 +72,7 @@ var LivePropMap = map[xml.Name]LiveProp{
if matter.Dir {
return ""
} else {
return dav.EscapeXML(matter.Name)
return dav2.EscapeXML(matter.Name)
}
},
dir: false,

View File

@ -7,9 +7,9 @@ import (
"path"
"regexp"
"strings"
"tank/code/dav"
"tank/code/dav/xml"
"tank/code/result"
dav2 "tank/code/tool/dav"
xml2 "tank/code/tool/dav/xml"
"tank/code/tool/util"
)
@ -63,18 +63,18 @@ func (this *DavService) ParseDepth(request *http.Request) int {
return depth
}
func (this *DavService) makePropstatResponse(href string, pstats []dav.Propstat) *dav.Response {
resp := dav.Response{
func (this *DavService) makePropstatResponse(href string, pstats []dav2.Propstat) *dav2.Response {
resp := dav2.Response{
Href: []string{(&url.URL{Path: href}).EscapedPath()},
Propstat: make([]dav.SubPropstat, 0, len(pstats)),
Propstat: make([]dav2.SubPropstat, 0, len(pstats)),
}
for _, p := range pstats {
var xmlErr *dav.XmlError
var xmlErr *dav2.XmlError
if p.XMLError != "" {
xmlErr = &dav.XmlError{InnerXML: []byte(p.XMLError)}
xmlErr = &dav2.XmlError{InnerXML: []byte(p.XMLError)}
}
resp.Propstat = append(resp.Propstat, dav.SubPropstat{
Status: fmt.Sprintf("HTTP/1.1 %d %s", p.Status, dav.StatusText(p.Status)),
resp.Propstat = append(resp.Propstat, dav2.SubPropstat{
Status: fmt.Sprintf("HTTP/1.1 %d %s", p.Status, dav2.StatusText(p.Status)),
Prop: p.Props,
ResponseDescription: p.ResponseDescription,
Error: xmlErr,
@ -84,11 +84,11 @@ func (this *DavService) makePropstatResponse(href string, pstats []dav.Propstat)
}
//从一个matter中获取其 []dav.Propstat
func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNames []xml.Name) []dav.Propstat {
func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNames []xml2.Name) []dav2.Propstat {
propstats := make([]dav.Propstat, 0)
propstats := make([]dav2.Propstat, 0)
var properties []dav.Property
var properties []dav2.Property
for _, xmlName := range xmlNames {
//TODO: deadprops尚未考虑
@ -97,7 +97,7 @@ func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNam
if liveProp := LivePropMap[xmlName]; liveProp.findFn != nil && (liveProp.dir || !matter.Dir) {
innerXML := liveProp.findFn(user, matter)
properties = append(properties, dav.Property{
properties = append(properties, dav2.Property{
XMLName: xmlName,
InnerXML: []byte(innerXML),
})
@ -110,7 +110,7 @@ func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNam
panic(result.BadRequest("请求的属性项无法解析!"))
}
okPropstat := dav.Propstat{Status: http.StatusOK, Props: properties}
okPropstat := dav2.Propstat{Status: http.StatusOK, Props: properties}
propstats = append(propstats, okPropstat)
@ -119,9 +119,9 @@ func (this *DavService) PropstatsFromXmlNames(user *User, matter *Matter, xmlNam
}
//从一个matter中获取所有的propsNames
func (this *DavService) AllPropXmlNames(matter *Matter) []xml.Name {
func (this *DavService) AllPropXmlNames(matter *Matter) []xml2.Name {
pnames := make([]xml.Name, 0)
pnames := make([]xml2.Name, 0)
for pn, prop := range LivePropMap {
if prop.findFn != nil && (prop.dir || !matter.Dir) {
pnames = append(pnames, pn)
@ -132,9 +132,9 @@ func (this *DavService) AllPropXmlNames(matter *Matter) []xml.Name {
}
//从一个matter中获取其 []dav.Propstat
func (this *DavService) Propstats(user *User, matter *Matter, propfind *dav.Propfind) []dav.Propstat {
func (this *DavService) Propstats(user *User, matter *Matter, propfind *dav2.Propfind) []dav2.Propstat {
propstats := make([]dav.Propstat, 0)
propstats := make([]dav2.Propstat, 0)
if propfind.Propname != nil {
panic(result.BadRequest("propfind.Propname != nil 尚未处理"))
} else if propfind.Allprop != nil {
@ -161,7 +161,7 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
depth := this.ParseDepth(request)
//读取请求参数。按照用户的参数请求返回内容。
propfind := dav.ReadPropfind(request.Body)
propfind := dav2.ReadPropfind(request.Body)
//寻找符合条件的matter.
//如果是空或者/就是请求根目录
@ -179,7 +179,7 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
}
//准备一个输出结果的Writer
multiStatusWriter := &dav.MultiStatusWriter{Writer: writer}
multiStatusWriter := &dav2.MultiStatusWriter{Writer: writer}
for _, matter := range matters {

View File

@ -2,15 +2,15 @@ package test
import (
"bytes"
"tank/code/dav"
"tank/code/dav/xml"
dav2 "tank/code/tool/dav"
xml2 "tank/code/tool/dav/xml"
"testing"
"time"
)
func TestXmlDecoder(t *testing.T) {
propfind := &dav.Propfind{}
propfind := &dav2.Propfind{}
str := `
<?xml version="1.0" encoding="utf-8" ?>
@ -26,7 +26,7 @@ func TestXmlDecoder(t *testing.T) {
reader := bytes.NewReader([]byte(str))
err := xml.NewDecoder(reader).Decode(propfind)
err := xml2.NewDecoder(reader).Decode(propfind)
if err != nil {
t.Error(err.Error())
}
@ -58,18 +58,18 @@ func TestXmlEncoder(t *testing.T) {
writer := &bytes.Buffer{}
response := &dav.Response{
XMLName: xml.Name{Space: "DAV:", Local: "response"},
response := &dav2.Response{
XMLName: xml2.Name{Space: "DAV:", Local: "response"},
Href: []string{"/api/dav"},
Propstat: []dav.SubPropstat{
Propstat: []dav2.SubPropstat{
{
Prop: []dav.Property{
Prop: []dav2.Property{
{
XMLName: xml.Name{Space: "DAV:", Local: "resourcetype"},
XMLName: xml2.Name{Space: "DAV:", Local: "resourcetype"},
InnerXML: []byte(`<D:collection xmlns:D="DAV:"/>`),
},
{
XMLName: xml.Name{Space: "DAV:", Local: "getlastmodified"},
XMLName: xml2.Name{Space: "DAV:", Local: "getlastmodified"},
InnerXML: []byte(`Mon, 22 Apr 2019 06:38:36 GMT`),
},
},
@ -78,7 +78,7 @@ func TestXmlEncoder(t *testing.T) {
},
}
err := xml.NewEncoder(writer).Encode(response)
err := xml2.NewEncoder(writer).Encode(response)
if err != nil {
t.Error(err.Error())

View File

@ -10,8 +10,8 @@ import (
"fmt"
"io"
"net/http"
"tank/code/dav/xml"
"tank/code/result"
"tank/code/tool/dav/xml"
)
// Proppatch describes a property update instruction as defined in RFC 4918.