Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
[cbox-commit-5] Format adler checksum header as expected by the sync …
Browse files Browse the repository at this point in the history
…client
  • Loading branch information
ishank011 committed Jun 13, 2022
1 parent afe7101 commit 9335aae
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
14 changes: 13 additions & 1 deletion internal/grpc/services/storageprovider/transcoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@
package storageprovider

import (
"strings"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
)

// XS defines an hex-encoded string as checksum.
type XS string

func (x XS) String() string { return string(x) }
func (x XS) String() string {
// Based on https://github.com/owncloud/client/blob/15fc9d017fcdcc4cc95728c16a2dd171d0395b85/src/common/checksums.h#L38-L42
if x == XSMD5 || x == XSSHA1 || x == XSSHA256 {
return strings.ToUpper(string(x))
}
if x == XSAdler32 {
return strings.Title(string(x))
}
return string(x)

}

const (
// XSInvalid means the checksum type is invalid.
Expand Down
3 changes: 1 addition & 2 deletions internal/http/services/owncloud/ocdav/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"net/http"
"path"
"strconv"
"strings"
"time"

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
Expand Down Expand Up @@ -141,7 +140,7 @@ func (s *svc) handleGet(ctx context.Context, w http.ResponseWriter, r *http.Requ
w.Header().Set(HeaderContentLength, strconv.FormatUint(info.Size, 10))
}
if info.Checksum != nil {
w.Header().Set(HeaderOCChecksum, fmt.Sprintf("%s:%s", strings.ToUpper(string(storageprovider.GRPC2PKGXS(info.Checksum.Type))), info.Checksum.Sum))
w.Header().Set(HeaderOCChecksum, fmt.Sprintf("%s:%s", storageprovider.GRPC2PKGXS(info.Checksum.Type).String(), info.Checksum.Sum))
}
var c int64
if c, err = io.Copy(w, httpRes.Body); err != nil {
Expand Down
5 changes: 2 additions & 3 deletions internal/http/services/owncloud/ocdav/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"net/http"
"path"
"strconv"
"strings"
"time"

rtrace "github.com/cs3org/reva/pkg/trace"
Expand Down Expand Up @@ -77,8 +76,8 @@ func (s *svc) handleHead(ctx context.Context, w http.ResponseWriter, r *http.Req
w.Header().Set(HeaderOCFileID, resourceid.OwnCloudResourceIDWrap(info.Id))
w.Header().Set(HeaderOCETag, info.Etag)
if info.Checksum != nil {
w.Header().Set(HeaderOCChecksum, fmt.Sprintf("%s:%s", strings.ToUpper(string(storageprovider.GRPC2PKGXS(info.Checksum.Type))), info.Checksum.Sum))
w.Header().Set(HeaderChecksum, fmt.Sprintf("%s=%s", strings.ToLower(string(storageprovider.GRPC2PKGXS(info.Checksum.Type))), info.Checksum.Sum))
w.Header().Set(HeaderOCChecksum, fmt.Sprintf("%s:%s", storageprovider.GRPC2PKGXS(info.Checksum.Type).String(), info.Checksum.Sum))
w.Header().Set(HeaderChecksum, fmt.Sprintf("%s:%s", storageprovider.GRPC2PKGXS(info.Checksum.Type).String(), info.Checksum.Sum))
}
t := utils.TSToTime(info.Mtime).UTC()
lastModifiedString := t.Format(time.RFC1123Z)
Expand Down
12 changes: 6 additions & 6 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
var checksums strings.Builder
if md.Checksum != nil {
checksums.WriteString("<oc:checksum>")
checksums.WriteString(strings.ToUpper(string(storageprovider.GRPC2PKGXS(md.Checksum.Type))))
checksums.WriteString(storageprovider.GRPC2PKGXS(md.Checksum.Type).String())
checksums.WriteString(":")
checksums.WriteString(md.Checksum.Sum)
}
Expand All @@ -631,9 +631,9 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
}
if e, ok := md.Opaque.Map["adler32"]; ok {
if checksums.Len() == 0 {
checksums.WriteString("<oc:checksum>ADLER32:")
checksums.WriteString("<oc:checksum>Adler32:")
} else {
checksums.WriteString(" ADLER32:")
checksums.WriteString(" Adler32:")
}
checksums.WriteString(string(e.Value))
}
Expand Down Expand Up @@ -784,7 +784,7 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
var checksums strings.Builder
if md.Checksum != nil {
checksums.WriteString("<oc:checksum>")
checksums.WriteString(strings.ToUpper(string(storageprovider.GRPC2PKGXS(md.Checksum.Type))))
checksums.WriteString(storageprovider.GRPC2PKGXS(md.Checksum.Type).String())
checksums.WriteString(":")
checksums.WriteString(md.Checksum.Sum)
}
Expand All @@ -799,9 +799,9 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
}
if e, ok := md.Opaque.Map["adler32"]; ok {
if checksums.Len() == 0 {
checksums.WriteString("<oc:checksum>ADLER32:")
checksums.WriteString("<oc:checksum>Adler32:")
} else {
checksums.WriteString(" ADLER32:")
checksums.WriteString(" Adler32:")
}
checksums.WriteString(string(e.Value))
}
Expand Down
1 change: 0 additions & 1 deletion internal/http/services/owncloud/ocdav/tus.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (s *svc) handleTusPost(ctx context.Context, w http.ResponseWriter, r *http.
return
}
// r.Header.Get("OC-Checksum")
// TODO must be SHA1, ADLER32 or MD5 ... in capital letters????
// curl -X PUT https://demo.owncloud.com/remote.php/webdav/testcs.bin -u demo:demo -d '123' -v -H 'OC-Checksum: SHA1:40bd001563085fc35165329ea1ff5c5ecbdbbeef'

// TODO check Expect: 100-continue
Expand Down

0 comments on commit 9335aae

Please sign in to comment.