Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Joe Martin
OpenLDAP
Commits
dd94ddba
Commit
dd94ddba
authored
Dec 17, 2006
by
Pierangelo Masarati
Browse files
don't leave dependencies on liblutil in libldap :)
parent
8830e062
Changes
5
Hide whitespace changes
Inline
Side-by-side
include/lutil.h
View file @
dd94ddba
...
...
@@ -322,13 +322,6 @@ lutil_unparse_time( char *buf, size_t buflen, unsigned long t );
} while ( 0 );
#endif
/* ! timermul */
LDAP_LUTIL_F
(
int
)
lutil_bisect_find
(
ber_int_t
*
v
,
ber_len_t
n
,
ber_int_t
id
,
int
*
idxp
);
LDAP_LUTIL_F
(
int
)
lutil_bisect_insert
(
ber_int_t
**
vp
,
ber_len_t
*
np
,
int
id
,
int
idx
);
LDAP_LUTIL_F
(
int
)
lutil_bisect_delete
(
ber_int_t
**
vp
,
ber_len_t
*
np
,
int
id
,
int
idx
);
LDAP_END_DECL
#endif
/* _LUTIL_H */
libraries/libldap/abandon.c
View file @
dd94ddba
...
...
@@ -311,9 +311,9 @@ start_again:;
/* use bisection */
i
=
0
;
if
(
ld
->
ld_nabandoned
==
0
||
l
util
_bisect_find
(
ld
->
ld_abandoned
,
ld
->
ld_nabandoned
,
msgid
,
&
i
)
==
0
)
l
dap_int
_bisect_find
(
ld
->
ld_abandoned
,
ld
->
ld_nabandoned
,
msgid
,
&
i
)
==
0
)
{
l
util
_bisect_insert
(
&
ld
->
ld_abandoned
,
&
ld
->
ld_nabandoned
,
msgid
,
i
);
l
dap_int
_bisect_insert
(
&
ld
->
ld_abandoned
,
&
ld
->
ld_nabandoned
,
msgid
,
i
);
}
if
(
err
!=
-
1
)
{
...
...
@@ -326,3 +326,155 @@ start_again:;
#endif
return
(
ld
->
ld_errno
);
}
/*
* ldap_int_bisect_find
*
* args:
* v: array of length n (in)
* n: length of array v (in)
* id: value to look for (in)
* idxp: pointer to location of value/insert point
*
* return:
* 0: not found
* 1: found
* -1: error
*/
int
ldap_int_bisect_find
(
ber_int_t
*
v
,
ber_len_t
n
,
ber_int_t
id
,
int
*
idxp
)
{
int
begin
,
end
,
i
,
rc
=
0
;
assert
(
n
>=
0
);
assert
(
id
>=
0
);
begin
=
0
;
end
=
n
-
1
;
if
(
n
>
0
)
{
if
(
id
<
v
[
begin
]
)
{
*
idxp
=
0
;
}
else
if
(
id
>
v
[
end
]
)
{
*
idxp
=
n
;
}
else
{
int
pos
;
ber_int_t
curid
;
while
(
end
>=
begin
)
{
pos
=
(
begin
+
end
)
/
2
;
curid
=
v
[
pos
];
if
(
id
<
curid
)
{
end
=
pos
-
1
;
}
else
if
(
id
>
curid
)
{
begin
=
pos
+
1
;
}
else
{
/* already abandoned? */
*
idxp
=
pos
;
rc
=
1
;
break
;
}
}
if
(
rc
==
0
)
{
*
idxp
=
pos
+
(
id
>
curid
?
1
:
0
);
}
}
}
else
{
*
idxp
=
0
;
}
return
rc
;
}
/*
* ldap_int_bisect_insert
*
* args:
* vp: pointer to array of length *np (in/out)
* np: pointer to length of array *vp (in/out)
* id: value to insert (in)
* idx: location of insert point (as computed by ldap_int_bisect_find())
*
* return:
* 0: inserted
* -1: error
*/
int
ldap_int_bisect_insert
(
ber_int_t
**
vp
,
ber_len_t
*
np
,
int
id
,
int
idx
)
{
ber_int_t
*
v
;
ber_len_t
n
;
int
i
;
assert
(
vp
!=
NULL
);
assert
(
np
!=
NULL
);
assert
(
*
np
>=
0
);
assert
(
idx
>=
0
);
assert
(
idx
<=
*
np
);
n
=
*
np
;
v
=
ber_memrealloc
(
*
vp
,
sizeof
(
ber_int_t
)
*
(
n
+
1
)
);
if
(
v
==
NULL
)
{
return
-
1
;
}
*
vp
=
v
;
for
(
i
=
n
;
i
>
idx
;
i
--
)
{
v
[
i
]
=
v
[
i
-
1
];
}
v
[
idx
]
=
id
;
++
(
*
np
);
return
0
;
}
/*
* ldap_int_bisect_delete
*
* args:
* vp: pointer to array of length *np (in/out)
* np: pointer to length of array *vp (in/out)
* id: value to delete (in)
* idx: location of value to delete (as computed by ldap_int_bisect_find())
*
* return:
* 0: deleted
*/
int
ldap_int_bisect_delete
(
ber_int_t
**
vp
,
ber_len_t
*
np
,
int
id
,
int
idx
)
{
ber_int_t
*
v
;
ber_len_t
n
;
int
i
;
assert
(
vp
!=
NULL
);
assert
(
np
!=
NULL
);
assert
(
*
np
>=
0
);
assert
(
idx
>=
0
);
assert
(
idx
<
*
np
);
v
=
*
vp
;
assert
(
v
[
idx
]
==
id
);
--
(
*
np
);
n
=
*
np
;
for
(
i
=
idx
;
i
<
n
;
i
++
)
{
v
[
i
]
=
v
[
i
+
1
];
}
return
0
;
}
libraries/libldap/ldap-int.h
View file @
dd94ddba
...
...
@@ -398,6 +398,17 @@ LDAP_V( ldap_pvt_thread_mutex_t ) ldap_int_sasl_mutex;
#define LDAP_NEXT_MSGID(ld, id) id = ++(ld)->ld_msgid
#endif
/*
* in abandon.c
*/
LDAP_F
(
int
)
ldap_int_bisect_find
(
ber_int_t
*
v
,
ber_len_t
n
,
ber_int_t
id
,
int
*
idxp
);
LDAP_F
(
int
)
ldap_int_bisect_insert
(
ber_int_t
**
vp
,
ber_len_t
*
np
,
int
id
,
int
idx
);
LDAP_F
(
int
)
ldap_int_bisect_delete
(
ber_int_t
**
vp
,
ber_len_t
*
np
,
int
id
,
int
idx
);
/*
* in init.c
*/
...
...
libraries/libldap/result.c
View file @
dd94ddba
...
...
@@ -1237,7 +1237,7 @@ ldap_abandoned( LDAP *ld, ber_int_t msgid, int *idxp )
assert
(
msgid
>=
0
);
assert
(
ld
->
ld_nabandoned
>=
0
);
return
l
util
_bisect_find
(
ld
->
ld_abandoned
,
ld
->
ld_nabandoned
,
msgid
,
idxp
);
return
l
dap_int
_bisect_find
(
ld
->
ld_abandoned
,
ld
->
ld_nabandoned
,
msgid
,
idxp
);
}
/*
...
...
@@ -1252,11 +1252,11 @@ ldap_mark_abandoned( LDAP *ld, ber_int_t msgid, int idx )
LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER
(
&
ld
->
ld_res_mutex
);
#endif
/* NOTE: those assertions are repeated in l
util
_bisect_delete() */
/* NOTE: those assertions are repeated in l
dap_int
_bisect_delete() */
assert
(
idx
>=
0
);
assert
(
idx
<
ld
->
ld_nabandoned
);
assert
(
ld
->
ld_abandoned
[
idx
]
==
msgid
);
return
l
util
_bisect_delete
(
&
ld
->
ld_abandoned
,
&
ld
->
ld_nabandoned
,
return
l
dap_int
_bisect_delete
(
&
ld
->
ld_abandoned
,
&
ld
->
ld_nabandoned
,
msgid
,
idx
);
}
libraries/liblutil/utils.c
View file @
dd94ddba
...
...
@@ -572,154 +572,3 @@ lutil_unparse_time(
return
0
;
}
/*
* lutil_bisect_find
*
* args:
* v: array of length n (in)
* n: length of array v (in)
* id: value to look for (in)
* idxp: pointer to location of value/insert point
*
* return:
* 0: not found
* 1: found
* -1: error
*/
int
lutil_bisect_find
(
ber_int_t
*
v
,
ber_len_t
n
,
ber_int_t
id
,
int
*
idxp
)
{
int
begin
,
end
,
i
,
rc
=
0
;
assert
(
n
>=
0
);
assert
(
id
>=
0
);
begin
=
0
;
end
=
n
-
1
;
if
(
n
>
0
)
{
if
(
id
<
v
[
begin
]
)
{
*
idxp
=
0
;
}
else
if
(
id
>
v
[
end
]
)
{
*
idxp
=
n
;
}
else
{
int
pos
;
ber_int_t
curid
;
while
(
end
>=
begin
)
{
pos
=
(
begin
+
end
)
/
2
;
curid
=
v
[
pos
];
if
(
id
<
curid
)
{
end
=
pos
-
1
;
}
else
if
(
id
>
curid
)
{
begin
=
pos
+
1
;
}
else
{
/* already abandoned? */
*
idxp
=
pos
;
rc
=
1
;
break
;
}
}
if
(
rc
==
0
)
{
*
idxp
=
pos
+
(
id
>
curid
?
1
:
0
);
}
}
}
else
{
*
idxp
=
0
;
}
return
rc
;
}
/*
* lutil_bisect_insert
*
* args:
* vp: pointer to array of length *np (in/out)
* np: pointer to length of array *vp (in/out)
* id: value to insert (in)
* idx: location of insert point (as computed by lutil_bosect_find())
*
* return:
* 0: inserted
* -1: error
*/
int
lutil_bisect_insert
(
ber_int_t
**
vp
,
ber_len_t
*
np
,
int
id
,
int
idx
)
{
ber_int_t
*
v
;
ber_len_t
n
;
int
i
;
assert
(
vp
!=
NULL
);
assert
(
np
!=
NULL
);
assert
(
*
np
>=
0
);
assert
(
idx
>=
0
);
assert
(
idx
<=
*
np
);
n
=
*
np
;
v
=
ber_memrealloc
(
*
vp
,
sizeof
(
ber_int_t
)
*
(
n
+
1
)
);
if
(
v
==
NULL
)
{
return
-
1
;
}
*
vp
=
v
;
for
(
i
=
n
;
i
>
idx
;
i
--
)
{
v
[
i
]
=
v
[
i
-
1
];
}
v
[
idx
]
=
id
;
++
(
*
np
);
return
0
;
}
/*
* lutil_bisect_delete
*
* args:
* vp: pointer to array of length *np (in/out)
* np: pointer to length of array *vp (in/out)
* id: value to delete (in)
* idx: location of value to delete (as computed by lutil_bosect_find())
*
* return:
* 0: deleted
*/
int
lutil_bisect_delete
(
ber_int_t
**
vp
,
ber_len_t
*
np
,
int
id
,
int
idx
)
{
ber_int_t
*
v
;
ber_len_t
n
;
int
i
;
assert
(
vp
!=
NULL
);
assert
(
np
!=
NULL
);
assert
(
*
np
>=
0
);
assert
(
idx
>=
0
);
assert
(
idx
<
*
np
);
v
=
*
vp
;
assert
(
v
[
idx
]
==
id
);
--
(
*
np
);
n
=
*
np
;
for
(
i
=
idx
;
i
<
n
;
i
++
)
{
v
[
i
]
=
v
[
i
+
1
];
}
return
0
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment