diff mbox series

[1/2] libsepol/cil: Add function to determine if a subtree has a declaration

Message ID 20210624195815.148698-1-jwcart2@gmail.com (mailing list archive)
State Accepted
Headers show
Series [1/2] libsepol/cil: Add function to determine if a subtree has a declaration | expand

Commit Message

James Carter June 24, 2021, 7:58 p.m. UTC
Create the function cil_tree_subtree_has_decl() that returns CIL_TRUE
if the subtree has a declaration in it and CIL_FALSE otherwise.

Signed-off-by: James Carter <jwcart2@gmail.com>
---
 libsepol/cil/src/cil_tree.c | 16 ++++++++++++++++
 libsepol/cil/src/cil_tree.h |  2 ++
 2 files changed, 18 insertions(+)

Comments

Nicolas Iooss June 26, 2021, 12:33 p.m. UTC | #1
On Thu, Jun 24, 2021 at 9:58 PM James Carter <jwcart2@gmail.com> wrote:
>
> Create the function cil_tree_subtree_has_decl() that returns CIL_TRUE
> if the subtree has a declaration in it and CIL_FALSE otherwise.
>
> Signed-off-by: James Carter <jwcart2@gmail.com>

For these 2 patches:

Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>

Thanks!

> ---
>  libsepol/cil/src/cil_tree.c | 16 ++++++++++++++++
>  libsepol/cil/src/cil_tree.h |  2 ++
>  2 files changed, 18 insertions(+)
>
> diff --git a/libsepol/cil/src/cil_tree.c b/libsepol/cil/src/cil_tree.c
> index 067268eb..4cf8dcc8 100644
> --- a/libsepol/cil/src/cil_tree.c
> +++ b/libsepol/cil/src/cil_tree.c
> @@ -136,6 +136,22 @@ __attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *n
>         cil_log(lvl,"\n");
>  }
>
> +int cil_tree_subtree_has_decl(struct cil_tree_node *node)
> +{
> +       while (node) {
> +               if (node->flavor >= CIL_MIN_DECLARATIVE) {
> +                       return CIL_TRUE;
> +               }
> +               if (node->cl_head != NULL) {
> +                       if (cil_tree_subtree_has_decl(node->cl_head))
> +                               return CIL_TRUE;
> +               }
> +               node = node->next;
> +       }
> +
> +       return CIL_FALSE;
> +}
> +
>  int cil_tree_init(struct cil_tree **tree)
>  {
>         struct cil_tree *new_tree = cil_malloc(sizeof(*new_tree));
> diff --git a/libsepol/cil/src/cil_tree.h b/libsepol/cil/src/cil_tree.h
> index bac9f1e4..f4d22071 100644
> --- a/libsepol/cil/src/cil_tree.h
> +++ b/libsepol/cil/src/cil_tree.h
> @@ -54,6 +54,8 @@ struct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **
>  char *cil_tree_get_cil_path(struct cil_tree_node *node);
>  __attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...);
>
> +int cil_tree_subtree_has_decl(struct cil_tree_node *node);
> +
>  int cil_tree_init(struct cil_tree **tree);
>  void cil_tree_destroy(struct cil_tree **tree);
>  void cil_tree_subtree_destroy(struct cil_tree_node *node);
> --
> 2.26.3
>
Nicolas Iooss June 30, 2021, 7:45 p.m. UTC | #2
On Sat, Jun 26, 2021 at 2:33 PM Nicolas Iooss <nicolas.iooss@m4x.org> wrote:
>
> On Thu, Jun 24, 2021 at 9:58 PM James Carter <jwcart2@gmail.com> wrote:
> >
> > Create the function cil_tree_subtree_has_decl() that returns CIL_TRUE
> > if the subtree has a declaration in it and CIL_FALSE otherwise.
> >
> > Signed-off-by: James Carter <jwcart2@gmail.com>
>
> For these 2 patches:
>
> Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>

I applied them.

Thanks!
Nicolas

