netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Netfilter Development Mailing list <netfilter-devel@vger.kernel.org>
Subject: Re: [libnftables PATCH 4/6] internal: add a selector for parsing ops
Date: Wed, 8 Jan 2014 13:31:44 +0100	[thread overview]
Message-ID: <CAOkSjBiOw10oK4stjz48yqF63+Y_8-hOoH-uUh4FqO2e7P2DVA@mail.gmail.com> (raw)
In-Reply-To: <20140107232919.GD16894@localhost>

On 8 January 2014 00:29, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
>
> You should pass a callback function instead, eg.
>
> static int nft_chain_json_parse(struct nft_chain *c, const char *json,
>                                 struct nft_parse_err *err,
>                                 json_t *(*jsonbuilder)(const void *input_data,
>                                                        const char *treename,
>                                                        struct nft_parse_err *e))

Ok.

> But I don't understand yet what you save (in terms of lines of code)
> by using this aproach.

I avoid doing something like:

nft_*_parse() {
switch (type)
 if XML return xml_parse()
 if JSON return json_parse()
}

nft_*_parse_file() {
switch (type)
 if XML return xml_parse_file()
 if JSON return json_parse_file()
}

We double the format switch, and also two functions per format are
needed to do build and parsing.
Total = 6 functions heavily duplicating code.

With my approach, we have 1 function that decides which format to
parse, and a one function per format to build and do parsing.
Total = 3 functions, no duplicate code.
-- 
Arturo Borrero González
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2014-01-08 12:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-07 11:47 [libnftables PATCH 0/6] parsing update Arturo Borrero Gonzalez
2014-01-07 11:47 ` [libnftables PATCH 1/6] mxml: add error reference of the top node Arturo Borrero Gonzalez
2014-01-07 23:16   ` Pablo Neira Ayuso
2014-01-07 11:47 ` [libnftables PATCH 2/6] set_elem: add json parsing to API Arturo Borrero Gonzalez
2014-01-07 23:16   ` Pablo Neira Ayuso
2014-01-07 11:47 ` [libnftables PATCH 3/6] internal: rework parsing symbol logic Arturo Borrero Gonzalez
2014-01-07 23:18   ` Pablo Neira Ayuso
2014-01-08 12:20     ` Arturo Borrero Gonzalez
2014-01-08 12:25       ` Pablo Neira Ayuso
2014-01-07 11:47 ` [libnftables PATCH 4/6] internal: add a selector for parsing ops Arturo Borrero Gonzalez
2014-01-07 23:29   ` Pablo Neira Ayuso
2014-01-08 12:31     ` Arturo Borrero Gonzalez [this message]
2014-01-08 13:36       ` Pablo Neira Ayuso
2014-01-07 11:47 ` [libnftables PATCH 5/6] parsing: add interface to parse from file Arturo Borrero Gonzalez
2014-01-07 11:47 ` [libnftables PATCH 6/6] tests: update tests with nft_*_parse_file() Arturo Borrero Gonzalez
2014-01-07 23:32   ` Pablo Neira Ayuso
2014-01-08 12:21     ` Arturo Borrero Gonzalez

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=CAOkSjBiOw10oK4stjz48yqF63+Y_8-hOoH-uUh4FqO2e7P2DVA@mail.gmail.com \
    --to=arturo.borrero.glez@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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).