]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libndr: Streamline ndr_token_retrieve_cmp_fn
authorVolker Lendecke <vl@samba.org>
Wed, 28 Aug 2024 10:32:45 +0000 (12:32 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 29 Aug 2024 08:40:52 +0000 (08:40 +0000)
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

librpc/ABI/ndr-6.0.0.sigs
librpc/ndr/libndr.h
librpc/ndr/ndr.c
librpc/ndr/ndr_dns_utils.c

index cfc27b32a9a2132070c24e57a91c08f934a7557d..3244948abcc77e5c7c3e61840e711654668b9a5d 100644 (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
index aafdc1536ebdb0a77bce55a8a15f7a626a7da04a..223501ab781c5e6613b81ddb086e890e51061dfd 100644 (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);
index 75b6f67f3f377f7abbe5760ca208c5ab9e08d39d..16dc54463b81c883dbe38248216b88d076d51b0b 100644 (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);
 }
 
 /*
index a2e04640d52cd818418a7ae03333af3db46fb5aa..fe9e060306e4863ae241569c7a1c90021cd844c0 100644 (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];