From 2535ba7006f22a6470f4c88ea7d30c343a1d8799 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 28 Sep 2017 17:17:45 +0200 Subject: src: get rid of printf This patch introduces nft_print()/nft_gmp_print() functions which have to be used instead of printf to output information that were previously send to stdout. These functions print to a FILE pointer defined in struct output_ctx. It is set by calling: | old_fp = nft_ctx_set_output(ctx, new_fp); Having an application-defined FILE pointer is actually quite flexible: Using fmemopen() or even fopencookie(), an application gains full control over what is printed and where it should go to. Signed-off-by: Eric Leblond Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/ct.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/ct.c') diff --git a/src/ct.c b/src/ct.c index 0e9b17cd..b2faf627 100644 --- a/src/ct.c +++ b/src/ct.c @@ -141,11 +141,11 @@ static void ct_label_type_print(const struct expr *expr, for (s = ct_label_tbl->symbols; s->identifier != NULL; s++) { if (bit != s->value) continue; - printf("\"%s\"", s->identifier); + nft_print(octx, "\"%s\"", s->identifier); return; } /* can happen when connlabel.conf is altered after rules were added */ - printf("%ld\n", (long)mpz_scan1(expr->value, 0)); + nft_print(octx, "%ld\n", (long)mpz_scan1(expr->value, 0)); } static struct error_record *ct_label_type_parse(const struct expr *sym, @@ -269,27 +269,27 @@ static const struct ct_template ct_templates[] = { BYTEORDER_HOST_ENDIAN, 32), }; -static void ct_print(enum nft_ct_keys key, int8_t dir) +static void ct_print(enum nft_ct_keys key, int8_t dir, struct output_ctx *octx) { const struct symbolic_constant *s; - printf("ct "); + nft_print(octx, "ct "); if (dir < 0) goto done; for (s = ct_dir_tbl.symbols; s->identifier != NULL; s++) { if (dir == (int)s->value) { - printf("%s ", s->identifier); + nft_print(octx, "%s ", s->identifier); break; } } done: - printf("%s", ct_templates[key].token); + nft_print(octx, "%s", ct_templates[key].token); } static void ct_expr_print(const struct expr *expr, struct output_ctx *octx) { - ct_print(expr->ct.key, expr->ct.direction); + ct_print(expr->ct.key, expr->ct.direction, octx); } static bool ct_expr_cmp(const struct expr *e1, const struct expr *e2) @@ -385,8 +385,8 @@ void ct_expr_update_type(struct proto_ctx *ctx, struct expr *expr) static void ct_stmt_print(const struct stmt *stmt, struct output_ctx *octx) { - ct_print(stmt->ct.key, stmt->ct.direction); - printf(" set "); + ct_print(stmt->ct.key, stmt->ct.direction, octx); + nft_print(octx, " set "); expr_print(stmt->ct.expr, octx); } @@ -412,7 +412,7 @@ struct stmt *ct_stmt_alloc(const struct location *loc, enum nft_ct_keys key, static void notrack_stmt_print(const struct stmt *stmt, struct output_ctx *octx) { - printf("notrack"); + nft_print(octx, "notrack"); } static const struct stmt_ops notrack_stmt_ops = { -- cgit v1.2.3