> > ---
> >  libsepol/cil/src/cil_tree.c | 16 ++++++++++++++++
> >  libsepol/cil/src/cil_tree.h |  2 ++
> >  2 files changed, 18 insertions(+)
> >
> > diff --git a/libsepol/cil/src/cil_tree.c b/libsepol/cil/src/cil_tree.c
> > index 067268eb..4cf8dcc8 100644
> > --- a/libsepol/cil/src/cil_tree.c
> > +++ b/libsepol/cil/src/cil_tree.c
> > @@ -136,6 +136,22 @@ __attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *n
> >         cil_log(lvl,"\n");
> >  }
> >
> > +int cil_tree_subtree_has_decl(struct cil_tree_node *node)
> > +{
> > +       while (node) {
> > +               if (node->flavor >= CIL_MIN_DECLARATIVE) {
> > +                       return CIL_TRUE;
> > +               }
> > +               if (node->cl_head != NULL) {
> > +                       if (cil_tree_subtree_has_decl(node->cl_head))
> > +                               return CIL_TRUE;
> > +               }
> > +               node = node->next;
> > +       }
> > +
> > +       return CIL_FALSE;
> > +}
> > +
> >  int cil_tree_init(struct cil_tree **tree)
> >  {
> >         struct cil_tree *new_tree = cil_malloc(sizeof(*new_tree));
> > diff --git a/libsepol/cil/src/cil_tree.h b/libsepol/cil/src/cil_tree.h
> > index bac9f1e4..f4d22071 100644
> > --- a/libsepol/cil/src/cil_tree.h
> > +++ b/libsepol/cil/src/cil_tree.h
> > @@ -54,6 +54,8 @@ struct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **
> >  char *cil_tree_get_cil_path(struct cil_tree_node *node);
> >  __attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...);
> >
> > +int cil_tree_subtree_has_decl(struct cil_tree_node *node);
> > +
> >  int cil_tree_init(struct cil_tree **tree);
> >  void cil_tree_destroy(struct cil_tree **tree);
> >  void cil_tree_subtree_destroy(struct cil_tree_node *node);
> > --
> > 2.26.3
> >
diff mbox series

Patch

diff --git a/libsepol/cil/src/cil_tree.c b/libsepol/cil/src/cil_tree.c
index 067268eb..4cf8dcc8 100644
--- a/libsepol/cil/src/cil_tree.c
+++ b/libsepol/cil/src/cil_tree.c
@@ -136,6 +136,22 @@  __attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *n
 	cil_log(lvl,"\n");
 }
 
+int cil_tree_subtree_has_decl(struct cil_tree_node *node)
+{
+	while (node) {
+		if (node->flavor >= CIL_MIN_DECLARATIVE) {
+			return CIL_TRUE;
+		}
+		if (node->cl_head != NULL) {
+			if (cil_tree_subtree_has_decl(node->cl_head))
+				return CIL_TRUE;
+		}
+		node = node->next;
+	}
+
+	return CIL_FALSE;
+}
+
 int cil_tree_init(struct cil_tree **tree)
 {
 	struct cil_tree *new_tree = cil_malloc(sizeof(*new_tree));
diff --git a/libsepol/cil/src/cil_tree.h b/libsepol/cil/src/cil_tree.h
index bac9f1e4..f4d22071 100644
--- a/libsepol/cil/src/cil_tree.h
+++ b/libsepol/cil/src/cil_tree.h
@@ -54,6 +54,8 @@  struct cil_tree_node *cil_tree_get_next_path(struct cil_tree_node *node, char **
 char *cil_tree_get_cil_path(struct cil_tree_node *node);
 __attribute__((format (printf, 3, 4))) void cil_tree_log(struct cil_tree_node *node, enum cil_log_level lvl, const char* msg, ...);
 
+int cil_tree_subtree_has_decl(struct cil_tree_node *node);
+
 int cil_tree_init(struct cil_tree **tree);
 void cil_tree_destroy(struct cil_tree **tree);
 void cil_tree_subtree_destroy(struct cil_tree_node *node);