diff options
author | Vincent Vanackere <vincent.vanackere@gmail.com> | 2014-08-01 22:14:03 +0200 |
---|---|---|
committer | Vincent Vanackere <vincent.vanackere@gmail.com> | 2014-08-01 22:14:03 +0200 |
commit | 0e043b3393b5bd9027c702fe819d4da112f52227 (patch) | |
tree | 7ad918437fdd9fbe0d3fdb6f24ed743dcb321566 /filter.go | |
parent | filter_test : rewrite encode/decode tests to be table-driven (diff) | |
download | ldap-0e043b3393b5bd9027c702fe819d4da112f52227.tar ldap-0e043b3393b5bd9027c702fe819d4da112f52227.tar.gz ldap-0e043b3393b5bd9027c702fe819d4da112f52227.tar.bz2 ldap-0e043b3393b5bd9027c702fe819d4da112f52227.tar.lz ldap-0e043b3393b5bd9027c702fe819d4da112f52227.tar.xz ldap-0e043b3393b5bd9027c702fe819d4da112f52227.tar.zst ldap-0e043b3393b5bd9027c702fe819d4da112f52227.zip |
Diffstat (limited to 'filter.go')
-rw-r--r-- | filter.go | 30 |
1 files changed, 12 insertions, 18 deletions
@@ -24,7 +24,7 @@ const ( FilterExtensibleMatch = 9 ) -var FilterMap = map[uint64]string{ +var filterMap = map[uint8]string{ FilterAnd: "And", FilterOr: "Or", FilterNot: "Not", @@ -43,12 +43,6 @@ const ( FilterSubstringsFinal = 2 ) -var FilterSubstringsMap = map[uint64]string{ - FilterSubstringsInitial: "Substrings Initial", - FilterSubstringsAny: "Substrings Any", - FilterSubstringsFinal: "Substrings Final", -} - func CompileFilter(filter string) (*ber.Packet, error) { if len(filter) == 0 || filter[0] != '(' { return nil, NewError(ErrorFilterCompile, errors.New("ldap: filter does not start with an '('")) @@ -169,15 +163,15 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { newPos++ return packet, newPos, err case '&': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterAnd, nil, FilterMap[FilterAnd]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterAnd, nil, filterMap[FilterAnd]) newPos, err = compileFilterSet(filter, pos+1, packet) return packet, newPos, err case '|': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterOr, nil, FilterMap[FilterOr]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterOr, nil, filterMap[FilterOr]) newPos, err = compileFilterSet(filter, pos+1, packet) return packet, newPos, err case '!': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterNot, nil, FilterMap[FilterNot]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterNot, nil, filterMap[FilterNot]) var child *ber.Packet child, newPos, err = compileFilter(filter, pos+1) packet.AppendChild(child) @@ -190,15 +184,15 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { case packet != nil: condition += fmt.Sprintf("%c", filter[newPos]) case filter[newPos] == '=': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterEqualityMatch, nil, FilterMap[FilterEqualityMatch]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterEqualityMatch, nil, filterMap[FilterEqualityMatch]) case filter[newPos] == '>' && filter[newPos+1] == '=': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterGreaterOrEqual, nil, FilterMap[FilterGreaterOrEqual]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterGreaterOrEqual, nil, filterMap[FilterGreaterOrEqual]) newPos++ case filter[newPos] == '<' && filter[newPos+1] == '=': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterLessOrEqual, nil, FilterMap[FilterLessOrEqual]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterLessOrEqual, nil, filterMap[FilterLessOrEqual]) newPos++ case filter[newPos] == '~' && filter[newPos+1] == '=': - packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterApproxMatch, nil, FilterMap[FilterLessOrEqual]) + packet = ber.Encode(ber.ClassContext, ber.TypeConstructed, FilterApproxMatch, nil, filterMap[FilterLessOrEqual]) newPos++ case packet == nil: attribute += fmt.Sprintf("%c", filter[newPos]) @@ -217,7 +211,7 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { if packet.Tag == FilterEqualityMatch && condition == "*" { packet.TagType = ber.TypePrimitive packet.Tag = FilterPresent - packet.Description = FilterMap[uint64(packet.Tag)] + packet.Description = filterMap[packet.Tag] packet.Data.WriteString(attribute) return packet, newPos + 1, nil } @@ -226,21 +220,21 @@ func compileFilter(filter string, pos int) (*ber.Packet, int, error) { case packet.Tag == FilterEqualityMatch && condition[0] == '*' && condition[len(condition)-1] == '*': // Any packet.Tag = FilterSubstrings - packet.Description = FilterMap[uint64(packet.Tag)] + packet.Description = filterMap[packet.Tag] seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings") seq.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, FilterSubstringsAny, condition[1:len(condition)-1], "Any Substring")) packet.AppendChild(seq) case packet.Tag == FilterEqualityMatch && condition[0] == '*': // Final packet.Tag = FilterSubstrings - packet.Description = FilterMap[uint64(packet.Tag)] + packet.Description = filterMap[packet.Tag] seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings") seq.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, FilterSubstringsFinal, condition[1:], "Final Substring")) packet.AppendChild(seq) case packet.Tag == FilterEqualityMatch && condition[len(condition)-1] == '*': // Initial packet.Tag = FilterSubstrings - packet.Description = FilterMap[uint64(packet.Tag)] + packet.Description = filterMap[packet.Tag] seq := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "Substrings") seq.AppendChild(ber.NewString(ber.ClassContext, ber.TypePrimitive, FilterSubstringsInitial, condition[:len(condition)-1], "Initial Substring")) packet.AppendChild(seq) |