diff options
Diffstat (limited to 'include/libipset/session.h')
-rw-r--r-- | include/libipset/session.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/include/libipset/session.h b/include/libipset/session.h new file mode 100644 index 0000000..71b8e02 --- /dev/null +++ b/include/libipset/session.h @@ -0,0 +1,81 @@ +/* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#ifndef LIBIPSET_SESSION_H +#define LIBIPSET_SESSION_H + +#include <stdbool.h> /* bool */ +#include <stdint.h> /* uintxx_t */ +#include <stdio.h> /* printf */ + +#include <libipset/linux_ip_set.h> /* enum ipset_cmd */ +#include <libipset/ui.h> /* enum ipset_envopt */ + +/* Report and output buffer sizes */ +#define IPSET_ERRORBUFLEN 1024 +#define IPSET_OUTBUFLEN 8192 + +struct ipset_session; +struct ipset_data; +struct ipset_handle; + +extern struct ipset_data * ipset_session_data(const struct ipset_session *session); +extern struct ipset_handle * ipset_session_handle(const struct ipset_session *session); + +enum ipset_err_type { + IPSET_ERROR, + IPSET_WARNING, +}; + +extern int ipset_session_report(struct ipset_session *session, + enum ipset_err_type type, + const char *fmt, ...); + +#define ipset_err(session, fmt, args...) \ + ipset_session_report(session, IPSET_ERROR, fmt , ## args) + +#define ipset_warn(session, fmt, args...) \ + ipset_session_report(session, IPSET_WARNING, fmt , ## args) + +#define ipset_errptr(session, fmt, args...) ({ \ + ipset_session_report(session, IPSET_ERROR, fmt , ## args); \ + NULL; \ +}) + +extern void ipset_session_report_reset(struct ipset_session *session); +extern const char * ipset_session_error(const struct ipset_session *session); +extern const char * ipset_session_warning(const struct ipset_session *session); + +#define ipset_session_data_set(session, opt, value) \ + ipset_data_set(ipset_session_data(session), opt, value) +#define ipset_session_data_get(session, opt) \ + ipset_data_get(ipset_session_data(session), opt) + +enum ipset_output_mode { + IPSET_LIST_NONE, + IPSET_LIST_PLAIN, + IPSET_LIST_SAVE, + IPSET_LIST_XML, +}; + +extern int ipset_envopt_parse(struct ipset_session *session, + int env, const char *str); +extern bool ipset_envopt_test(struct ipset_session *session, + enum ipset_envopt env); +extern int ipset_session_output(struct ipset_session *session, + enum ipset_output_mode mode); + +extern int ipset_commit(struct ipset_session *session); +extern int ipset_cmd(struct ipset_session *session, enum ipset_cmd cmd, + uint32_t lineno); + +typedef int (*ipset_outfn)(const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); + +extern struct ipset_session * ipset_session_init(ipset_outfn outfn); +extern int ipset_session_fini(struct ipset_session *session); + +#endif /* LIBIPSET_SESSION_H */ |