mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
carddav: add full query AST
This commit is contained in:
parent
e56ab47c43
commit
5ada08f6ab
@ -20,9 +20,52 @@ type AddressBookQuery struct {
|
|||||||
Props []string
|
Props []string
|
||||||
AllProp bool
|
AllProp bool
|
||||||
|
|
||||||
|
PropFilters []PropFilter
|
||||||
|
FilterTest FilterTest // defaults to FilterAnyOf
|
||||||
|
|
||||||
Limit int // <= 0 means unlimited
|
Limit int // <= 0 means unlimited
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PropFilter struct {
|
||||||
|
Name string
|
||||||
|
|
||||||
|
// if IsNotDefined is set, TextMatches and Params need to be unset
|
||||||
|
IsNotDefined bool
|
||||||
|
TextMatches []TextMatch
|
||||||
|
Params []ParamFilter
|
||||||
|
}
|
||||||
|
|
||||||
|
type ParamFilter struct {
|
||||||
|
Name string
|
||||||
|
Test FilterTest // defaults to FilterAnyOf
|
||||||
|
|
||||||
|
// if IsNotDefined is set, TextMatch needs to be unset
|
||||||
|
IsNotDefined bool
|
||||||
|
TextMatch *TextMatch
|
||||||
|
}
|
||||||
|
|
||||||
|
type TextMatch struct {
|
||||||
|
Text string
|
||||||
|
NegateCondition bool
|
||||||
|
MatchType MatchType // defaults to MatchContains
|
||||||
|
}
|
||||||
|
|
||||||
|
type FilterTest string
|
||||||
|
|
||||||
|
const (
|
||||||
|
FilterAnyOf FilterTest = "anyof"
|
||||||
|
FilterAllOf FilterTest = "allof"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MatchType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
MatchEquals MatchType = "equals"
|
||||||
|
MatchContains MatchType = "contains"
|
||||||
|
MatchStartsWith MatchType = "starts-with"
|
||||||
|
MatchEndsWith MatchType = "ends-with"
|
||||||
|
)
|
||||||
|
|
||||||
type AddressBookMultiGet struct {
|
type AddressBookMultiGet struct {
|
||||||
Paths []string
|
Paths []string
|
||||||
|
|
||||||
|
@ -71,19 +71,13 @@ type filter struct {
|
|||||||
|
|
||||||
type filterTest string
|
type filterTest string
|
||||||
|
|
||||||
const (
|
|
||||||
filterAnyOf filterTest = "anyof"
|
|
||||||
filterAllOf filterTest = "allof"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (ft *filterTest) UnmarshalText(b []byte) error {
|
func (ft *filterTest) UnmarshalText(b []byte) error {
|
||||||
v := filterTest(b)
|
switch FilterTest(b) {
|
||||||
switch v {
|
case FilterAnyOf, FilterAllOf:
|
||||||
case filterAnyOf, filterAllOf:
|
*ft = filterTest(b)
|
||||||
*ft = v
|
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("carddav: invalid filter test value: %q", v)
|
return fmt.Errorf("carddav: invalid filter test value: %q", string(b))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +88,8 @@ type propFilter struct {
|
|||||||
Test filterTest `xml:"test,attr,omitempty"`
|
Test filterTest `xml:"test,attr,omitempty"`
|
||||||
|
|
||||||
IsNotDefined *struct{} `xml:"is-not-defined,omitempty"`
|
IsNotDefined *struct{} `xml:"is-not-defined,omitempty"`
|
||||||
TextMatch []textMatch `xml:"text-match"`
|
TextMatch []textMatch `xml:"text-match,omitempty"`
|
||||||
ParamFilter []paramFilter `xml:"param-filter"`
|
ParamFilter []paramFilter `xml:"param-filter,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc6352#section-10.5.4
|
// https://tools.ietf.org/html/rfc6352#section-10.5.4
|
||||||
@ -128,23 +122,15 @@ func (nc negateCondition) MarshalText() ([]byte, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type matchType string
|
type matchType MatchType
|
||||||
|
|
||||||
const (
|
|
||||||
matchEquals matchType = "equals"
|
|
||||||
matchContains matchType = "contains"
|
|
||||||
matchStartsWith matchType = "starts-with"
|
|
||||||
matchEndsWith matchType = "ends-with"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (mt *matchType) UnmarshalText(b []byte) error {
|
func (mt *matchType) UnmarshalText(b []byte) error {
|
||||||
v := matchType(b)
|
switch MatchType(b) {
|
||||||
switch v {
|
case MatchEquals, MatchContains, MatchStartsWith, MatchEndsWith:
|
||||||
case matchEquals, matchContains, matchStartsWith, matchEndsWith:
|
*mt = matchType(b)
|
||||||
*mt = v
|
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("carddav: invalid match type value: %q", v)
|
return fmt.Errorf("carddav: invalid match type value: %q", string(b))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user