summaryrefslogtreecommitdiff
path: root/demo4/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'demo4/main.c')
-rw-r--r--demo4/main.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/demo4/main.c b/demo4/main.c
new file mode 100644
index 0000000..d6fd1d4
--- /dev/null
+++ b/demo4/main.c
@@ -0,0 +1,113 @@
+#include "maat.h"
+#include "stdio.h"
+#include <arpa/inet.h>
+#include <assert.h>
+#include <stddef.h>
+#include <string.h>
+
+#define ARRAY_SIZE 16
+
+const char *json_filename = "/root/Git/demo/demo4/maat_json_cb.json";
+const char *table_info_path = "/root/Git/demo/demo4/table_info_cb.conf";
+
+// struct ip_plugin_ud {
+// long long rule_id;
+// char *buffer;
+// size_t buf_len;
+// };
+// void ip_plugin_ex_new_cb(const char *table_name, int table_id, const char *key,
+// const char *table_line, void **ad, long argl, void *argp)
+// {
+// int *counter = (int *)argp;
+// size_t column_offset=0, column_len=0;
+// struct ip_plugin_ud *ud = ALLOC(struct ip_plugin_ud, 1);
+
+// int ret = get_column_pos(table_line, 1, &column_offset, &column_len);
+// EXPECT_EQ(ret, 0);
+
+// ud->rule_id = atoll(table_line + column_offset);
+
+// ret = get_column_pos(table_line, 5, &column_offset, &column_len);
+// EXPECT_EQ(ret, 0);
+
+// ud->buffer = ALLOC(char, column_len + 1);
+// strncpy(ud->buffer, table_line + column_offset, column_len);
+
+// ud->buf_len = column_len + 1;
+// *ad = ud;
+// (*counter)++;
+// }
+
+// void ip_plugin_ex_free_cb(int table_id, void **ad, long argl, void *argp)
+// {
+// struct ip_plugin_ud *ud = (struct ip_plugin_ud *)(*ad);
+
+// ud->rule_id = 0;
+// memset(ud->buffer, 0, ud->buf_len);
+// ud->buf_len = 0;
+
+// free(ud->buffer);
+// free(ud);
+// *ad = NULL;
+// }
+
+// void ip_plugin_ex_dup_cb(int table_id, void **to, void **from, long argl, void *argp)
+// {
+// struct ip_plugin_ud *ud = (struct ip_plugin_ud *)(*from);
+
+// *to = ud;
+// }
+
+int main()
+{
+ /* initialize maat options which will be used by maat_new() */
+ struct maat_options *opts = maat_options_new();
+ maat_options_set_json_file(opts, json_filename);
+ maat_options_set_logger(opts, "./sample_test.log", LOG_LEVEL_INFO);
+
+ /* create maat instance, rules in table_info.conf will be loaded. */
+ struct maat *maat_instance = maat_new(opts, table_info_path);
+ assert(maat_instance != NULL);
+ maat_options_free(opts);
+
+ const char *table_name = "WANNAT_DYN_UE_ID_IP"; /* maat_json.json has TEST_IP_PLUGIN_WITH_EXDATA rule */
+ int table_id = maat_get_table_id(maat_instance, table_name);
+ assert(table_id == 0); /* defined in table_info.conf */
+
+ // int ret = maat_plugin_table_ex_schema_register(maat_inst, table_name,
+ // ip_plugin_ex_new_cb,
+ // ip_plugin_ex_free_cb,
+ // ip_plugin_ex_dup_cb,
+ // 0, &ip_plugin_ex_data_counter);
+ // EXPECT_EQ(ret, 0);
+ // EXPECT_EQ(ip_plugin_ex_data_counter, 4);
+
+ // struct ip_addr ipv4;
+ // ipv4.ip_type = IPv4;
+ // ret = inet_pton(AF_INET, "192.168.30.100", &ipv4.ipv4);
+ // EXPECT_EQ(ret, 1);
+
+ // /* get ex_data */
+ // struct ip_plugin_ud *results[ARRAY_SIZE];
+ // ret = maat_ip_plugin_table_get_ex_data(maat_inst, table_id, &ipv4,
+ // (void **)results, ARRAY_SIZE);
+ // EXPECT_EQ(ret, 2);
+ // EXPECT_EQ(results[0]->rule_id, 101);
+ // EXPECT_EQ(results[1]->rule_id, 102);
+
+ // struct ip_addr ipv6;
+ // ipv6.ip_type = IPv6;
+ // inet_pton(AF_INET6, "2001:db8:1234::5210", &(ipv6.ipv6));
+ // memset(results, 0, sizeof(results));
+
+ // ret = maat_ip_plugin_table_get_ex_data(maat_inst, table_id, &ipv6,
+ // (void**)results, ARRAY_SIZE);
+ // EXPECT_EQ(ret, 2);
+ // EXPECT_EQ(results[0]->rule_id, 104);
+ // EXPECT_EQ(results[1]->rule_id, 103);
+
+ // maat_state_free(state);
+
+ return 0;
+}
+