diff options
Diffstat (limited to 'demo4/main.c')
| -rw-r--r-- | demo4/main.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/demo4/main.c b/demo4/main.c index 2eb3e51..12d4aaf 100644 --- a/demo4/main.c +++ b/demo4/main.c @@ -53,6 +53,51 @@ void ip_plugin_ex_dup_cb(int table_id, void **to, void **from, long argl, void * *to = ud; } +struct wannat_compile +{ + int compile_id; + int service; + int action; + int do_blacklist; + int do_log; + char user_region[8192]; + int group_num; + int is_valid; +}; + +void wannat_compile_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; + char effective_range[20] = {0}; + char op_time[20] = {0}; + + struct wannat_compile *ud = ALLOC(struct wannat_compile, 1); + + int ret = sscanf(table_line, "%d\t%d\t%d\t%d\t%d\t%10s\t%8192s\t%d\t%d\t%20s", &(ud->compile_id), &(ud->service), + &(ud->action), &(ud->do_blacklist), &(ud->do_log), effective_range, ud->user_region, + &(ud->group_num), &(ud->is_valid), &op_time); + + *ad = ud; + (*counter)++; +} + +void wannat_compile_ex_free_cb(int table_id, void **ad, long argl, void *argp) +{ + struct wannat_compile *ud = (struct wannat_compile *)(*ad); + + memset(ud, 0, sizeof(struct wannat_compile)); + free(ud); + *ad = NULL; +} + +void wannat_compile_ex_dup_cb(int table_id, void **to, void **from, long argl, void *argp) +{ + struct wannat_compile *ud = (struct wannat_compile *)(*from); + + *to = ud; +} + int main() { /* initialize maat options which will be used by maat_new() */ @@ -87,6 +132,25 @@ int main() assert(ud != NULL); assert(ud->id == 1); + plugin_ex_data_counter = 0; + const char *table_name2 = "WANNAT_COMPILE"; + table_id = maat_get_table_id(maat_instance, table_name2); + assert(table_id == 3); /* defined in table_info.conf */ + + ret = maat_plugin_table_ex_schema_register(maat_instance, table_name2, wannat_compile_ex_new_cb, wannat_compile_ex_free_cb, + wannat_compile_ex_dup_cb, 0, &plugin_ex_data_counter); + assert(ret == 0); + assert(plugin_ex_data_counter == 2); + + struct wannat_compile *ud2 = NULL; + int key = 301; + ud2 = (struct wannat_compile *)maat_plugin_table_get_ex_data(maat_instance, table_id, (char *)&key, sizeof(int)); + + assert(ud2 != NULL); + assert(ud2->compile_id == 301); + assert(ud2->action == 1); + + // struct ip_addr ipv4; // ipv4.ip_type = IPv4; // ret = inet_pton(AF_INET, "192.168.30.100", &ipv4.ipv4); |
