]> granicus.if.org Git - ipset/blob - include/libipset/session.h
Fix parsing service names for ports
[ipset] / include / libipset / session.h
1 /* Copyright 2007-2010 Jozsef Kadlecsik (kadlec@blackhole.kfki.hu)
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation.
6  */
7 #ifndef LIBIPSET_SESSION_H
8 #define LIBIPSET_SESSION_H
9
10 #include <stdbool.h>                            /* bool */
11 #include <stdint.h>                             /* uintxx_t */
12 #include <stdio.h>                              /* printf */
13
14 #include <libipset/linux_ip_set.h>              /* enum ipset_cmd */
15
16 /* Report and output buffer sizes */
17 #define IPSET_ERRORBUFLEN               1024
18 #define IPSET_OUTBUFLEN                 8192
19
20 struct ipset_session;
21 struct ipset_data;
22 struct ipset_handle;
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 extern struct ipset_data *
29         ipset_session_data(const struct ipset_session *session);
30 extern struct ipset_handle *
31         ipset_session_handle(const struct ipset_session *session);
32 extern const struct ipset_type *
33         ipset_saved_type(const struct ipset_session *session);
34 extern void ipset_session_lineno(struct ipset_session *session,
35                                  uint32_t lineno);
36
37 enum ipset_err_type {
38         IPSET_ERROR,
39         IPSET_WARNING,
40 };
41
42 extern int ipset_session_report(struct ipset_session *session,
43                                 enum ipset_err_type type,
44                                 const char *fmt, ...);
45 extern int ipset_session_warning_as_error(struct ipset_session *session);
46
47 #define ipset_err(session, fmt, args...) \
48         ipset_session_report(session, IPSET_ERROR, fmt , ## args)
49
50 #define ipset_warn(session, fmt, args...) \
51         ipset_session_report(session, IPSET_WARNING, fmt , ## args)
52
53 #define ipset_errptr(session, fmt, args...) ({                          \
54         ipset_session_report(session, IPSET_ERROR, fmt , ## args);      \
55         NULL;                                                           \
56 })
57
58 extern void ipset_session_report_reset(struct ipset_session *session);
59 extern const char *ipset_session_error(const struct ipset_session *session);
60 extern const char *ipset_session_warning(const struct ipset_session *session);
61
62 #define ipset_session_data_set(session, opt, value)     \
63         ipset_data_set(ipset_session_data(session), opt, value)
64 #define ipset_session_data_get(session, opt)            \
65         ipset_data_get(ipset_session_data(session), opt)
66
67 /* Environment option flags */
68 enum ipset_envopt {
69         IPSET_ENV_BIT_SORTED    = 0,
70         IPSET_ENV_SORTED        = (1 << IPSET_ENV_BIT_SORTED),
71         IPSET_ENV_BIT_QUIET     = 1,
72         IPSET_ENV_QUIET         = (1 << IPSET_ENV_BIT_QUIET),
73         IPSET_ENV_BIT_RESOLVE   = 2,
74         IPSET_ENV_RESOLVE       = (1 << IPSET_ENV_BIT_RESOLVE),
75         IPSET_ENV_BIT_EXIST     = 3,
76         IPSET_ENV_EXIST         = (1 << IPSET_ENV_BIT_EXIST),
77         IPSET_ENV_BIT_LIST_SETNAME = 4,
78         IPSET_ENV_LIST_SETNAME  = (1 << IPSET_ENV_BIT_LIST_SETNAME),
79         IPSET_ENV_BIT_LIST_HEADER = 5,
80         IPSET_ENV_LIST_HEADER   = (1 << IPSET_ENV_BIT_LIST_HEADER),
81 };
82
83 extern int ipset_envopt_parse(struct ipset_session *session,
84                               int env, const char *str);
85 extern bool ipset_envopt_test(struct ipset_session *session,
86                               enum ipset_envopt env);
87
88 enum ipset_output_mode {
89         IPSET_LIST_NONE,
90         IPSET_LIST_PLAIN,
91         IPSET_LIST_SAVE,
92         IPSET_LIST_XML,
93 };
94
95 extern int ipset_session_output(struct ipset_session *session,
96                                 enum ipset_output_mode mode);
97
98 extern int ipset_commit(struct ipset_session *session);
99 extern int ipset_cmd(struct ipset_session *session, enum ipset_cmd cmd,
100                      uint32_t lineno);
101
102 typedef int (*ipset_outfn)(const char *fmt, ...)
103         __attribute__ ((format (printf, 1, 2)));
104
105 extern int ipset_session_outfn(struct ipset_session *session,
106                                ipset_outfn outfn);
107 extern struct ipset_session *ipset_session_init(ipset_outfn outfn);
108 extern int ipset_session_fini(struct ipset_session *session);
109
110 extern void ipset_debug_msg(const char *dir, void *buffer, int len);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif /* LIBIPSET_SESSION_H */