Skip to content

Commit 6ad0c55

Browse files
committed
debug: unleash a flood of debug prints upon the propfind
1 parent 3465648 commit 6ad0c55

File tree

1 file changed

+104
-5
lines changed

1 file changed

+104
-5
lines changed

internal/http/services/owncloud/ocdav/propfind.go

Lines changed: 104 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ func (s *svc) handlePathPropfind(w http.ResponseWriter, r *http.Request, ns stri
9090
w.WriteHeader(status)
9191
return
9292
}
93+
94+
// Debug: log PROPFIND request details
95+
requestType := "unknown"
96+
if pf.Allprop != nil {
97+
requestType = "allprop"
98+
} else if pf.Propname != nil {
99+
requestType = "propname"
100+
} else if len(pf.Prop) > 0 {
101+
requestType = "specific properties"
102+
propNames := make([]string, len(pf.Prop))
103+
for i, prop := range pf.Prop {
104+
propNames[i] = prop.Local
105+
}
106+
sublog.Debug().
107+
Str("request_type", requestType).
108+
Strs("requested_properties", propNames).
109+
Msg("propfind: request details")
110+
}
111+
sublog.Debug().
112+
Str("request_type", requestType).
113+
Bool("spaces_enabled", s.c.SpacesEnabled).
114+
Msg("propfind: request configuration")
93115

94116
parentInfo, resourceInfos, ok := s.getResourceInfos(ctx, w, r, pf, ref, false, sublog)
95117
if !ok {
@@ -482,6 +504,39 @@ func (s *svc) multistatusResponse(ctx context.Context, pf *propfindXML, mds []*p
482504
if err != nil {
483505
return "", err
484506
}
507+
508+
// Debug: log the response for this resource
509+
log.Debug().
510+
Int("index", i).
511+
Str("href", res.Href).
512+
Int("num_propstats", len(res.Propstat)).
513+
Msg("propfind: response created for resource")
514+
515+
// Debug: log properties in the response
516+
for j, propstat := range res.Propstat {
517+
propCount := len(propstat.Prop)
518+
log.Debug().
519+
Int("resource_index", i).
520+
Int("propstat_index", j).
521+
Int("prop_count", propCount).
522+
Str("status", propstat.Status).
523+
Msg("propfind: propstat details")
524+
525+
// Log specific properties we care about
526+
for k, prop := range propstat.Prop {
527+
if prop.XMLName.Local == "fileid" || prop.XMLName.Local == "id" {
528+
log.Debug().
529+
Int("resource_index", i).
530+
Int("propstat_index", j).
531+
Int("prop_index", k).
532+
Str("prop_name", prop.XMLName.Local).
533+
Str("prop_namespace", prop.XMLName.Space).
534+
Str("prop_value", string(prop.InnerXML)).
535+
Msg("propfind: ID property value in response")
536+
}
537+
}
538+
}
539+
485540
responses = append(responses, res)
486541
}
487542
responsesXML, err := xml.Marshal(&responses)
@@ -492,6 +547,10 @@ func (s *svc) multistatusResponse(ctx context.Context, pf *propfindXML, mds []*p
492547
msg := `<?xml version="1.0" encoding="utf-8"?><d:multistatus xmlns:d="DAV:" `
493548
msg += `xmlns:s="http://sabredav.org/ns" xmlns:oc="http://owncloud.org/ns">`
494549
msg += string(responsesXML) + `</d:multistatus>`
550+
551+
// Debug: log the full XML response
552+
log.Debug().Str("xml_response", msg).Msg("propfind: full XML multistatus response")
553+
495554
return msg, nil
496555
}
497556

@@ -605,11 +664,17 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
605664
spacesEnabled := s.c.SpacesEnabled
606665

607666
baseURI := ctx.Value(ctxKeyBaseURI).(string)
667+
sublog.Debug().
668+
Str("base_uri", baseURI).
669+
Bool("spaces_enabled", spacesEnabled).
670+
Msg("propfind: mdToPropResponse - constructing href")
671+
608672
var ref string
609673
var err error
610674
if spacesEnabled {
611675
ref, err = spaceHref(ctx, baseURI, md)
612676
if err != nil {
677+
sublog.Error().Err(err).Msg("propfind: spaceHref failed")
613678
pxml := propstatXML{
614679
Status: "HTTP/1.1 400 Bad Request",
615680
Prop: []*propertyXML{},
@@ -621,6 +686,9 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
621686
}, err
622687

623688
}
689+
sublog.Debug().
690+
Str("href", ref).
691+
Msg("propfind: spaceHref result")
624692
} else {
625693
md.Path = strings.TrimPrefix(md.Path, ns)
626694

@@ -629,11 +697,19 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
629697
_, md.Path = router.ShiftPath(md.Path)
630698
}
631699
ref = path.Join(baseURI, md.Path)
700+
sublog.Debug().
701+
Str("href", ref).
702+
Msg("propfind: non-spaces href constructed")
632703
}
633704
if md.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
634705
ref += "/"
635706
}
636707

