1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-11 16:58:40 +03:00

libndr: Streamline ndr_token_retrieve_cmp_fn

Rename the public function to ndr_token_peek_cmp_fn, the only user
does not remove the token. Factor out ndr_token_find to move the
token-removing logic to ndr_token_retrieve, the only caller that does
remove the token.

Keep libndr at 6.0.0, this has not been released yet.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jennifer Sutton <josutton@catalyst.net.nz>

Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Aug 29 08:40:52 UTC 2024 on atb-devel-224
This commit is contained in:
Volker Lendecke 2024-08-28 12:32:45 +02:00
parent f43ae1ab1a
commit df103890f9
4 changed files with 46 additions and 23 deletions

View File

@ -266,8 +266,8 @@ ndr_syntax_id_null: uuid = {time_low = 0, time_mid = 0, time_hi_and_version = 0,
ndr_syntax_id_to_string: char *(TALLOC_CTX *, const struct ndr_syntax_id *)
ndr_token_max_list_size: size_t (void)
ndr_token_peek: enum ndr_err_code (struct ndr_token_list *, const void *, uint32_t *)
ndr_token_peek_cmp_fn: enum ndr_err_code (struct ndr_token_list *, const void *, uint32_t *, comparison_fn_t)
ndr_token_retrieve: enum ndr_err_code (struct ndr_token_list *, const void *, uint32_t *)
ndr_token_retrieve_cmp_fn: enum ndr_err_code (struct ndr_token_list *, const void *, uint32_t *, comparison_fn_t, bool)
ndr_token_store: enum ndr_err_code (TALLOC_CTX *, struct ndr_token_list *, const void *, uint32_t)
ndr_transfer_syntax_ndr: uuid = {time_low = 2324192516, time_mid = 7403, time_hi_and_version = 4553, clock_seq = "\237\350", node = "\b\000+\020H`"}, if_version = 2
ndr_transfer_syntax_ndr64: uuid = {time_low = 1903232307, time_mid = 48826, time_hi_and_version = 18743, clock_seq = "\203\031", node = "\265\333\357\234\3146"}, if_version = 1

View File

@ -721,8 +721,11 @@ enum ndr_err_code ndr_token_store(TALLOC_CTX *mem_ctx,
struct ndr_token_list *list,
const void *key,
uint32_t value);
enum ndr_err_code ndr_token_retrieve_cmp_fn(struct ndr_token_list *list, const void *key, uint32_t *v,
int(*_cmp_fn)(const void*,const void*), bool erase);
enum ndr_err_code ndr_token_peek_cmp_fn(struct ndr_token_list *list,
const void *key,
uint32_t *v,
int (*_cmp_fn)(const void *,
const void *));
enum ndr_err_code ndr_token_retrieve(struct ndr_token_list *list, const void *key, uint32_t *v);
enum ndr_err_code ndr_token_peek(struct ndr_token_list *list, const void *key, uint32_t *v);
enum ndr_err_code ndr_pull_array_size(struct ndr_pull *ndr, const void *p);

View File

@ -1044,28 +1044,31 @@ _PUBLIC_ enum ndr_err_code ndr_token_store(TALLOC_CTX *mem_ctx,
/*
retrieve a token from a ndr context, using cmp_fn to match the tokens
*/
_PUBLIC_ enum ndr_err_code ndr_token_retrieve_cmp_fn(struct ndr_token_list *list,
const void *key, uint32_t *v,
comparison_fn_t _cmp_fn,
bool erase)
static enum ndr_err_code ndr_token_find(struct ndr_token_list *list,
const void *key,
uint32_t *v,
comparison_fn_t _cmp_fn,
unsigned *_i)
{
struct ndr_token *tokens = list->tokens;
unsigned i;
for (i = list->count - 1; i < list->count; i--) {
if (_cmp_fn(tokens[i].key, key) == 0) {
goto found;
*_i = i;
*v = tokens[i].value;
return NDR_ERR_SUCCESS;
}
}
return NDR_ERR_TOKEN;
found:
*v = tokens[i].value;
if (erase) {
if (i != list->count - 1) {
tokens[i] = tokens[list->count - 1];
}
list->count--;
}
return NDR_ERR_SUCCESS;
}
_PUBLIC_ enum ndr_err_code ndr_token_peek_cmp_fn(struct ndr_token_list *list,
const void *key,
uint32_t *v,
comparison_fn_t _cmp_fn)
{
unsigned i;
return ndr_token_find(list, key, v, _cmp_fn, &i);
}
static int token_cmp_ptr(const void *a, const void *b)
@ -1079,7 +1082,22 @@ static int token_cmp_ptr(const void *a, const void *b)
_PUBLIC_ enum ndr_err_code ndr_token_retrieve(struct ndr_token_list *list,
const void *key, uint32_t *v)
{
return ndr_token_retrieve_cmp_fn(list, key, v, token_cmp_ptr, true);
enum ndr_err_code err;
uint32_t last;
unsigned i;
err = ndr_token_find(list, key, v, token_cmp_ptr, &i);
if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
return err;
}
last = list->count - 1;
if (i != last) {
list->tokens[i] = list->tokens[last];
}
list->count--;
return NDR_ERR_SUCCESS;
}
/*
@ -1088,7 +1106,8 @@ _PUBLIC_ enum ndr_err_code ndr_token_retrieve(struct ndr_token_list *list,
_PUBLIC_ enum ndr_err_code ndr_token_peek(struct ndr_token_list *list,
const void *key, uint32_t *v)
{
return ndr_token_retrieve_cmp_fn(list, key, v, token_cmp_ptr, false);
unsigned i;
return ndr_token_find(list, key, v, token_cmp_ptr, &i);
}
/*

View File

@ -50,10 +50,11 @@ enum ndr_err_code ndr_push_dns_string_list(struct ndr_push *ndr,
/* see if we have pushed the remaining string already,
* if so we use a label pointer to this string
*/
ndr_err = ndr_token_retrieve_cmp_fn(string_list, s,
&offset,
(comparison_fn_t)strcmp,
false);
ndr_err = ndr_token_peek_cmp_fn(string_list,
s,
&offset,
(comparison_fn_t)
strcmp);
if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
uint8_t b[2];