From: Stefan Schantl Date: Thu, 1 Sep 2022 17:33:43 +0000 (+0200) Subject: Add private call_list_cmd function. X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=95944a1b943a4ac58ce28cdbb759cd57b6722c6a;p=people%2Fstevee%2Fperl-ipset.git Add private call_list_cmd function. This function uses the print_outfm_to_string function to capute the output and return it as string. Signed-off-by: Stefan Schantl --- diff --git a/IPSet.xs b/IPSet.xs index 507f94a..d44e8f6 100644 --- a/IPSet.xs +++ b/IPSet.xs @@ -43,6 +43,55 @@ ERROR: return r; } +char* call_list_cmd(struct ipset_session *session, + enum ipset_envopt envopt, + const char *setname, ...) +{ + + enum ipset_cmd cmd = IPSET_CMD_LIST; + int r; + + char* p = NULL; + char* sets = NULL; + + // Check if an environment option has been passed. + if(envopt) { + // Set the environemt option. + ipset_envopt_set(session, envopt); + } + + // Check if a setname has been given. + if(setname) { + r = ipset_session_data_set(session, IPSET_SETNAME, setname); + if (r < 0 ) { + goto ERROR; + } + } + + // Use print_outfm_to_string function to put the output into a string which + // can be processed further. + ipset_session_print_outfn(session, print_outfm_to_string, &sets); + + r = ipset_cmd(session, cmd, 0); + if (r < 0) { + goto ERROR; + } + + goto END; + + ERROR: + // Reset session data. + ipset_data_reset(ipset_session_data(session)); + END: + // Remove environment option. + ipset_envopt_unset(session, envopt); + + // Reset outfn to defaul. + ipset_session_print_outfn(session, NULL, NULL); + + return sets; +} + MODULE = IPSet PACKAGE = IPSet struct ipset_session *