carddav: add full query AST

This commit is contained in:
Simon Ser 2020-01-24 11:25:58 +01:00
parent e56ab47c43
commit 5ada08f6ab
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 54 additions and 25 deletions

View File

@ -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

View File

@ -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))
} }
} }