Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
openldap
OpenLDAP
Commits
e36d1e31
Commit
e36d1e31
authored
Mar 24, 2021
by
Ondřej Kuzník
Browse files
ITS#9001 manual changes
parent
51c444b0
Changes
67
Hide whitespace changes
Inline
Side-by-side
contrib/slapd-modules/authzid/authzid.c
View file @
e36d1e31
...
...
@@ -71,7 +71,7 @@ authzid_conn_find( Connection *c )
authzid_conn_t
*
ac
=
NULL
,
tmp
=
{
0
};
tmp
.
conn
=
c
;
ac
=
(
authzid_conn_t
*
)
avl_find
(
authzid_tree
,
(
caddr_t
)
&
tmp
,
authzid_conn_cmp
);
ac
=
(
authzid_conn_t
*
)
ldap_
avl_find
(
authzid_tree
,
(
caddr_t
)
&
tmp
,
authzid_conn_cmp
);
if
(
ac
==
NULL
||
(
ac
!=
NULL
&&
ac
->
refcnt
!=
0
)
)
{
ac
=
NULL
;
}
...
...
@@ -121,7 +121,7 @@ authzid_conn_insert( Connection *c, char flag )
ac
->
conn
=
c
;
ac
->
refcnt
=
0
;
ac
->
authzid_flag
=
flag
;
rc
=
avl_insert
(
&
authzid_tree
,
(
caddr_t
)
ac
,
rc
=
ldap_
avl_insert
(
&
authzid_tree
,
(
caddr_t
)
ac
,
authzid_conn_cmp
,
authzid_conn_dup
);
ldap_pvt_thread_mutex_unlock
(
&
authzid_mutex
);
...
...
@@ -139,7 +139,7 @@ authzid_conn_remove( Connection *c )
ldap_pvt_thread_mutex_unlock
(
&
authzid_mutex
);
return
-
1
;
}
tmp
=
avl_delete
(
&
authzid_tree
,
(
caddr_t
)
ac
,
authzid_conn_cmp
);
tmp
=
ldap_
avl_delete
(
&
authzid_tree
,
(
caddr_t
)
ac
,
authzid_conn_cmp
);
ldap_pvt_thread_mutex_unlock
(
&
authzid_mutex
);
assert
(
tmp
==
ac
);
...
...
contrib/slapd-modules/vc/vc.c
View file @
e36d1e31
...
...
@@ -281,7 +281,7 @@ vc_exop(
AC_MEMCPY
(
(
char
*
)
&
tmp
.
conn
,
(
const
char
*
)
cookie
.
bv_val
,
cookie
.
bv_len
);
ldap_pvt_thread_mutex_lock
(
&
vc_mutex
);
conn
=
(
vc_conn_t
*
)
avl_find
(
vc_tree
,
(
caddr_t
)
&
tmp
,
vc_conn_cmp
);
conn
=
(
vc_conn_t
*
)
ldap_
avl_find
(
vc_tree
,
(
caddr_t
)
&
tmp
,
vc_conn_cmp
);
if
(
conn
==
NULL
||
(
conn
!=
NULL
&&
conn
->
refcnt
!=
0
)
)
{
conn
=
NULL
;
ldap_pvt_thread_mutex_unlock
(
&
vc_mutex
);
...
...
@@ -376,7 +376,7 @@ done:;
conn
->
conn
=
conn
;
conn
->
refcnt
--
;
ldap_pvt_thread_mutex_lock
(
&
vc_mutex
);
rc
=
avl_insert
(
&
vc_tree
,
(
caddr_t
)
conn
,
rc
=
ldap_
avl_insert
(
&
vc_tree
,
(
caddr_t
)
conn
,
vc_conn_cmp
,
vc_conn_dup
);
ldap_pvt_thread_mutex_unlock
(
&
vc_mutex
);
assert
(
rc
==
0
);
...
...
@@ -392,7 +392,7 @@ done:;
vc_conn_t
*
tmp
;
ldap_pvt_thread_mutex_lock
(
&
vc_mutex
);
tmp
=
avl_delete
(
&
vc_tree
,
(
caddr_t
)
conn
,
vc_conn_cmp
);
tmp
=
ldap_
avl_delete
(
&
vc_tree
,
(
caddr_t
)
conn
,
vc_conn_cmp
);
ldap_pvt_thread_mutex_unlock
(
&
vc_mutex
);
}
SLAP_FREE
(
conn
);
...
...
include/avl.h
→
include/
ldap_
avl.h
View file @
e36d1e31
/* avl.h - avl tree definitions */
/*
ldap_
avl.h - avl tree definitions */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
...
...
@@ -73,15 +73,15 @@ struct tavlnode {
#define AVL_THREAD 1
/* avl routines */
#define avl_getone(x) ((x) == 0 ? 0 : (x)->avl_data)
#define avl_onenode(x) ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
#define
ldap_
avl_getone(x) ((x) == 0 ? 0 : (x)->avl_data)
#define
ldap_
avl_onenode(x) ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
#endif
/* AVL_INTERNALS */
#define avl_child(x,dir) ((x)->avl_bits[dir]) == AVL_CHILD ? \
#define
ldap_
avl_child(x,dir) ((x)->avl_bits[dir]) == AVL_CHILD ? \
(x)->avl_link[dir] : NULL
#define avl_lchild(x) avl_child(x,0)
#define avl_rchild(x) avl_child(x,1)
#define
ldap_
avl_lchild(x)
ldap_
avl_child(x,0)
#define
ldap_
avl_rchild(x)
ldap_
avl_child(x,1)
typedef
int
(
*
AVL_APPLY
)
LDAP_P
((
void
*
,
void
*
));
typedef
int
(
*
AVL_CMP
)
LDAP_P
((
const
void
*
,
const
void
*
));
...
...
@@ -89,69 +89,69 @@ typedef int (*AVL_DUP) LDAP_P((void*, void*));
typedef
void
(
*
AVL_FREE
)
LDAP_P
((
void
*
));
LDAP_AVL_F
(
int
)
avl_free
LDAP_P
((
Avlnode
*
root
,
AVL_FREE
dfree
));
ldap_
avl_free
LDAP_P
((
Avlnode
*
root
,
AVL_FREE
dfree
));
LDAP_AVL_F
(
int
)
avl_insert
LDAP_P
((
Avlnode
**
,
void
*
,
AVL_CMP
,
AVL_DUP
));
ldap_
avl_insert
LDAP_P
((
Avlnode
**
,
void
*
,
AVL_CMP
,
AVL_DUP
));
LDAP_AVL_F
(
void
*
)
avl_delete
LDAP_P
((
Avlnode
**
,
void
*
,
AVL_CMP
));
ldap_
avl_delete
LDAP_P
((
Avlnode
**
,
void
*
,
AVL_CMP
));
LDAP_AVL_F
(
void
*
)
avl_find
LDAP_P
((
Avlnode
*
,
const
void
*
,
AVL_CMP
));
ldap_
avl_find
LDAP_P
((
Avlnode
*
,
const
void
*
,
AVL_CMP
));
LDAP_AVL_F
(
Avlnode
*
)
avl_find2
LDAP_P
((
Avlnode
*
,
const
void
*
,
AVL_CMP
));
ldap_
avl_find2
LDAP_P
((
Avlnode
*
,
const
void
*
,
AVL_CMP
));
LDAP_AVL_F
(
void
*
)
avl_find_lin
LDAP_P
((
Avlnode
*
,
const
void
*
,
AVL_CMP
));
ldap_
avl_find_lin
LDAP_P
((
Avlnode
*
,
const
void
*
,
AVL_CMP
));
#ifdef AVL_NONREENTRANT
LDAP_AVL_F
(
void
*
)
avl_getfirst
LDAP_P
((
Avlnode
*
));
ldap_
avl_getfirst
LDAP_P
((
Avlnode
*
));
LDAP_AVL_F
(
void
*
)
avl_getnext
LDAP_P
((
void
));
ldap_
avl_getnext
LDAP_P
((
void
));
#endif
LDAP_AVL_F
(
int
)
avl_dup_error
LDAP_P
((
void
*
,
void
*
));
ldap_
avl_dup_error
LDAP_P
((
void
*
,
void
*
));
LDAP_AVL_F
(
int
)
avl_dup_ok
LDAP_P
((
void
*
,
void
*
));
ldap_
avl_dup_ok
LDAP_P
((
void
*
,
void
*
));
LDAP_AVL_F
(
int
)
avl_apply
LDAP_P
((
Avlnode
*
,
AVL_APPLY
,
void
*
,
int
,
int
));
ldap_
avl_apply
LDAP_P
((
Avlnode
*
,
AVL_APPLY
,
void
*
,
int
,
int
));
LDAP_AVL_F
(
int
)
avl_prefixapply
LDAP_P
((
Avlnode
*
,
void
*
,
AVL_CMP
,
void
*
,
AVL_CMP
,
void
*
,
int
));
ldap_
avl_prefixapply
LDAP_P
((
Avlnode
*
,
void
*
,
AVL_CMP
,
void
*
,
AVL_CMP
,
void
*
,
int
));
LDAP_AVL_F
(
int
)
tavl_free
LDAP_P
((
TAvlnode
*
root
,
AVL_FREE
dfree
));
ldap_
tavl_free
LDAP_P
((
TAvlnode
*
root
,
AVL_FREE
dfree
));
LDAP_AVL_F
(
int
)
tavl_insert
LDAP_P
((
TAvlnode
**
,
void
*
,
AVL_CMP
,
AVL_DUP
));
ldap_
tavl_insert
LDAP_P
((
TAvlnode
**
,
void
*
,
AVL_CMP
,
AVL_DUP
));
LDAP_AVL_F
(
void
*
)
tavl_delete
LDAP_P
((
TAvlnode
**
,
void
*
,
AVL_CMP
));
ldap_
tavl_delete
LDAP_P
((
TAvlnode
**
,
void
*
,
AVL_CMP
));
LDAP_AVL_F
(
void
*
)
tavl_find
LDAP_P
((
TAvlnode
*
,
const
void
*
,
AVL_CMP
));
ldap_
tavl_find
LDAP_P
((
TAvlnode
*
,
const
void
*
,
AVL_CMP
));
LDAP_AVL_F
(
TAvlnode
*
)
tavl_find2
LDAP_P
((
TAvlnode
*
,
const
void
*
,
AVL_CMP
));
ldap_
tavl_find2
LDAP_P
((
TAvlnode
*
,
const
void
*
,
AVL_CMP
));
LDAP_AVL_F
(
TAvlnode
*
)
tavl_find3
LDAP_P
((
TAvlnode
*
,
const
void
*
,
AVL_CMP
,
int
*
ret
));
ldap_
tavl_find3
LDAP_P
((
TAvlnode
*
,
const
void
*
,
AVL_CMP
,
int
*
ret
));
#define TAVL_DIR_LEFT 0
#define TAVL_DIR_RIGHT 1
LDAP_AVL_F
(
TAvlnode
*
)
tavl_end
LDAP_P
((
TAvlnode
*
,
int
direction
));
ldap_
tavl_end
LDAP_P
((
TAvlnode
*
,
int
direction
));
LDAP_AVL_F
(
TAvlnode
*
)
tavl_next
LDAP_P
((
TAvlnode
*
,
int
direction
));
ldap_
tavl_next
LDAP_P
((
TAvlnode
*
,
int
direction
));
/* apply traversal types */
#define AVL_PREORDER 1
...
...
libraries/libldap/Makefile.in
View file @
e36d1e31
...
...
@@ -15,7 +15,7 @@
LIBRARY
=
libldap.la
PROGRAMS
=
apitest dntest ftest ltest urltest
PROGRAMS
=
apitest dntest ftest ltest urltest
testavl
SRCS
=
bind.c open.c result.c error.c compare.c search.c
\
controls.c messages.c references.c extended.c cyrus.c
\
...
...
@@ -31,7 +31,7 @@ SRCS = bind.c open.c result.c error.c compare.c search.c \
assertion.c deref.c ldifutil.c ldif.c fetch.c lbase64.c
\
msctrl.c psearchctrl.c threads.c rdwr.c tpool.c rq.c
\
thr_posix.c thr_thr.c thr_nt.c thr_pth.c thr_debug.c
\
account_usability.c
account_usability.c
avl.c tavl.c testavl.c
OBJS
=
bind.lo open.lo result.lo error.lo compare.lo search.lo
\
controls.lo messages.lo references.lo extended.lo cyrus.lo
\
...
...
@@ -47,7 +47,7 @@ OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \
assertion.lo deref.lo ldifutil.lo ldif.lo fetch.lo lbase64.lo
\
msctrl.lo psearchctrl.lo threads.lo rdwr.lo tpool.lo rq.lo
\
thr_posix.lo thr_thr.lo thr_nt.lo thr_pth.lo thr_debug.lo
\
account_usability.lo
account_usability.lo
avl.lo tavl.lo
LDAP_INCDIR
=
../../include
LDAP_LIBDIR
=
../../libraries
...
...
@@ -70,9 +70,14 @@ ftest: $(XLIBS) ftest.o
$(LTLINK)
-o
$@
ftest.o
$(LIBS)
ltest
:
$(XLIBS) test.o
$(LTLINK)
-o
$@
test.o
$(LIBS)
testavl
:
$(XLIBS) testavl.o
$(LTLINK)
-o
$@
testavl.o
$(LIBS)
testtavl
:
$(XLIBS) testtavl.o
$(LTLINK)
-o
$@
testtavl.o
$(LIBS)
urltest
:
$(XLIBS) urltest.o
$(LTLINK)
-o
$@
urltest.o
$(LIBS)
CFFILES
=
ldap.conf
install-local
:
$(CFFILES) FORCE
...
...
libraries/libl
util
/avl.c
→
libraries/libl
dap
/avl.c
View file @
e36d1e31
...
...
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-202
1
The OpenLDAP Foundation.
* Copyright 1998-202
0
The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
...
...
@@ -47,7 +47,7 @@
#endif
#define AVL_INTERNAL
#include
"avl.h"
#include
"
ldap_
avl.h"
/* Maximum tree depth this host's address space could support */
#define MAX_TREE_DEPTH (sizeof(void *) * CHAR_BIT)
...
...
@@ -55,13 +55,13 @@
static
const
int
avl_bfs
[]
=
{
LH
,
RH
};
/*
* avl_insert -- insert a node containing data data into the avl tree
*
ldap_
avl_insert -- insert a node containing data data into the avl tree
* with root root. fcmp is a function to call to compare the data portion
* of two nodes. it should take two arguments and return <, >, or == 0,
* depending on whether its first argument is <, >, or == its second
* argument (like strcmp, e.g.). fdup is a function to call when a duplicate
* node is inserted. it should return 0, or -1 and its return value
* will be the return value from avl_insert in the case of a duplicate node.
* will be the return value from
ldap_
avl_insert in the case of a duplicate node.
* the function will be called with the original node's data as its first
* argument and with the incoming duplicate node's data as its second
* argument. this could be used, for example, to keep a count with each
...
...
@@ -70,7 +70,7 @@ static const int avl_bfs[] = {LH, RH};
* NOTE: this routine may malloc memory
*/
int
avl_insert
(
Avlnode
**
root
,
void
*
data
,
AVL_CMP
fcmp
,
AVL_DUP
fdup
)
ldap_
avl_insert
(
Avlnode
**
root
,
void
*
data
,
AVL_CMP
fcmp
,
AVL_DUP
fdup
)
{
Avlnode
*
t
,
*
p
,
*
s
,
*
q
,
*
r
;
int
a
,
cmp
,
ncmp
;
...
...
@@ -180,7 +180,7 @@ avl_insert( Avlnode ** root, void *data, AVL_CMP fcmp, AVL_DUP fdup )
}
void
*
avl_delete
(
Avlnode
**
root
,
void
*
data
,
AVL_CMP
fcmp
)
ldap_
avl_delete
(
Avlnode
**
root
,
void
*
data
,
AVL_CMP
fcmp
)
{
Avlnode
*
p
,
*
q
,
*
r
,
*
top
;
int
side
,
side_bf
,
shorter
,
nside
;
...
...
@@ -207,7 +207,7 @@ avl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
if
(
p
==
NULL
)
return
p
;
}
data
=
p
->
avl_data
;
data
=
p
->
avl_data
;
/* If this node has two children, swap so we are deleting a node with
* at most one child.
...
...
@@ -268,7 +268,7 @@ avl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
top
=
NULL
;
shorter
=
1
;
while
(
shorter
)
{
p
=
pptr
[
depth
];
side
=
pdir
[
depth
];
...
...
@@ -280,7 +280,7 @@ avl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
/* Tree is now heavier on opposite side */
p
->
avl_bf
=
avl_bfs
[
nside
];
shorter
=
0
;
}
else
if
(
p
->
avl_bf
==
side_bf
)
{
/* case 2: taller subtree shortened, height reduced */
p
->
avl_bf
=
EH
;
...
...
@@ -358,7 +358,7 @@ avl_inapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
return
(
AVL_NOMORE
);
if
(
root
->
avl_left
!=
0
)
if
(
avl_inapply
(
root
->
avl_left
,
fn
,
arg
,
stopflag
)
if
(
avl_inapply
(
root
->
avl_left
,
fn
,
arg
,
stopflag
)
==
stopflag
)
return
(
stopflag
);
...
...
@@ -378,12 +378,12 @@ avl_postapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
return
(
AVL_NOMORE
);
if
(
root
->
avl_left
!=
0
)
if
(
avl_postapply
(
root
->
avl_left
,
fn
,
arg
,
stopflag
)
if
(
avl_postapply
(
root
->
avl_left
,
fn
,
arg
,
stopflag
)
==
stopflag
)
return
(
stopflag
);
if
(
root
->
avl_right
!=
0
)
if
(
avl_postapply
(
root
->
avl_right
,
fn
,
arg
,
stopflag
)
if
(
avl_postapply
(
root
->
avl_right
,
fn
,
arg
,
stopflag
)
==
stopflag
)
return
(
stopflag
);
...
...
@@ -400,7 +400,7 @@ avl_preapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
return
(
stopflag
);
if
(
root
->
avl_left
!=
0
)
if
(
avl_preapply
(
root
->
avl_left
,
fn
,
arg
,
stopflag
)
if
(
avl_preapply
(
root
->
avl_left
,
fn
,
arg
,
stopflag
)
==
stopflag
)
return
(
stopflag
);
...
...
@@ -411,7 +411,7 @@ avl_preapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
}
/*
* avl_apply -- avl tree root is traversed, function fn is called with
*
ldap_
avl_apply -- avl tree root is traversed, function fn is called with
* arguments arg and the data portion of each node. if fn returns stopflag,
* the traversal is cut short, otherwise it continues. Do not use -6 as
* a stopflag, as this is what is used to indicate the traversal ran out
...
...
@@ -419,7 +419,7 @@ avl_preapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
*/
int
avl_apply
(
Avlnode
*
root
,
AVL_APPLY
fn
,
void
*
arg
,
int
stopflag
,
int
type
)
ldap_
avl_apply
(
Avlnode
*
root
,
AVL_APPLY
fn
,
void
*
arg
,
int
stopflag
,
int
type
)
{
switch
(
type
)
{
case
AVL_INORDER
:
...
...
@@ -437,18 +437,18 @@ avl_apply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag, int type )
}
/*
* avl_prefixapply - traverse avl tree root, applying function fprefix
*
ldap_
avl_prefixapply - traverse avl tree root, applying function fprefix
* to any nodes that match. fcmp is called with data as its first arg
* and the current node's data as its second arg. it should return
* 0 if they match, < 0 if data is less, and > 0 if data is greater.
* the idea is to efficiently find all nodes that are prefixes of
* some key... Like avl_apply, this routine also takes a stopflag
* some key... Like
ldap_
avl_apply, this routine also takes a stopflag
* and will return prematurely if fmatch returns this value. Otherwise,
* AVL_NOMORE is returned.
*/
int
avl_prefixapply
(
ldap_
avl_prefixapply
(
Avlnode
*
root
,
void
*
data
,
AVL_CMP
fmatch
,
...
...
@@ -469,23 +469,23 @@ avl_prefixapply(
return
(
stopflag
);
if
(
root
->
avl_left
!=
0
)
if
(
avl_prefixapply
(
root
->
avl_left
,
data
,
fmatch
,
if
(
ldap_
avl_prefixapply
(
root
->
avl_left
,
data
,
fmatch
,
marg
,
fcmp
,
carg
,
stopflag
)
==
stopflag
)
return
(
stopflag
);
if
(
root
->
avl_right
!=
0
)
return
(
avl_prefixapply
(
root
->
avl_right
,
data
,
fmatch
,
return
(
ldap_
avl_prefixapply
(
root
->
avl_right
,
data
,
fmatch
,
marg
,
fcmp
,
carg
,
stopflag
)
);
else
return
(
AVL_NOMORE
);
}
else
if
(
cmp
<
0
)
{
if
(
root
->
avl_left
!=
0
)
return
(
avl_prefixapply
(
root
->
avl_left
,
data
,
fmatch
,
return
(
ldap_
avl_prefixapply
(
root
->
avl_left
,
data
,
fmatch
,
marg
,
fcmp
,
carg
,
stopflag
)
);
}
else
{
if
(
root
->
avl_right
!=
0
)
return
(
avl_prefixapply
(
root
->
avl_right
,
data
,
fmatch
,
return
(
ldap_
avl_prefixapply
(
root
->
avl_right
,
data
,
fmatch
,
marg
,
fcmp
,
carg
,
stopflag
)
);
}
...
...
@@ -493,13 +493,13 @@ avl_prefixapply(
}
/*
* avl_free -- traverse avltree root, freeing the memory it is using.
*
ldap_
avl_free -- traverse avltree root, freeing the memory it is using.
* the dfree() is called to free the data portion of each node. The
* number of items actually freed is returned.
*/
int
avl_free
(
Avlnode
*
root
,
AVL_FREE
dfree
)
ldap_
avl_free
(
Avlnode
*
root
,
AVL_FREE
dfree
)
{
int
nleft
,
nright
;
...
...
@@ -508,10 +508,10 @@ avl_free( Avlnode *root, AVL_FREE dfree )
nleft
=
nright
=
0
;
if
(
root
->
avl_left
!=
0
)
nleft
=
avl_free
(
root
->
avl_left
,
dfree
);
nleft
=
ldap_
avl_free
(
root
->
avl_left
,
dfree
);
if
(
root
->
avl_right
!=
0
)
nright
=
avl_free
(
root
->
avl_right
,
dfree
);
nright
=
ldap_
avl_free
(
root
->
avl_right
,
dfree
);
if
(
dfree
)
(
*
dfree
)(
root
->
avl_data
);
...
...
@@ -521,14 +521,14 @@ avl_free( Avlnode *root, AVL_FREE dfree )
}
/*
* avl_find -- search avltree root for a node with data data. the function
* cmp is used to compare things. it is called with data as its first arg
*
ldap_
avl_find -- search avltree root for a node with data data. the function
* cmp is used to compare things. it is called with data as its first arg
* and the current node data as its second. it should return 0 if they match,
* < 0 if arg1 is less than arg2 and > 0 if arg1 is greater than arg2.
*/
Avlnode
*
avl_find2
(
Avlnode
*
root
,
const
void
*
data
,
AVL_CMP
fcmp
)
ldap_
avl_find2
(
Avlnode
*
root
,
const
void
*
data
,
AVL_CMP
fcmp
)
{
int
cmp
;
...
...
@@ -540,7 +540,7 @@ avl_find2( Avlnode *root, const void *data, AVL_CMP fcmp )
}
void
*
avl_find
(
Avlnode
*
root
,
const
void
*
data
,
AVL_CMP
fcmp
)
ldap_
avl_find
(
Avlnode
*
root
,
const
void
*
data
,
AVL_CMP
fcmp
)
{
int
cmp
;
...
...
@@ -553,14 +553,14 @@ avl_find( Avlnode *root, const void* data, AVL_CMP fcmp )
}
/*
* avl_find_lin -- search avltree root linearly for a node with data data.
*
ldap_
avl_find_lin -- search avltree root linearly for a node with data data.
* the function cmp is used to compare things. it is called with data as its
* first arg and the current node data as its second. it should return 0 if
* they match, non-zero otherwise.
*/
void
*
avl_find_lin
(
Avlnode
*
root
,
const
void
*
data
,
AVL_CMP
fcmp
)
ldap_
avl_find_lin
(
Avlnode
*
root
,
const
void
*
data
,
AVL_CMP
fcmp
)
{
void
*
res
;
...
...
@@ -571,21 +571,21 @@ avl_find_lin( Avlnode *root, const void* data, AVL_CMP fcmp )
return
(
root
->
avl_data
);
if
(
root
->
avl_left
!=
0
)
if
(
(
res
=
avl_find_lin
(
root
->
avl_left
,
data
,
fcmp
))
if
(
(
res
=
ldap_
avl_find_lin
(
root
->
avl_left
,
data
,
fcmp
))
!=
NULL
)
return
(
res
);
if
(
root
->
avl_right
==
0
)
return
(
NULL
);
else
return
(
avl_find_lin
(
root
->
avl_right
,
data
,
fcmp
)
);
return
(
ldap_
avl_find_lin
(
root
->
avl_right
,
data
,
fcmp
)
);
}
/* NON-REENTRANT INTERFACE */
static
void
*
*
avl_list
;
static
int
avl_maxlist
;
static
int
avl_nextlist
;
static
int
ldap_
avl_nextlist
;
#define AVL_GRABSIZE 100
...
...
@@ -611,61 +611,61 @@ avl_buildlist( void* data, void* arg )
}
/*
* avl_getfirst() and avl_getnext() are provided as alternate tree
*
ldap_
avl_getfirst() and
ldap_
avl_getnext() are provided as alternate tree
* traversal methods, to be used when a single function cannot be
* provided to be called with every node in the tree. avl_getfirst()
* provided to be called with every node in the tree.
ldap_
avl_getfirst()
* traverses the tree and builds a linear list of all the nodes,
* returning the first node. avl_getnext() returns the next thing
* on the list built by avl_getfirst(). This means that avl_getfirst()
* returning the first node.
ldap_
avl_getnext() returns the next thing
* on the list built by
ldap_
avl_getfirst(). This means that
ldap_
avl_getfirst()
* can take a while, and that the tree should not be messed with while
* being traversed in this way, and that multiple traversals (even of
* different trees) cannot be active at once.
*/
void
*
avl_getfirst
(
Avlnode
*
root
)
ldap_
avl_getfirst
(
Avlnode
*
root
)
{
if
(
avl_list
)
{
ber_memfree
(
(
char
*
)
avl_list
);
avl_list
=
(
void
*
*
)
0
;
}
avl_maxlist
=
0
;
avl_nextlist
=
0
;
ldap_
avl_nextlist
=
0
;
if
(
root
==
0
)
return
(
0
);
(
void
)
avl_apply
(
root
,
avl_buildlist
,
(
void
*
)
0
,
-
1
,
AVL_INORDER
);
(
void
)
ldap_
avl_apply
(
root
,
avl_buildlist
,
(
void
*
)
0
,
-
1
,
AVL_INORDER
);
return
(
avl_list
[
avl_nextlist
++
]
);
return
(
avl_list
[
ldap_
avl_nextlist
++
]
);
}
void
*
avl_getnext
(
void
)
ldap_
avl_getnext
(
void
)
{
if
(
avl_list
==
0
)
return
(
0
);
if
(
avl_nextlist
==
avl_maxlist
)
{
if
(
ldap_
avl_nextlist
==
avl_maxlist
)
{
ber_memfree
(
(
void
*
)
avl_list
);
avl_list
=
(
void
*
*
)
0
;
return
(
0
);
}
return
(
avl_list
[
avl_nextlist
++
]
);
return
(
avl_list
[
ldap_
avl_nextlist
++
]
);
}
/* end non-reentrant code */
int
avl_dup_error
(
void
*
left
,
void
*
right
)
ldap_
avl_dup_error
(
void
*
left
,
void
*
right
)
{
return
(
-
1
);
}
int
avl_dup_ok
(
void
*
left
,
void
*
right
)
ldap_
avl_dup_ok
(
void
*
left
,
void
*
right
)
{
return
(
0
);
}
libraries/libl
util
/tavl.c
→
libraries/libl
dap
/tavl.c
View file @
e36d1e31
...
...
@@ -2,7 +2,7 @@
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 2005-202
1
The OpenLDAP Foundation.
* Copyright 2005-202
0
The OpenLDAP Foundation.
* Portions Copyright (c) 2005 by Howard Chu, Symas Corp.
* All rights reserved.
*
...
...
@@ -34,7 +34,7 @@
#endif
#define AVL_INTERNAL
#include
"avl.h"
#include
"
ldap_
avl.h"
/* Maximum tree depth this host's address space could support */
#define MAX_TREE_DEPTH (sizeof(void *) * CHAR_BIT)
...
...
@@ -45,13 +45,13 @@ static const int avl_bfs[] = {LH, RH};
* Threaded AVL trees - for fast in-order traversal of nodes.
*/
/*
* tavl_insert -- insert a node containing data data into the avl tree
*
ldap_
tavl_insert -- insert a node containing data data into the avl tree
* with root root. fcmp is a function to call to compare the data portion
* of two nodes. it should take two arguments and return <, >, or == 0,
* depending on whether its first argument is <, >, or == its second
* argument (like strcmp, e.g.). fdup is a function to call when a duplicate
* node is inserted. it should return 0, or -1 and its return value
* will be the return value from avl_insert in the case of a duplicate node.
* will be the return value from
ldap_
avl_insert in the case of a duplicate node.
* the function will be called with the original node's data as its first
* argument and with the incoming duplicate node's data as its second
* argument. this could be used, for example, to keep a count with each
...
...
@@ -60,7 +60,7 @@ static const int avl_bfs[] = {LH, RH};
* NOTE: this routine may malloc memory
*/
int
tavl_insert
(
TAvlnode
**
root
,
void
*
data
,
AVL_CMP
fcmp
,
AVL_DUP
fdup
)
ldap_
tavl_insert
(
TAvlnode
**
root
,
void
*
data
,
AVL_CMP
fcmp
,
AVL_DUP
fdup
)
{
TAvlnode
*
t
,
*
p
,
*
s
,
*
q
,
*
r
;
int
a
,
cmp
,
ncmp
;
...
...
@@ -88,7 +88,7 @@ tavl_insert( TAvlnode ** root, void *data, AVL_CMP fcmp, AVL_DUP fdup )
return
(
*
fdup
)(
p
->
avl_data
,
data
);
cmp
=
(
cmp
>
0
);
q
=
avl_child
(
p
,
cmp
);
q
=
ldap_
avl_child
(
p
,
cmp
);
if
(
q
==
NULL
)
{
/* insert */
if
((
q
=
(
TAvlnode
*
)
ber_memalloc
(
sizeof
(
TAvlnode
)))
==
NULL
)
{
...
...
@@ -187,7 +187,7 @@ tavl_insert( TAvlnode ** root, void *data, AVL_CMP fcmp, AVL_DUP fdup )
}
void
*
tavl_delete
(
TAvlnode
**
root
,
void
*
data
,
AVL_CMP
fcmp
)
ldap_
tavl_delete
(
TAvlnode
**
root
,
void
*
data
,
AVL_CMP
fcmp
)
{
TAvlnode
*
p
,
*
q
,
*
r
,
*
top
;
int
side
,
side_bf
,
shorter
,
nside
=
-
1
;
...
...
@@ -214,7 +214,7 @@ tavl_delete( TAvlnode **root, void* data, AVL_CMP fcmp )
return
NULL
;
p
=
p
->
avl_link
[
side
];
}
data
=
p
->
avl_data
;
data
=
p
->
avl_data
;
/* If this node has two children, swap so we are deleting a node with
* at most one child.
...
...
@@ -313,7 +313,7 @@ tavl_delete( TAvlnode **root, void* data, AVL_CMP fcmp )
top
=
NULL
;
shorter
=
1
;
while
(
shorter
)
{