diff options
Diffstat (limited to 'demo3/main.c')
| -rw-r--r-- | demo3/main.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/demo3/main.c b/demo3/main.c new file mode 100644 index 0000000..320b1de --- /dev/null +++ b/demo3/main.c @@ -0,0 +1,83 @@ +#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/demo3/maat_json.json"; +const char *table_info_path = "/root/Git/demo/demo3/table_info.conf"; + +const char *json_filename_cb = "/root/Git/demo/demo3/maat_json_cb.json"; +const char *table_info_path_cb = "/root/Git/demo/demo3/table_info_cb.conf"; + +int main_1() +{ + /* 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, "/root/Git/demo/demo3/sample_test.log", LOG_LEVEL_TRACE); + + /* 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 = "UE_ID"; // ่ๆ่กจ 5 + int table_id = maat_get_table_id(maat_instance, table_name); + assert(table_id == 4); /* defined in table_info.conf */ + + int thread_id = 0; + long long results[ARRAY_SIZE] = {0}; + size_t n_hit_result = 0; + int ret = 0; + + /* store scanning intermediate state */ + struct maat_state *state = maat_state_new(maat_instance, thread_id); + assert(state != NULL); + + const char *ue_id = "abcdefghij"; + + ret = maat_scan_string(maat_instance, 4, ue_id, strlen(ue_id), results, ARRAY_SIZE, &n_hit_result, state); + // assert(ret == MAAT_SCAN_HIT); + // assert(n_hit_result == 1); + // assert(results[0] == 123); + + maat_state_free(state); + + // struct ip_addr ipv4; + // ipv4.ip_type = 4; + // ret = inet_pton(AF_INET, "20.20.20.20", &ipv4.ipv4); + + // struct maat_state *state2 = maat_state_new(maat_instance, thread_id); + // assert(state2 != NULL); + + // uint32_t a = ipv4.ipv4; + // ret = maat_scan_ipv4(maat_instance, 6, a, results, ARRAY_SIZE, &n_hit_result, state2); + + // printf("ret: %d\n", ret); + // maat_state_free(state2); + + return 0; +} + +// int main2() +// { +// /* 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_cb); +// maat_options_set_logger(opts, "/root/Git/demo/matt/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_cb); +// assert(maat_instance != NULL); +// maat_options_free(opts); +// } + +int main() +{ + main_1(); + // main2(); +}
\ No newline at end of file |