708+
sublog.Debug().
709+
Str("final_href", ref).
710+
Str("encoded_href", encodePath(ref)).
711+
Msg("propfind: final href for response")
712+
637713
response := responseXML{
638714
Href: encodePath(ref),
639715
Propstat: []propstatXML{},
@@ -692,6 +768,7 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
692768

693769
// when allprops has been requested
694770
if pf.Allprop != nil {
771+
sublog.Debug().Msg("propfind: allprop mode - returning all properties")
695772
// return all known properties
696773
if md.Id != nil {
697774
if spacesEnabled {
@@ -700,18 +777,28 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
700777
Str("space_id", md.Id.SpaceId).
701778
Str("opaque_id", md.Id.OpaqueId).
702779
Str("path", md.Path).
703-
Msg("propfind: encoding resource ID")
780+
Msg("propfind: encoding resource ID (allprop, spaces enabled)")
704781
id := spaces.EncodeResourceID(md.Id)
782+
sublog.Debug().
783+
Str("encoded_id", id).
784+
Msg("propfind: allprop - setting oc:id and oc:fileid")
705785
propstatOK.Prop = append(propstatOK.Prop,
706786
s.newProp("oc:id", id),
707787
s.newProp("oc:fileid", id))
708788
} else {
709789
id := spaces.ResourceIdToString(md.Id)
790+
sublog.Debug().
791+
Str("encoded_id", id).
792+
Msg("propfind: allprop - setting oc:id and oc:fileid (non-spaces)")
710793
propstatOK.Prop = append(propstatOK.Prop,
711794
s.newProp("oc:id", id),
712795
s.newProp("oc:fileid", id))
713796
}
714797
}
798+
} else {
799+
sublog.Debug().
800+
Int("num_requested_props", len(pf.Prop)).
801+
Msg("propfind: specific properties requested")
715802

716803
if md.ParentId != nil {
717804
sublog.Debug().
@@ -817,24 +904,36 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
817904
// I tested the desktop client and phoenix to annotate which properties are requestted, see below cases
818905
case "fileid": // phoenix only
819906
if md.Id == nil {
907+
sublog.Debug().Msg("propfind: fileid requested but md.Id is nil")
820908
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:fileid", ""))
821909
} else if spacesEnabled {
822910
sublog.Debug().
823911
Str("storage_id", md.Id.StorageId).
824912
Str("space_id", md.Id.SpaceId).
825913
Str("opaque_id", md.Id.OpaqueId).
826914
Str("path", md.Path).
827-
Msg("propfind: encoding fileid property")
915+
Msg("propfind: encoding fileid property (specific, spaces enabled)")
828916
// If our client uses spaces, we try to use the spaces-encoded file id (storage$base32(spacePath)!inode)
829917
fileId, err := spaces.EncodeResourceInfo(md)
830918
if err != nil {
831-
sublog.Error().Err(err).Any("md", md).Msg("Failed to encode file id")
832-
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:fileid", spaces.EncodeResourceID(md.Id)))
919+
sublog.Error().Err(err).Any("md", md).Msg("Failed to encode file id with EncodeResourceInfo")
920+
fallbackId := spaces.EncodeResourceID(md.Id)
921+
sublog.Debug().
922+
Str("fallback_id", fallbackId).
923+
Msg("propfind: using EncodeResourceID fallback for fileid")
924+
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:fileid", fallbackId))
833925
} else {
926+
sublog.Debug().
927+
Str("encoded_fileid", fileId).
928+
Msg("propfind: specific property - setting oc:fileid from EncodeResourceInfo")
834929
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:fileid", fileId))
835930
}
836931
} else {
837-
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:fileid", spaces.ResourceIdToString(md.Id)))
932+
encodedId := spaces.ResourceIdToString(md.Id)
933+
sublog.Debug().
934+
Str("encoded_fileid", encodedId).
935+
Msg("propfind: specific property - setting oc:fileid (non-spaces)")
936+
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:fileid", encodedId))
838937
}
839938

840939
case "id": // desktop client only

0 commit comments

Comments
 (0)