summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Vanackere <vincent.vanackere@gmail.com>2014-08-01 22:14:03 +0200
committerVincent Vanackere <vincent.vanackere@gmail.com>2014-08-01 22:14:03 +0200
commit0e043b3393b5bd9027c702fe819d4da112f52227 (patch)
tree7ad918437fdd9fbe0d3fdb6f24ed743dcb321566
parentfilter_test : rewrite encode/decode tests to be table-driven (diff)
downloadldap-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
-rw-r--r--filter.go30
-rw-r--r--filter_test.go4
2 files changed, 14 insertions, 20 deletions
diff --git a/filter.go b/filter.go
index 30e2f9f..690f67d 100644
--- a/filter.go
+++ b/filter.go
@@ -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)
diff --git a/filter_test.go b/filter_test.go
index a771cff..baecab9 100644
--- a/filter_test.go
+++ b/filter_test.go
@@ -9,7 +9,7 @@ import (
type compileTest struct {
filterStr string
- filterType int
+ filterType uint8
}
var testFilters = []compileTest{
@@ -34,7 +34,7 @@ func TestFilter(t *testing.T) {
if err != nil {
t.Errorf("Problem compiling %s - %s", i.filterStr, err.Error())
} else if filter.Tag != uint8(i.filterType) {
- t.Errorf("%q Expected %q got %q", i.filterStr, FilterMap[uint64(i.filterType)], FilterMap[uint64(filter.Tag)])
+ t.Errorf("%q Expected %q got %q", i.filterStr, filterMap[i.filterType], filterMap[filter.Tag])
} else {
o, err := DecompileFilter(filter)
if err != nil {