summaryrefslogtreecommitdiffstats
path: root/server.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-07-20 18:27:43 +0200
committerGitHub <noreply@github.com>2021-07-20 18:27:43 +0200
commit7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80 (patch)
tree16215733e543353c2bd5efd1dcf89c7879e2ad3d /server.go
parentFixed handling of UTF8 chars in filter value (#9) (diff)
downloadldap-7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80.tar
ldap-7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80.tar.gz
ldap-7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80.tar.bz2
ldap-7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80.tar.lz
ldap-7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80.tar.xz
ldap-7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80.tar.zst
ldap-7f8d1e44eeba4156c0a258b6a1af47cb0a7e2d80.zip
Diffstat (limited to 'server.go')
-rw-r--r--server.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/server.go b/server.go
index 3576475..24b1e77 100644
--- a/server.go
+++ b/server.go
@@ -376,14 +376,20 @@ func sendPacket(conn net.Conn, packet *ber.Packet) error {
//
func routeFunc(dn string, funcNames []string) string {
bestPick := ""
+ bestPickWeight := 0
+ dnMatch := "," + strings.ToLower(dn)
+ var weight int
for _, fn := range funcNames {
- if strings.HasSuffix(dn, fn) {
- l := len(strings.Split(bestPick, ","))
- if bestPick == "" {
- l = 0
+ if strings.HasSuffix(dnMatch, "," + fn) {
+ // empty string as 0, no-comma string 1 , etc
+ if fn == "" {
+ weight = 0
+ } else {
+ weight = strings.Count(fn, ",") + 1
}
- if len(strings.Split(fn, ",")) > l {
+ if weight > bestPickWeight {
bestPick = fn
+ bestPickWeight = weight
}
}
}