]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
use dlists for filenames
authorAlan T. DeKok <aland@freeradius.org>
Fri, 2 Dec 2022 21:54:10 +0000 (16:54 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 2 Dec 2022 21:54:10 +0000 (16:54 -0500)
that way they get processed in the order that they appear in
on the command line, and not in some random order by sorting
the filename.

This isn't stricyly needed here, but will be needed for receiving
CoA packets.

src/bin/radclient.c
src/bin/radclient.h

index 7fb11f6c8dc23dafc86fee1c51b14e81e2ccc617..382d9a529c2d8af508b35e8f4970e66aa3c828c2 100644 (file)
@@ -819,22 +819,6 @@ static int radclient_sane(rc_request_t *request)
 }
 
 
-/*
- *     For request handling.
- */
-static int8_t filename_cmp(void const *one, void const *two)
-{
-       rc_file_pair_t const *a = one, *b = two;
-       int ret;
-
-       ret = strcmp(a->packets, b->packets);
-       ret = CMP(ret, 0);
-       if (ret != 0) return ret;
-
-       ret = strcmp(a->filters, b->filters);
-       return CMP(ret, 0);
-}
-
 static int8_t request_cmp(void const *one, void const *two)
 {
        rc_request_t const *a = one, *b = two;
@@ -1379,7 +1363,7 @@ int main(int argc, char **argv)
 #ifndef NDEBUG
        TALLOC_CTX      *autofree;
 #endif
-       fr_rb_tree_t    *filename_tree = NULL;
+       fr_dlist_head_t filenames;
        rc_request_t    *request;
 
        /*
@@ -1408,12 +1392,7 @@ int main(int argc, char **argv)
 
        fr_dlist_talloc_init(&rc_request_list, rc_request_t, entry);
 
-       filename_tree = fr_rb_inline_talloc_alloc(NULL, rc_file_pair_t, node, filename_cmp, NULL);
-       if (!filename_tree) {
-       oom:
-               ERROR("Out of memory");
-               fr_exit_now(EXIT_FAILURE);
-       }
+       fr_dlist_talloc_init(&filenames, rc_file_pair_t, entry);
 
        /*
         *      Always log to stdout
@@ -1472,7 +1451,11 @@ int main(int argc, char **argv)
                        rc_file_pair_t *files;
 
                        files = talloc(talloc_autofree_context(), rc_file_pair_t);
-                       if (!files) goto oom;
+                       if (!files) {
+                       oom:
+                               ERROR("Out of memory");
+                               fr_exit_now(EXIT_FAILURE);
+                       }
 
                        p = strchr(optarg, ':');
                        if (p) {
@@ -1483,7 +1466,7 @@ int main(int argc, char **argv)
                                files->packets = optarg;
                                files->filters = NULL;
                        }
-                       fr_rb_insert(filename_tree, (void *) files);
+                       fr_dlist_insert_tail(&filenames, files);
                }
                        break;
 
@@ -1667,7 +1650,7 @@ int main(int argc, char **argv)
        /*
         *      If no '-f' is specified, we're reading from stdin.
         */
-       if (fr_rb_num_elements(filename_tree) == 0) {
+       if (fr_dlist_num_elements(&filenames) == 0) {
                rc_file_pair_t *files;
 
                files = talloc_zero(talloc_autofree_context(), rc_file_pair_t);
@@ -1678,17 +1661,10 @@ int main(int argc, char **argv)
        /*
         *      Walk over the list of filenames, creating the requests.
         */
-       {
-               fr_rb_iter_inorder_t    iter;
-               rc_file_pair_t                  *files;
-
-               for (files = fr_rb_iter_init_inorder(&iter, filename_tree);
-                    files;
-                    files = fr_rb_iter_next_inorder(&iter)) {
-                       if (radclient_init(files, files)) {
-                               ERROR("Failed parsing input files");
-                               fr_exit_now(1);
-                       }
+       fr_dlist_foreach(&filenames, rc_file_pair_t, files) {
+               if (radclient_init(files, files)) {
+                       ERROR("Failed parsing input files");
+                       fr_exit_now(1);
                }
        }
 
@@ -1931,8 +1907,6 @@ int main(int argc, char **argv)
                }
        } while (!done);
 
-       talloc_free(filename_tree);
-
        fr_packet_list_free(packet_list);
 
        fr_dlist_talloc_free(&rc_request_list);
index b1fe98175501dafd6940d367e1b639fdbbc9e522..042da94cc4415f3d3eb66bdadc5a9f9a028b2113 100644 (file)
@@ -57,7 +57,7 @@ typedef struct {
 } rc_stats_t;
 
 typedef struct {
-       fr_rb_node_t            node;           //!< rbtree node data.
+       fr_dlist_t              entry;          //!< for linked list
        char const              *packets;       //!< The file containing the request packet
        char const              *filters;       //!< The file containing the definition of the
                                                //!< packet we want to match.