netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: fasnacht@protonmail.ch
Subject: [PATCH nft 2/4] scanner: add indesc_file_alloc() helper function
Date: Tue, 11 Feb 2020 21:23:06 +0100	[thread overview]
Message-ID: <20200211202308.90575-3-pablo@netfilter.org> (raw)
In-Reply-To: <20200211202308.90575-1-pablo@netfilter.org>

New helper function to allocate the file input_descriptor.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/scanner.l | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/scanner.l b/src/scanner.l
index fe70df5c18ec..56f6e9956791 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -665,6 +665,22 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 
 %%
 
+static struct input_descriptor *
+indesc_file_alloc(FILE *f, const char *filename, const struct location *loc)
+{
+	struct input_descriptor *indesc;
+
+	indesc = xzalloc(sizeof(struct input_descriptor));
+	if (loc != NULL)
+		indesc->location = *loc;
+	indesc->type	= INDESC_FILE;
+	indesc->name	= xstrdup(filename);
+	indesc->f	= f;
+	init_pos(indesc);
+
+	return indesc;
+}
+
 static void scanner_push_indesc(struct parser_state *state,
 				struct input_descriptor *indesc)
 {
@@ -702,15 +718,7 @@ static void scanner_push_file(struct nft_ctx *nft, void *scanner,
 	b = yy_create_buffer(f, YY_BUF_SIZE, scanner);
 	yypush_buffer_state(b, scanner);
 
-	indesc = xzalloc(sizeof(struct input_descriptor));
-
-	if (loc != NULL)
-		indesc->location = *loc;
-	indesc->type	= INDESC_FILE;
-	indesc->name	= xstrdup(filename);
-	indesc->f	= f;
-	init_pos(indesc);
-
+	indesc = indesc_file_alloc(f, filename, loc);
 	scanner_push_indesc(state, indesc);
 }
 
-- 
2.11.0


  parent reply	other threads:[~2020-02-11 20:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 20:23 [PATCH nft 0/4] glob and maximum number of includes Pablo Neira Ayuso
2020-02-11 20:23 ` [PATCH nft 1/4] scanner: call scanner_push_file() after scanner_push_file() Pablo Neira Ayuso
2020-02-11 20:23 ` Pablo Neira Ayuso [this message]
2020-02-11 20:23 ` [PATCH nft 3/4] scanner: call scanner_push_indesc() " Pablo Neira Ayuso
2020-02-11 20:23 ` [PATCH nft 4/4] scanner: multi-level input file stack for glob Pablo Neira Ayuso
2020-02-12 20:44 ` [PATCH nft 0/4] glob and maximum number of includes Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200211202308.90575-3-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=fasnacht@protonmail.ch \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).