From patchwork Wed Aug 16 20:43:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Leblond X-Patchwork-Id: 802252 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xXj7R1ybfz9t32 for ; Thu, 17 Aug 2017 07:25:39 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752727AbdHPVZi (ORCPT ); Wed, 16 Aug 2017 17:25:38 -0400 Received: from home.regit.org ([37.187.126.138]:40710 "EHLO home.regit.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752678AbdHPVZi (ORCPT ); Wed, 16 Aug 2017 17:25:38 -0400 Received: from [2a01:e34:ee97:b130:c685:8ff:feb3:c9c8] (helo=localhost.localdomain) by home.regit.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1di5BM-0006tM-6D; Wed, 16 Aug 2017 22:44:53 +0200 From: Eric Leblond To: pablo@netfilter.org Cc: netfilter-devel@vger.kernel.org, Eric Leblond Subject: [nft PATH 11/16] libnftables: add nft_context_set_print Date: Wed, 16 Aug 2017 22:43:05 +0200 Message-Id: <20170816204310.3371-12-eric@regit.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170816204310.3371-1-eric@regit.org> References: <20170816204310.3371-1-eric@regit.org> X-Spam-Score: -1.0 (-) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org This function allows user to set his own printing function. It is still dependant of the format used by nft but at least it can be redirected easily. Signed-off-by: Eric Leblond --- include/nftables/nftables.h | 3 +++ src/libnftables.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/include/nftables/nftables.h b/include/nftables/nftables.h index b902cbd..935d0db 100644 --- a/include/nftables/nftables.h +++ b/include/nftables/nftables.h @@ -26,6 +26,9 @@ void nft_global_deinit(void); struct nft_ctx *nft_context_new(void); void nft_context_free(struct nft_ctx *nft); +void nft_context_set_print_func(struct nft_ctx *nft, + int (*print)(void *ctx, const char *fmt, ...), + void *ctx); int nft_run_command_from_buffer(struct nft_ctx *nft, char *buf, size_t buflen); diff --git a/src/libnftables.c b/src/libnftables.c index 356e9c4..494ff57 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -86,6 +86,15 @@ struct nft_ctx *nft_context_new(void) return ctx; } +void nft_context_set_print_func(struct nft_ctx *nft, + int (*print)(void *ctx, const char *fmt, ...), + void *ctx) +{ + if (nft) { + nft->output.print = print; + nft->output.ctx = ctx; + } +} void nft_context_free(struct nft_ctx *nft) {