From: Kevin Day Date: Fri, 16 Feb 2024 05:56:20 +0000 (-0600) Subject: Progress: Continue refactoring firewall from 0.6.x to 0.7.x/0.8.x. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=1738f4b85ca67e5ec37dfe846828f9a38b66f042;p=fll Progress: Continue refactoring firewall from 0.6.x to 0.7.x/0.8.x. This gets the programming compiling. There still remains some code to change. The runtime needs to be tested. I expect that there are things wrong given how much I jumped around while migrating this. --- diff --git a/level_3/firewall/c/main/common.c b/level_3/firewall/c/main/common.c index 4d28f17..00e3fe4 100644 --- a/level_3/firewall/c/main/common.c +++ b/level_3/firewall/c/main/common.c @@ -83,6 +83,7 @@ extern "C" { } f_number_unsigned_t at = 0; + f_number_unsigned_t index = 0; if (main->program.parameters.array[firewall_parameter_operation_start_e].result & f_console_result_found_e) { main->setting.flag &= ~firewall_main_flag_operation_lock_e; @@ -153,24 +154,26 @@ extern "C" { } if (main->setting.flag & firewall_main_flag_operation_show_e) { - if (main->parameters.remaining.used) { + if (main->program.parameters.remaining.used) { main->setting.flag &= ~firewall_main_flag_operation_show_filter_nat_mangle_e; - for (at = 0; at < main->parameters.remaining.used; ++at) { + for (at = 0; at < main->program.parameters.remaining.used; ++at) { if (firewall_signal_check(main)) return; - if (f_compare_dynamic(firewall_show_nat_s, data.argv[main->program.parameters.remaining.array[at]]) == F_equal_to) { + index = main->program.parameters.remaining.array[at]; + + if (f_compare_dynamic(firewall_show_nat_s, main->program.parameters.arguments.array[index]) == F_equal_to) { main->setting.flag |= firewall_main_flag_operation_show_nat_e; } - else if (f_compare_dynamic(firewall_show_mangle_s, data.argv[main->program.parameters.remaining.array[at]]) == F_equal_to) { + else if (f_compare_dynamic(firewall_show_mangle_s, main->program.parameters.arguments.array[index]) == F_equal_to) { main->setting.flag |= firewall_main_flag_operation_show_mangle_e; } - else if (f_compare_dynamic(firewall_show_fillter_s, data.argv[main->program.parameters.remaining.array[at]]) == F_equal_to) { + else if (f_compare_dynamic(firewall_show_filter_s, main->program.parameters.arguments.array[index]) == F_equal_to) { main->setting.flag |= firewall_main_flag_operation_show_filter_e; } else { - firewall_print_warning_show_option_unknown(&main->warning, data.argv[main->program.parameters.remaining.array[at]]); + firewall_print_warning_show_option_unknown(&main->program.warning, main->program.parameters.arguments.array[index]); } } // for } @@ -178,6 +181,24 @@ extern "C" { main->setting.flag |= firewall_main_flag_operation_show_filter_nat_mangle_e; } } + else { + // @todo + + // Example: + /* + for (f_number_unsigned_t number = 0; index < main->program.parameters.remaining.used; ++index) { + + if (control_signal_check(main)) return; + + number = main->program.parameters.remaining.array[index]; + + // Statically allocate the inner strings. + main->setting.actions.array[main->setting.actions.used].string = main->program.parameters.arguments.array[number].string; + main->setting.actions.array[main->setting.actions.used].used = main->program.parameters.arguments.array[number].used; + main->setting.actions.array[main->setting.actions.used++].size = 0; + } // for + */ + } } #endif // _di_firewall_setting_load_ diff --git a/level_3/firewall/c/main/common/enumeration.h b/level_3/firewall/c/main/common/enumeration.h index 986d30c..fbcf193 100644 --- a/level_3/firewall/c/main/common/enumeration.h +++ b/level_3/firewall/c/main/common/enumeration.h @@ -91,6 +91,7 @@ extern "C" { * * firewall_chain_*_e: * - none: The chain is none. + * - custom: The chain is custom. * - forward: The chain is forward. * - input: The chain is input. * - output: The chain is output. @@ -100,6 +101,7 @@ extern "C" { #ifndef _di_firewall_action_e_ enum { firewall_chain_none_e, + firewall_chain_custom_e, firewall_chain_forward_e, firewall_chain_input_e, firewall_chain_output_e, @@ -189,22 +191,22 @@ extern "C" { */ #ifndef _di_firewall_parameter_e_ enum { - fake_parameter_operation_lock_e = f_console_standard_parameter_last_e, - fake_parameter_operation_restart_e, - fake_parameter_operation_show_e, - fake_parameter_operation_start_e, - fake_parameter_operation_stop_e, + firewall_parameter_operation_lock_e = f_console_standard_parameter_last_e, + firewall_parameter_operation_restart_e, + firewall_parameter_operation_show_e, + firewall_parameter_operation_start_e, + firewall_parameter_operation_stop_e, }; // enum #define firewall_console_parameter_t_initialize \ { \ macro_fll_program_console_parameter_standard_initialize, \ \ - macro_f_console_parameter_t_initialize_6(fake_other_operation_lock_s, 0, f_console_flag_simple_e), \ - macro_f_console_parameter_t_initialize_6(fake_other_operation_restart_s, 0, f_console_flag_simple_e), \ - macro_f_console_parameter_t_initialize_6(fake_other_operation_show_s, 0, f_console_flag_simple_e), \ - macro_f_console_parameter_t_initialize_6(fake_other_operation_start_s, 0, f_console_flag_simple_e), \ - macro_f_console_parameter_t_initialize_6(fake_other_operation_stop_s, 0, f_console_flag_simple_e), \ + macro_f_console_parameter_t_initialize_6(firewall_operation_lock_s, 0, f_console_flag_simple_e), \ + macro_f_console_parameter_t_initialize_6(firewall_operation_restart_s, 0, f_console_flag_simple_e), \ + macro_f_console_parameter_t_initialize_6(firewall_operation_show_s, 0, f_console_flag_simple_e), \ + macro_f_console_parameter_t_initialize_6(firewall_operation_start_s, 0, f_console_flag_simple_e), \ + macro_f_console_parameter_t_initialize_6(firewall_operation_stop_s, 0, f_console_flag_simple_e), \ } #define firewall_parameter_total_d (f_console_parameter_state_type_total_d + 5) diff --git a/level_3/firewall/c/main/common/print.c b/level_3/firewall/c/main/common/print.c index b507598..1844ea8 100644 --- a/level_3/firewall/c/main/common/print.c +++ b/level_3/firewall/c/main/common/print.c @@ -15,6 +15,9 @@ extern "C" { "f_memory_array_increase_by", "f_string_dynamic_append", "f_string_dynamic_partial_append", + "f_string_dynamic_partial_append_nulless", + "f_string_dynamic_terminate_after", + "f_thread_create", "firewall_operate_process_rules", "fll_execute_program", "fll_fss_basic_read", diff --git a/level_3/firewall/c/main/common/print.h b/level_3/firewall/c/main/common/print.h index b57d6f0..c450697 100644 --- a/level_3/firewall/c/main/common/print.h +++ b/level_3/firewall/c/main/common/print.h @@ -48,7 +48,10 @@ extern "C" { firewall_f_f_memory_array_increase_by_e, firewall_f_f_string_dynamic_append_e, firewall_f_f_string_dynamic_partial_append_e, - firewall_f_firewall_operate_process_rules_perform_e, + firewall_f_f_string_dynamic_partial_append_nulless_e, + firewall_f_f_string_dynamic_terminate_after_e, + firewall_f_f_thread_create_e, + firewall_f_firewall_operate_process_rules_e, firewall_f_fll_execute_program_e, firewall_f_fll_fss_basic_read_e, firewall_f_fll_fss_basic_list_read_e, diff --git a/level_3/firewall/c/main/common/string.c b/level_3/firewall/c/main/common/string.c index a71c403..afb3440 100644 --- a/level_3/firewall/c/main/common/string.c +++ b/level_3/firewall/c/main/common/string.c @@ -93,14 +93,6 @@ extern "C" { const f_string_static_t firewall_tool_ipset_s = macro_f_string_static_t_initialize_1(FIREWALL_tool_ipset_s, 0, FIREWALL_tool_ipset_s_length); #endif // _di_firewall_s_ -#ifndef _di_firewall_operation_s_ - const f_string_static_t firewall_operation_start_s = macro_f_string_static_t_initialize_1(FIREWALL_operation_start_s, 0, FIREWALL_operation_start_s_length); - const f_string_static_t firewall_operation_stop_s = macro_f_string_static_t_initialize_1(FIREWALL_operation_stop_s, 0, FIREWALL_operation_stop_s_length); - const f_string_static_t firewall_operation_restart_s = macro_f_string_static_t_initialize_1(FIREWALL_operation_restart_s, 0, FIREWALL_operation_restart_s_length); - const f_string_static_t firewall_operation_lock_s = macro_f_string_static_t_initialize_1(FIREWALL_operation_lock_s, 0, FIREWALL_operation_lock_s_length); - const f_string_static_t firewall_operation_show_s = macro_f_string_static_t_initialize_1(FIREWALL_operation_show_s, 0, FIREWALL_operation_show_s_length); -#endif // _di_firewall_operation_s_ - #ifndef _di_firewall_path_s_ const f_string_static_t firewall_file_first_s = macro_f_string_static_t_initialize_1(FIREWALL_file_first_s, 0, FIREWALL_file_first_s_length); const f_string_static_t firewall_file_last_s = macro_f_string_static_t_initialize_1(FIREWALL_file_last_s, 0, FIREWALL_file_last_s_length); @@ -111,15 +103,15 @@ extern "C" { const f_string_static_t firewall_network_devices_s = macro_f_string_static_t_initialize_1(FIREWALL_network_devices_s, 0, FIREWALL_network_devices_s_length); #endif // _di_firewall_path_s_ -#ifndef _di_firewall_show_s_ - const f_string_static_t firewall_show_filter_s = macro_f_string_static_t_initialize_1(FIREWALL_show_filter_s, 0, FIREWALL_show_filter_s_length); - const f_string_static_t firewall_show_mangle_s = macro_f_string_static_t_initialize_1(FIREWALL_show_mangle_s, 0, FIREWALL_show_mangle_s_length); - const f_string_static_t firewall_show_nat_s = macro_f_string_static_t_initialize_1(FIREWALL_show_nat_s, 0, FIREWALL_show_nat_s_length); +#ifndef _di_firewall_print_show_s_ + const f_string_static_t firewall_print_show_filter_s = macro_f_string_static_t_initialize_1(FIREWALL_print_show_filter_s, 0, FIREWALL_print_show_filter_s_length); + const f_string_static_t firewall_print_show_mangle_s = macro_f_string_static_t_initialize_1(FIREWALL_print_show_mangle_s, 0, FIREWALL_print_show_mangle_s_length); + const f_string_static_t firewall_print_show_nat_s = macro_f_string_static_t_initialize_1(FIREWALL_print_show_nat_s, 0, FIREWALL_print_show_nat_s_length); - const f_string_static_t firewall_show_bars_26_s = macro_f_string_static_t_initialize_1(FIREWALL_show_bars_26_s, 0, FIREWALL_show_bars_26_s_length); - const f_string_static_t firewall_show_bars_27_s = macro_f_string_static_t_initialize_1(FIREWALL_show_bars_27_s, 0, FIREWALL_show_bars_27_s_length); - const f_string_static_t firewall_show_bars_28_s = macro_f_string_static_t_initialize_1(FIREWALL_show_bars_28_s, 0, FIREWALL_show_bars_28_s_length); -#endif // _di_firewall_show_s_ + const f_string_static_t firewall_print_show_bars_26_s = macro_f_string_static_t_initialize_1(FIREWALL_print_show_bars_26_s, 0, FIREWALL_print_show_bars_26_s_length); + const f_string_static_t firewall_print_show_bars_27_s = macro_f_string_static_t_initialize_1(FIREWALL_print_show_bars_27_s, 0, FIREWALL_print_show_bars_27_s_length); + const f_string_static_t firewall_print_show_bars_28_s = macro_f_string_static_t_initialize_1(FIREWALL_print_show_bars_28_s, 0, FIREWALL_print_show_bars_28_s_length); +#endif // _di_firewall_print_show_s_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/firewall/c/main/common/string.h b/level_3/firewall/c/main/common/string.h index e9c3df3..32760bb 100644 --- a/level_3/firewall/c/main/common/string.h +++ b/level_3/firewall/c/main/common/string.h @@ -349,33 +349,33 @@ extern "C" { #endif // _di_firewall_path_s_ /** - * The show option related strings. + * The show option related strings for printing to the screen. */ -#ifndef _di_firewall_show_s_ - #define FIREWALL_show_filter_s "FILTER" - #define FIREWALL_show_mangle_s "MANGLE" - #define FIREWALL_show_nat_s "NAT" - - #define FIREWALL_show_bars_26_s "==========================" - #define FIREWALL_show_bars_27_s "============================" - #define FIREWALL_show_bars_28_s "============================" - - #define FIREWALL_show_filter_s_length 6 - #define FIREWALL_show_mangle_s_length 6 - #define FIREWALL_show_nat_s_length 3 - - #define FIREWALL_show_bars_26_s_length 26 - #define FIREWALL_show_bars_27_s_length 27 - #define FIREWALL_show_bars_28_s_length 28 - - extern const f_string_static_t firewall_show_filter_s; - extern const f_string_static_t firewall_show_mangle_s; - extern const f_string_static_t firewall_show_nat_s; - - extern const f_string_static_t firewall_show_bars_26_s; - extern const f_string_static_t firewall_show_bars_27_s; - extern const f_string_static_t firewall_show_bars_28_s; -#endif // _di_firewall_show_s_ +#ifndef _di_firewall_print_show_s_ + #define FIREWALL_print_show_filter_s "FILTER" + #define FIREWALL_print_show_mangle_s "MANGLE" + #define FIREWALL_print_show_nat_s "NAT" + + #define FIREWALL_print_show_bars_26_s "==========================" + #define FIREWALL_print_show_bars_27_s "============================" + #define FIREWALL_print_show_bars_28_s "============================" + + #define FIREWALL_print_show_filter_s_length 6 + #define FIREWALL_print_show_mangle_s_length 6 + #define FIREWALL_print_show_nat_s_length 3 + + #define FIREWALL_print_show_bars_26_s_length 26 + #define FIREWALL_print_show_bars_27_s_length 27 + #define FIREWALL_print_show_bars_28_s_length 28 + + extern const f_string_static_t firewall_print_show_filter_s; + extern const f_string_static_t firewall_print_show_mangle_s; + extern const f_string_static_t firewall_print_show_nat_s; + + extern const f_string_static_t firewall_print_show_bars_26_s; + extern const f_string_static_t firewall_print_show_bars_27_s; + extern const f_string_static_t firewall_print_show_bars_28_s; +#endif // _di_firewall_print_show_s_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/firewall/c/main/common/type.c b/level_3/firewall/c/main/common/type.c index 0a6da2b..eec7d79 100644 --- a/level_3/firewall/c/main/common/type.c +++ b/level_3/firewall/c/main/common/type.c @@ -14,14 +14,15 @@ extern "C" { f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->buffer.string, &cache->buffer.used, &cache->buffer.size); f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->device.string, &cache->device.used, &cache->device.size); f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->ip_list.string, &cache->ip_list.used, &cache->ip_list.size); - f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->local_buffer.string, &cache->local_buffer.used, &cache->local_buffer.size); f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->path_file.string, &cache->path_file.used, &cache->path_file.size); f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->path_file_specific.string, &cache->path_file_specific.used, &cache->path_file_specific.size); f_memory_array_resize(0, sizeof(f_char_t), (void **) &cache->protocol.string, &cache->protocol.used, &cache->protocol.size); f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &cache->arguments.array, &cache->arguments.used, &cache->arguments.size, &f_string_dynamics_delete_callback); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &cache->basic_objects.string, &cache->basic_objects.used, &cache->basic_objects.size); + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &cache->delimits.array, &cache->delimits.used, &cache->delimits.size); + + f_memory_array_resize(0, sizeof(f_range_t), (void **) &cache->basic_objects.array, &cache->basic_objects.used, &cache->basic_objects.size); f_memory_arrays_resize(0, sizeof(f_ranges_t), (void **) &cache->basic_contents.array, &cache->basic_contents.used, &cache->basic_contents.size, &f_rangess_delete_callback); } #endif // _di_firewall_cache_delete_ @@ -32,10 +33,12 @@ extern "C" { if (!data) return; f_memory_array_resize(0, sizeof(f_char_t), (void **) &data->buffer.string, &data->buffer.used, &data->buffer.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &data->chain_ids.string, &data->chain_ids.used, &data->chain_ids.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &data->delimits.string, &data->delimits.used, &data->delimits.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &data->chain_objects.string, &data->chain_objects.used, &data->chain_objects.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &data->rule_objects.string, &data->rule_objects.used, &data->rule_objects.size); + + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &data->chain_ids.array, &data->chain_ids.used, &data->chain_ids.size); + + f_memory_array_resize(0, sizeof(f_range_t), (void **) &data->comments.array, &data->comments.used, &data->comments.size); + f_memory_array_resize(0, sizeof(f_range_t), (void **) &data->chain_objects.array, &data->chain_objects.used, &data->chain_objects.size); + f_memory_array_resize(0, sizeof(f_range_t), (void **) &data->rule_objects.array, &data->rule_objects.used, &data->rule_objects.size); f_memory_arrays_resize(0, sizeof(f_ranges_t), (void **) &data->chain_contents.array, &data->chain_contents.used, &data->chain_contents.size, &f_rangess_delete_callback); f_memory_arrays_resize(0, sizeof(f_ranges_t), (void **) &data->rule_contents.array, &data->rule_contents.used, &data->rule_contents.size, &f_rangess_delete_callback); diff --git a/level_3/firewall/c/main/common/type.h b/level_3/firewall/c/main/common/type.h index a300a8d..209d725 100644 --- a/level_3/firewall/c/main/common/type.h +++ b/level_3/firewall/c/main/common/type.h @@ -22,31 +22,33 @@ extern "C" { * Properties: * - file: The file structure. * - * - buffer: A generic string buffer. - * - device: The device string. - * - ip_list: The ip_list string. - * - local_buffer: The protocol string. - * - path_file: The protocol string. - * - path_file_specific: The protocol string. - * - protocol: The protocol string. - * - arguments: The array of strings. + * - buffer: A buffer used when proessing the basic objects and contents cache. + * - device: The device. + * - ip_list: The ip list. + * - path_file: The path to a file. + * - path_file_specific: The specific path to a file. + * - protocol: The protocol. + * - arguments: The arguments array. + * + * - delimits: The delimits array used when loading FSS data. * * - basic_objects: The FSS Basic Objects. * - basic_contents: The FSS Basic Contents. */ #ifndef _di_firewall_cache_t_ typedef struct { - f_file_t file = f_file_t_initialize; + f_file_t file; f_string_dynamic_t buffer; f_string_dynamic_t device; f_string_dynamic_t ip_list; - f_string_dynamic_t local_buffer; f_string_dynamic_t path_file; f_string_dynamic_t path_file_specific; f_string_dynamic_t protocol; f_string_dynamics_t arguments; + f_number_unsigneds_t delimits; + f_ranges_t basic_objects; f_rangess_t basic_contents; } firewall_cache_t; @@ -60,8 +62,8 @@ extern "C" { f_string_dynamic_t_initialize, \ f_string_dynamic_t_initialize, \ f_string_dynamic_t_initialize, \ - f_string_dynamic_t_initialize, \ f_string_dynamics_t_initialize, \ + f_number_unsigneds_t_initialize, \ f_ranges_t_initialize, \ f_rangess_t_initialize, \ } @@ -81,10 +83,9 @@ extern "C" { * - stop: The stop position. * - range: A range used during operation processing. * - * - buffer: The buffer used for during processing. + * - buffer: The entire set of chains and rules to operate on. * * - chain_ids: The list of chain IDs. - * - delimits: The delimits array used when loading FSS data. * * - chain_objects: The list of chain Objects. * - rule_objects: The list of rule Objects. @@ -103,11 +104,11 @@ extern "C" { f_number_unsigned_t stop; f_range_t range; - f_number_unsigneds_t chain_ids; - f_number_unsigneds_t delimits; - f_string_dynamic_t buffer; + f_number_unsigneds_t chain_ids; + + f_ranges_t comments; f_ranges_t chain_objects; f_ranges_t rule_objects; f_rangess_t chain_contents; @@ -124,9 +125,9 @@ extern "C" { 0, \ 0, \ f_range_t_initialize, \ - f_number_unsigneds_t_initialize, \ - f_number_unsigneds_t_initialize, \ f_string_dynamic_t_initialize, \ + f_number_unsigneds_t_initialize, \ + f_ranges_t_initialize, \ f_ranges_t_initialize, \ f_ranges_t_initialize, \ f_rangess_t_initialize, \ @@ -205,7 +206,7 @@ extern "C" { * This does not alter main.setting.state.status. */ #ifndef _di_firewall_cache_delete_ - extern void firewall_data_delete(firewall_cache_t * const cache); + extern void firewall_cache_delete(firewall_cache_t * const cache); #endif // _di_firewall_cache_delete_ /** diff --git a/level_3/firewall/c/main/firewall.h b/level_3/firewall/c/main/firewall.h index 13ac460..fe51fbf 100644 --- a/level_3/firewall/c/main/firewall.h +++ b/level_3/firewall/c/main/firewall.h @@ -41,7 +41,11 @@ // FLL-2 includes. #include +#include #include +#include +#include +#include #include #include @@ -56,11 +60,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include diff --git a/level_3/firewall/c/main/operate.c b/level_3/firewall/c/main/operate.c index d541f1f..62c478a 100644 --- a/level_3/firewall/c/main/operate.c +++ b/level_3/firewall/c/main/operate.c @@ -17,14 +17,14 @@ extern "C" { return; } - main->setting.state.status = f_directory_list(firewall_network_devices_s, 0, alphasort, &main->data.devices); + main->setting.state.status = f_directory_list(firewall_network_devices_s, 0, alphasort, &main->setting.devices); if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_data_not) { firewall_print_error_network_device_none(&main->program.error); } else if (F_status_set_fine(main->setting.state.status) == F_failure) { - firewall_print_error_directory_read(&main->program.error, firewall_network_devices_s); + firewall_print_error_file(&main->program.error, macro_firewall_f(f_directory_list), firewall_network_devices_s, f_file_operation_read_s, fll_error_file_type_directory_e); } else { firewall_print_error(&main->program.error, macro_firewall_f(f_console_parameter_process)); @@ -37,18 +37,18 @@ extern "C" { f_string_static_t buffer = f_string_static_t_initialize; // Remove "lo" (loopback) from the device listing. - for (; i < main->data.devices.used; ++i) { + for (; i < main->setting.devices.used; ++i) { if (firewall_signal_check(main)) return; - if (f_compare_dynamic(firewall_device_loop_s, main->data.devices.array[i]) == F_equal_to) { - buffer = main->data.devices.array[i]; + if (f_compare_dynamic(firewall_device_loop_s, main->setting.devices.array[i]) == F_equal_to) { + buffer = main->setting.devices.array[i]; - for (--main->data.devices.used; i < main->data.devices.used; ++i) { - main->data.devices.array[i] = main->data.devices.array[i + 1]; + for (--main->setting.devices.used; i < main->setting.devices.used; ++i) { + main->setting.devices.array[i] = main->setting.devices.array[i + 1]; } // for - main->data.devices.array[main->data.devices.used] = buffer; + main->setting.devices.array[main->setting.devices.used] = buffer; } } // for @@ -62,7 +62,7 @@ extern "C" { memcpy(path_file_other, firewall_network_path_s.string, sizeof(f_char_t) * firewall_network_path_s.used); memcpy(path_file_other + firewall_network_path_s.used, firewall_file_other_s.string, sizeof(f_char_t) * firewall_file_other_s.used); - firewall_operate_buffer_rules(&main, buffer, F_false); + firewall_operate_buffer_chain(main, buffer, F_false); if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_child) return; for (i = 0; i < main->data.chain_objects.used; ++i) { @@ -92,12 +92,14 @@ extern "C" { main->data.range.start = main->data.chain_contents.array[main->data.lock].array[0].start; main->data.range.stop = main->data.chain_contents.array[main->data.lock].array[0].stop; - firewall_operate_load_rules(main); + firewall_operate_buffer_rules(main); + + firewall_operate_rules(main); } else { main->setting.state.status = F_status_set_error(F_data); - firewall_print_error_operation_files_missing(&main->error, firewall_operation_lock_s, path_file_other); + firewall_print_error_operation_files_missing(&main->program.error, firewall_operation_lock_s, buffer); } return; @@ -109,20 +111,23 @@ extern "C" { firewall_operate_default_lock(main); - if (F_status_is_error(status) || status == F_child) return; + if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_child) return; main->data.chain = main->data.stop; main->data.is = firewall_data_is_global_e | firewall_data_is_stop_e; main->data.range.start = main->data.chain_contents.array[main->data.stop].array[0].start; main->data.range.stop = main->data.chain_contents.array[main->data.stop].array[0].stop; - firewall_operate_load_rules(&main); + firewall_operate_buffer_rules(main); + + firewall_operate_rules(main); + if (F_status_is_error(main->setting.state.status) || (main->data.has & firewall_main_flag_operation_stop_e) || main->setting.state.status == F_child) return; } else { main->setting.state.status = F_status_set_error(F_data); - firewall_print_error_operation_files_missing(&main->error, firewall_operation_stop_s, path_file_other); + firewall_print_error_operation_files_missing(&main->program.error, firewall_operation_stop_s, buffer); return; } @@ -133,13 +138,13 @@ extern "C" { buffer.used = firewall_network_path_s.used + firewall_file_first_s.used; f_char_t path_file_first[buffer.used + 1]; - buffer.string = path_file_first_string; + buffer.string = path_file_first; path_file_first[buffer.used] = 0; memcpy(path_file_first, firewall_network_path_s.string, sizeof(f_char_t) * firewall_network_path_s.used); memcpy(path_file_first + firewall_network_path_s.used, firewall_file_first_s.string, sizeof(f_char_t) * firewall_file_first_s.used); - firewall_operate_buffer_rules(main, buffer, F_false); + firewall_operate_buffer_chain(main, buffer, F_false); if (main->setting.flag & firewall_main_flag_operation_start_e) { firewall_operate_delete_chains(main); @@ -151,18 +156,19 @@ extern "C" { main->data.is = firewall_data_is_global_e; - firewall_operate_load_chains(main); + firewall_operate_chains(main); + if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_child || (main->setting.flag & firewall_main_flag_operation_stop_e)) return; { - for (f_number_unsigned_t j = 0; j < main->data.devices.used; ++j) { + for (f_number_unsigned_t j = 0; j < main->setting.devices.used; ++j) { if (firewall_signal_check(main)) return; - main->data.path_file.used = 0; - local.device = j; + main->cache.path_file.used = 0; + main->data.device = j; - main->setting.state.status = f_memory_array_increase_by(firewall_network_path_s.used + data.devices.array[j].used + firewall_file_suffix_s.used + 1, sizeof(f_char_t), (void **) &main->data.path_file.string, &main->data.path_file.used, &main->data.path_file.size); + main->setting.state.status = f_memory_array_increase_by(firewall_network_path_s.used + main->setting.devices.array[j].used + firewall_file_suffix_s.used + 1, sizeof(f_char_t), (void **) &main->cache.path_file.string, &main->cache.path_file.used, &main->cache.path_file.size); if (F_status_is_error(main->setting.state.status)) { firewall_print_error(&main->program.error, macro_firewall_f(f_memory_array_increase_by)); @@ -170,14 +176,14 @@ extern "C" { return; } - main->setting.state.status = f_string_dynamic_append(firewall_network_path_s, &main->data.path_file); + main->setting.state.status = f_string_dynamic_append(firewall_network_path_s, &main->cache.path_file); if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_string_dynamic_append(data.devices.array[j], &main->data.path_file); + main->setting.state.status = f_string_dynamic_append(main->setting.devices.array[j], &main->cache.path_file); } if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_string_dynamic_append(firewall_file_suffix_s, &main->data.path_file); + main->setting.state.status = f_string_dynamic_append(firewall_file_suffix_s, &main->cache.path_file); } if (F_status_is_error(main->setting.state.status)) { @@ -186,22 +192,22 @@ extern "C" { return; } - firewall_operate_buffer_rules(main, main->data.path_file, F_true); + firewall_operate_buffer_chain(main, main->cache.path_file, F_true); firewall_operate_create_custom_chains(main); main->data.is = 0; - firewall_operate_load_chains(main); + firewall_operate_chains(main); if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_child || (main->setting.flag & firewall_main_flag_operation_stop_e)) return; } // for - main->data.path_file.used = 0; + main->cache.path_file.used = 0; - main->setting.state.status = f_string_dynamic_append(firewall_network_path_s, &main->data.path_file); + main->setting.state.status = f_string_dynamic_append(firewall_network_path_s, &main->cache.path_file); if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_string_dynamic_append(firewall_file_last_s, &main->data.path_file); + main->setting.state.status = f_string_dynamic_append(firewall_file_last_s, &main->cache.path_file); } if (F_status_is_error(main->setting.state.status)) { @@ -210,13 +216,13 @@ extern "C" { return; } - firewall_operate_buffer_rules(main, main->data.path_file, F_false); + firewall_operate_buffer_chain(main, main->cache.path_file, F_false); firewall_operate_create_custom_chains(main); main->data.is = firewall_data_is_global_e; - firewall_operate_load_chains(main); + firewall_operate_chains(main); if (F_status_is_error(main->setting.state.status) || main->setting.state.status == F_child) return; } } @@ -225,6 +231,54 @@ extern "C" { } #endif // _di_firewall_operate_ +#ifndef _di_firewall_operate_chains_ + void firewall_operate_chains(firewall_main_t * const main) { + + if (!main || F_status_is_error_not(main->setting.state.status) && main->setting.state.status == F_child) return; + + for (f_number_unsigned_t i = 0; i < main->data.chain_contents.used; ++i) { + + main->data.range = main->data.chain_contents.array[i].array[0]; + + if ((main->data.has & firewall_data_has_main_e) && i == main->data.main) { + main->data.is |= firewall_data_is_main_e; + } + else { + main->data.is &= ~firewall_data_is_main_e; + } + + main->data.chain = i; + + firewall_operate_buffer_rules(main); + + firewall_operate_rules(main); + + if (F_status_is_error(main->setting.state.status) || (main->setting.flag & firewall_main_flag_operation_stop_e) || main->setting.state.status == F_child) return; + } // for + + main->setting.state.status = F_okay; + } +#endif // _di_firewall_operate_chains_ + +#ifndef _di_firewall_operate_rules_ + void firewall_operate_rules(firewall_main_t * const main) { + + if (!main || F_status_is_error_not(main->setting.state.status) && main->setting.state.status == F_child) return; + + firewall_operate_process_rules(main); + + if (F_status_is_error(main->setting.state.status)) { + if (F_status_set_fine(main->setting.state.status) != F_failure) { + firewall_print_error_unhandled(&main->program.error, macro_firewall_f(firewall_operate_process_rules), f_string_empty_s); + } + + return; + } + + main->setting.state.status = F_okay; + } +#endif // _di_firewall_operate_rules_ + #ifndef _di_firewall_operate_show_ void firewall_operate_show(firewall_main_t * const main) { @@ -260,7 +314,7 @@ extern "C" { firewall_show_parameter_list_s, }; - const f_string_static_t show_arrays[][] = { + f_string_static_t * const show_arrays[] = { show_nats, show_mangles, show_filters, @@ -273,21 +327,21 @@ extern "C" { }; const f_string_static_t show_lefts[] = { - firewall_show_bars_27_s, - firewall_show_bars_26_s, - firewall_show_bars_26_s, + firewall_print_show_bars_27_s, + firewall_print_show_bars_26_s, + firewall_print_show_bars_26_s, }; const f_string_static_t show_headers[] = { - firewall_show_nat_s, - firewall_show_mangle_s, - firewall_show_filter_s, + firewall_print_show_nat_s, + firewall_print_show_mangle_s, + firewall_print_show_filter_s, }; const f_string_static_t show_rights[] = { - firewall_show_bars_28_s, - firewall_show_bars_26_s, - firewall_show_bars_26_s, + firewall_print_show_bars_28_s, + firewall_print_show_bars_26_s, + firewall_print_show_bars_26_s, }; const uint16_t show_flags[] = { @@ -303,21 +357,21 @@ extern "C" { parameters.array = show_arrays[i]; parameters.used = show_lengths[i]; - firewall_print_message_show_header(&main->output, show_lefts[i], show_headers[i], show_rights[i]); + firewall_print_message_show_header(&main->program.output, show_lefts[i], show_headers[i], show_rights[i]); - main->setting.status = fll_execute_program(firewall_tool_iptables_s, parameters, 0, 0, (void *) &return_code); + main->setting.state.status = fll_execute_program(firewall_tool_iptables_s, parameters, 0, 0, (void *) &return_code); - if (status == F_child) { - main->child = return_code; + if (main->setting.state.status == F_child) { + main->program.child = return_code; return; } - fll_print_dynamic_raw(f_string_eol_s, main->output.to); - f_file_stream_flush(main->output.to); + fll_print_dynamic_raw(f_string_eol_s, main->program.output.to); + f_file_stream_flush(main->program.output.to); - if (F_status_is_error(main->setting.status)) { - firewall_print_error_operation(&main->error, firewall_tool_iptables_s, parameters); + if (F_status_is_error(main->setting.state.status)) { + firewall_print_error_operation(&main->program.error, firewall_tool_iptables_s, parameters); return; } diff --git a/level_3/firewall/c/main/operate.h b/level_3/firewall/c/main/operate.h index 331b440..81b6109 100644 --- a/level_3/firewall/c/main/operate.h +++ b/level_3/firewall/c/main/operate.h @@ -30,21 +30,21 @@ extern "C" { * * Errors (with error bit) from: f_directory_list() * Errors (with error bit) from: f_memory_array_increase_by() - * Errors (with error bit) from: firewall_operate_buffer_rules() + * Errors (with error bit) from: firewall_operate_buffer_chain() * Errors (with error bit) from: firewall_operate_create_custom_chains() * Errors (with error bit) from: firewall_operate_default_lock() * Errors (with error bit) from: firewall_operate_delete_chains() - * Errors (with error bit) from: firewall_operate_load_rules() + * Errors (with error bit) from: firewall_operate_rules() * Errors (with error bit) from: firewall_operate_process_rules() * Errors (with error bit) from: firewall_operate_show() * * @see f_directory_list() * @see f_memory_array_increase_by() - * @see firewall_operate_buffer_rules() + * @see firewall_operate_buffer_chain() * @see firewall_operate_create_custom_chains() * @see firewall_operate_default_lock() * @see firewall_operate_delete_chains() - * @see firewall_operate_load_rules() + * @see firewall_operate_rules() * @see firewall_operate_process_rules() * @see firewall_operate_show() */ @@ -53,6 +53,29 @@ extern "C" { #endif // _di_firewall_operate_ /** + * Load and operate the each of the Content chains. + * + * @param main + * The main program and setting data. + * + * This alters: + * - main.data.is. + * - main.data.range. + * + * This alters main.setting.state.status: + * F_okay on success. + * + * F_interrupt (with error bit) on interrupt signal received. + * + * Errors (with error bit) from: firewall_operate_rules() + * + * @see firewall_operate_rules() + */ +#ifndef _di_firewall_operate_chains_ + extern void firewall_operate_chains(firewall_main_t * const main); +#endif // _di_firewall_operate_chains_ + +/** * Perform the firewall show operation. * * @param main @@ -74,6 +97,29 @@ extern "C" { extern void firewall_operate_show(firewall_main_t * const main); #endif // _di_firewall_operate_show_ +/** + * Operate the rules. + * + * @param main + * The main program and setting data. + * + * This alters main.setting.state.status: + * F_okay on success. + * + * F_interrupt (with error bit) on interrupt signal received. + * + * Errors (with error bit) from: f_fss_apply_delimit() + * Errors (with error bit) from: firewall_operate_process_rules() + * Errors (with error bit) from: fll_fss_extended_read() + * + * @see f_fss_apply_delimit() + * @see firewall_operate_process_rules() + * @see fll_fss_extended_read() + */ +#ifndef _di_firewall_operate_rules_ + extern void firewall_operate_rules(firewall_main_t * const main); +#endif // _di_firewall_operate_rules_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_3/firewall/c/main/operate/buffer.c b/level_3/firewall/c/main/operate/buffer.c index 1befc0d..c15fed2 100644 --- a/level_3/firewall/c/main/operate/buffer.c +++ b/level_3/firewall/c/main/operate/buffer.c @@ -4,18 +4,21 @@ extern "C" { #endif -#ifndef _di_firewall_operate_buffer_rules_ - void firewall_operate_buffer_rules(firewall_main_t * const main, const f_string_static_t file, const bool optional) { +#ifndef _di_firewall_operate_buffer_chain_ + void firewall_operate_buffer_chain(firewall_main_t * const main, const f_string_static_t file, const bool optional) { if (!main || F_status_is_error_not(main->setting.state.status) && main->setting.state.status == F_child) return; main->data.buffer.used = 0; + main->data.chain_contents.used = 0; + main->data.chain_objects.used = 0; + main->cache.delimits.used = 0; main->setting.state.status = f_file_open(file, 0, &main->cache.file); if (F_status_is_error(main->setting.state.status)) { if (!optional || optional && F_status_set_fine(main->setting.state.status) != F_file_found_not && F_status_set_fine(main->setting.state.status) != F_file_open && F_status_set_fine(main->setting.state.status) != F_file_descriptor) { - firewall_print_error_file(&main->program.error, macro_firewall_f(f_file_open), f_file_operation_open_s, fll_error_file_type_file_e); + firewall_print_error_file(&main->program.error, macro_firewall_f(f_file_open), file, f_file_operation_open_s, fll_error_file_type_file_e); return; } @@ -27,7 +30,7 @@ extern "C" { f_file_stream_close(&main->cache.file); if (F_status_is_error(main->setting.state.status)) { - firewall_print_error_file(&main->program.error, macro_firewall_f(f_file_read), f_file_operation_read_s, fll_error_file_type_file_e); + firewall_print_error_file(&main->program.error, macro_firewall_f(f_file_read), file, f_file_operation_read_s, fll_error_file_type_file_e); return; } @@ -36,21 +39,20 @@ extern "C" { main->data.range.start = 0; main->data.range.stop = main->data.buffer.used - 1; -// @fixme bufferchain_objects, etc.. - main->setting.state.status = fll_fss_basic_list_read(main->data.buffer, main->setting.state, &main->data.range, &main->data.bufferchain_objects, &main->data.bufferchain_contents, &main->data.delimits, 0, &main->data.comments); + fll_fss_basic_list_read(main->data.buffer, &main->data.range, &main->data.chain_objects, &main->data.chain_contents, &main->cache.delimits, 0, &main->data.comments, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_data_not_eos || F_status_set_fine(main->setting.state.status) == F_data_not || F_status_set_fine(main->setting.state.status) == F_data_not_stop) { firewall_print_error_file_empty(&main->program.error, file); } else { - firewall_print_error_file(&main->program.error, macro_firewall_f(fll_fss_basic_list_read), f_file_operation_process_s, fll_error_file_type_file_e); + firewall_print_error_file(&main->program.error, macro_firewall_f(fll_fss_basic_list_read), file, f_file_operation_process_s, fll_error_file_type_file_e); } return; } else { - main->setting.state.status = f_fss_apply_delimit(state, main->data.delimits, &main->data.buffer); + f_fss_apply_delimit(main->cache.delimits, &main->data.buffer, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { firewall_print_error(&main->program.error, macro_firewall_f(f_fss_apply_delimit)); @@ -62,6 +64,35 @@ extern "C" { main->setting.state.status = F_okay; } +#endif // _di_firewall_operate_buffer_chain_ + +#ifndef _di_firewall_operate_buffer_rules_ + void firewall_operate_buffer_rules(firewall_main_t * const main) { + + if (!main || F_status_is_error_not(main->setting.state.status) && main->setting.state.status == F_child) return; + + main->cache.delimits.used = 0; + main->data.rule_contents.used = 0; + main->data.rule_objects.used = 0; + + fll_fss_extended_read(main->data.buffer, &main->data.range, &main->data.rule_objects, &main->data.rule_contents, 0, 0, &main->cache.delimits, 0, &main->setting.state); + + if (F_status_is_error(main->setting.state.status)) { + firewall_print_error(&main->program.error, macro_firewall_f(fll_fss_extended_read)); + + return; + } + + f_fss_apply_delimit(main->cache.delimits, &main->data.buffer, &main->setting.state); + + if (F_status_is_error(main->setting.state.status)) { + firewall_print_error(&main->program.error, macro_firewall_f(f_fss_apply_delimit)); + + return; + } + + main->setting.state.status = F_okay; + } #endif // _di_firewall_operate_buffer_rules_ #ifdef __cplusplus diff --git a/level_3/firewall/c/main/operate/buffer.h b/level_3/firewall/c/main/operate/buffer.h index 4a43f62..3a2a1a8 100644 --- a/level_3/firewall/c/main/operate/buffer.h +++ b/level_3/firewall/c/main/operate/buffer.h @@ -17,11 +17,20 @@ extern "C" { #endif /** - * Buffer firewall rules. + * Buffer firewall chain. + * + * The rules being processed are selected from main.data.range within main.data.buffer. + * Delimits are applied to the main.data.buffer on success. * * @param main * The main program and setting data. * + * This alters: + * - main.cache.delimits. + * - main.data.buffer. + * - main.data.chain_contents. + * - main.data.chain_objects. + * * This alters main.setting.state.status: * F_okay on success. * F_child on child process exiting. @@ -43,8 +52,40 @@ extern "C" { * @see f_fss_apply_delimit() * @see fll_fss_basic_list_read() */ +#ifndef _di_firewall_operate_buffer_chain_ + extern void firewall_operate_buffer_chain(firewall_main_t * const main, const f_string_static_t file, const bool optional); +#endif // _di_firewall_operate_buffer_chain_ + +/** + * Buffer firewall rules. + * + * The rules being processed are selected from main.data.range within main.data.buffer. + * Delimits are applied to the main.data.buffer on success. + * + * @param main + * The main program and setting data. + * + * This alters: + * - main.cache.delimits. + * - main.data.buffer. + * - main.data.rule_contents. + * - main.data.rule_objects. + * + * This alters main.setting.state.status: + * F_okay on success. + * + * F_interrupt (with error bit) on interrupt signal received. + * + * Errors (with error bit) from: f_fss_apply_delimit() + * Errors (with error bit) from: firewall_operate_process_rules() + * Errors (with error bit) from: fll_fss_extended_read() + * + * @see f_fss_apply_delimit() + * @see firewall_operate_process_rules() + * @see fll_fss_extended_read() + */ #ifndef _di_firewall_operate_buffer_rules_ - extern void firewall_operate_buffer_rules(firewall_main_t * const main, const f_string_static_t file, const bool optional); + extern void firewall_operate_buffer_rules(firewall_main_t * const main); #endif // _di_firewall_operate_buffer_rules_ #ifdef __cplusplus diff --git a/level_3/firewall/c/main/operate/create.c b/level_3/firewall/c/main/operate/create.c index d7d5637..9186053 100644 --- a/level_3/firewall/c/main/operate/create.c +++ b/level_3/firewall/c/main/operate/create.c @@ -19,13 +19,13 @@ extern "C" { f_string_static_t tool = firewall_tool_iptables_s; - main->cache.chain_ids.used = 0; + main->data.chain_ids.used = 0; main->cache.arguments.used = 0; main->setting.state.status = f_memory_array_increase_by(2, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_memory_array_increase_by(main->cache.chain_objects.used, sizeof(f_number_unsigned_t), (void **) &main->cache.chain_ids.array, &main->cache.chain_ids.used, &main->cache.chain_ids.size); + main->setting.state.status = f_memory_array_increase_by(main->data.chain_objects.used, sizeof(f_number_unsigned_t), (void **) &main->data.chain_ids.array, &main->data.chain_ids.used, &main->data.chain_ids.size); } if (F_status_is_error(main->setting.state.status)) { @@ -34,10 +34,10 @@ extern "C" { return; } - main->cache.chain_ids.used = main->cache.chain_objects.used; - memset(main->cache.chain_ids.array, 0, sizeof(f_number_unsigned_t) * main->cache.chain_ids.used); + main->data.chain_ids.used = main->data.chain_objects.used; + memset(main->data.chain_ids.array, 0, sizeof(f_number_unsigned_t) * main->data.chain_ids.used); - main->setting.state.status = f_string_dynamic_append(firewall_chain_create_command_s, &main->cache.arguments.array[0]); + main->setting.state.status = f_string_dynamic_append(firewall_chain_create_operation_s, &main->cache.arguments.array[0]); if (F_status_is_error(main->setting.state.status)) { firewall_print_error(&main->program.error, macro_firewall_f(f_string_dynamic_append)); @@ -56,7 +56,7 @@ extern "C" { main->cache.arguments.used = 2; main->data.has = 0; - for (; i < main->cache.chain_objects.used; ++i) { + for (; i < main->data.chain_objects.used; ++i) { if (firewall_signal_check(main)) return; @@ -64,37 +64,37 @@ extern "C" { j = 0; // Skip globally reserved chain name: main. - if (f_compare_dynamic_partial_string(firewall_group_main_s.string, main->cache.buffer, firewall_group_main_s.used, main->cache.chain_objects.array[i]) == F_equal_to) { + if (f_compare_dynamic_partial_string(firewall_group_main_s.string, main->data.buffer, firewall_group_main_s.used, main->data.chain_objects.array[i]) == F_equal_to) { new_chain = F_false; main->data.has |= firewall_data_has_main_e; main->data.main = i; } // Skip globally reserved chain name: stop. - if (f_compare_dynamic_partial_string(firewall_group_stop_s.string, main->cache.buffer, firewall_group_stop_s.used, main->cache.chain_objects.array[i]) == F_equal_to) { + if (f_compare_dynamic_partial_string(firewall_group_stop_s.string, main->data.buffer, firewall_group_stop_s.used, main->data.chain_objects.array[i]) == F_equal_to) { new_chain = F_false; main->data.has |= firewall_data_has_stop_e; main->data.stop = i; } // Skip globally reserved chain name: lock. - if (f_compare_dynamic_partial_string(firewall_group_lock_s.string, main->cache.buffer, firewall_group_lock_s.used, main->cache.chain_objects.array[i]) == F_equal_to) { + if (f_compare_dynamic_partial_string(firewall_group_lock_s.string, main->data.buffer, firewall_group_lock_s.used, main->data.chain_objects.array[i]) == F_equal_to) { new_chain = F_false; main->data.has |= firewall_data_has_lock_e; main->data.lock = i; } // Skip globally reserved chain name: none. - if (f_compare_dynamic_partial_string(firewall_chain_none_s.string, main->cache.buffer, firewall_chain_none_s.used, main->cache.chain_objects.array[i]) == F_equal_to) { + if (f_compare_dynamic_partial_string(firewall_chain_none_s.string, main->data.buffer, firewall_chain_none_s.used, main->data.chain_objects.array[i]) == F_equal_to) { new_chain = F_false; } if (new_chain) { - for (; j < main->data.chains.used; ++j) { + for (; j < main->setting.chains.used; ++j) { - if (f_compare_dynamic_partial_string(main->data.chains.array[j].string, main->cache.buffer, main->data.chains.array[j].used, main->cache.chain_objects.array[i]) == F_equal_to) { + if (f_compare_dynamic_partial_string(main->setting.chains.array[j].string, main->data.buffer, main->setting.chains.array[j].used, main->data.chain_objects.array[i]) == F_equal_to) { new_chain = F_false; - main->cache.chain_ids.array[i] = j; + main->data.chain_ids.array[i] = j; break; } @@ -102,7 +102,7 @@ extern "C" { } if (new_chain) { - main->setting.state.status = f_memory_array_increase(firewall_default_allocation_step_d, sizeof(f_string_dynamic_t), (void **) &main->data.chains.array, &main->data.chains.used, &main->data.chains.size); + main->setting.state.status = f_memory_array_increase(firewall_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &main->setting.chains.array, &main->setting.chains.used, &main->setting.chains.size); if (F_status_is_error(main->setting.state.status)) { firewall_print_error(&main->program.error, macro_firewall_f(f_memory_array_increase)); @@ -111,14 +111,14 @@ extern "C" { } create_chain = F_true; - length = (main->data.chain_objects.array[i].stop - main->data.chain_objects.array[i].start) + 1; + length = (main->data.chain_objects.array[i].start > main->data.chain_objects.array[i].stop) ? 0 : (main->data.chain_objects.array[i].stop - main->data.chain_objects.array[i].start) + 1; main->cache.arguments.array[1].used = 0; main->setting.state.status = f_memory_array_increase_by(length + 1, sizeof(f_char_t), (void **) &main->cache.arguments.array[1].string, &main->cache.arguments.array[1].used, &main->cache.arguments.array[1].size); if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_memory_array_increase_by(length + 1, sizeof(f_char_t), (void **) &main->data.chains.array[main->data.chains.used].string, &main->data.chains.array[main->data.chains.used].used, &main->data.chains.array[main->data.chains.used].size); + main->setting.state.status = f_memory_array_increase_by(length + 1, sizeof(f_char_t), (void **) &main->setting.chains.array[main->setting.chains.used].string, &main->setting.chains.array[main->setting.chains.used].used, &main->setting.chains.array[main->setting.chains.used].size); } if (F_status_is_error(main->setting.state.status)) { @@ -127,20 +127,31 @@ extern "C" { return; } - main->data.chains.array[main->data.chains.used].used = 0; - main->data.chain_ids.array[i] = main->data.chains.used; + f_string_dynamic_partial_append_nulless(main->data.buffer, main->data.chain_objects.array[i], &main->cache.arguments.array[1]); - // Copy the string character by character, ignoring placeholders. - for (j = main->data.chain_objects.array[i].start; j <= main->data.chain_objects.array[i].stop; ++j) { + if (F_status_is_error_not(main->setting.state.status)) { + f_string_dynamic_partial_append_nulless(main->data.buffer, main->data.chain_objects.array[i], &main->setting.chains.array[main->setting.chains.used]); + } - if (main->data.buffer.string[j] == f_fss_placeholder_s.string[0]) continue; + if (F_status_is_error(main->setting.state.status)) { + firewall_print_error(&main->program.error, macro_firewall_f(f_string_dynamic_partial_append_nulless)); - main->data.chains.array[main->data.chains.used].string[main->data.chains.array[main->data.chains.used].used++] = main->data.buffer.string[j]; - main->cache.arguments.array[1].string[main->cache.arguments.array[1].used++] = main->data.buffer.string[j]; - } // for + return; + } + + f_string_dynamic_terminate_after(&main->cache.arguments.array[1]); + + if (F_status_is_error_not(main->setting.state.status)) { + f_string_dynamic_terminate_after(&main->setting.chains.array[main->setting.chains.used]); + } + + if (F_status_is_error(main->setting.state.status)) { + firewall_print_error(&main->program.error, macro_firewall_f(f_string_dynamic_terminate_after)); + + return; + } - main->cache.arguments.array[1].string[main->cache.arguments.array[1].used] = 0; - main->data.chains.array[main->data.chains.used].string[main->data.chains.array[main->data.chains.used].used] = 0; + main->data.chain_ids.array[i] = main->setting.chains.used; if (f_compare_dynamic(main->cache.arguments.array[1], firewall_chain_forward_s) == F_equal_to) { create_chain = F_false; @@ -159,14 +170,14 @@ extern "C" { } if (create_chain) { - firewall_print_debug_tool(main->program->warning, firewall_tool_iptables_s, main->cache.arguments); + firewall_print_debug_tool(&main->program.warning, firewall_tool_iptables_s, main->cache.arguments); tool = firewall_tool_iptables_s; main->setting.state.status = fll_execute_program(firewall_tool_iptables_s, main->cache.arguments, 0, 0, (void *) &return_code); if (main->setting.state.status == F_child) { - main->program->child = return_code; + main->program.child = return_code; return; } @@ -176,13 +187,13 @@ extern "C" { if (F_status_is_error_not(main->setting.state.status) && main->setting.state.status != F_child) { tool = firewall_tool_ip6tables_s; - firewall_print_debug_tool(main->program->warning, firewall_tool_ip6tables_s, main->cache.arguments); + firewall_print_debug_tool(&main->program.warning, firewall_tool_ip6tables_s, main->cache.arguments); main->setting.state.status = fll_execute_program(firewall_tool_ip6tables_s, main->cache.arguments, 0, 0, (void *) &return_code); } if (main->setting.state.status == F_child) { - main->program->child = return_code; + main->program.child = return_code; return; } @@ -191,7 +202,7 @@ extern "C" { if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_failure) { - firewall_print_error_operation(main->program->error, tool, main->cache.arguments); + firewall_print_error_operation(&main->program.error, tool, main->cache.arguments); } else { firewall_print_error(&main->program.error, macro_firewall_f(fll_execute_program)); @@ -201,7 +212,7 @@ extern "C" { } } - ++main->data.chains.used; + ++main->setting.chains.used; } } // for diff --git a/level_3/firewall/c/main/operate/create.h b/level_3/firewall/c/main/operate/create.h index 4fedb4d..0718c46 100644 --- a/level_3/firewall/c/main/operate/create.h +++ b/level_3/firewall/c/main/operate/create.h @@ -45,7 +45,7 @@ extern "C" { */ #ifndef _di_firewall_operate_create_custom_chains_ extern void firewall_operate_create_custom_chains(firewall_main_t * const main); -#endif / _di_firewall_operate_create_custom_chains_ +#endif // _di_firewall_operate_create_custom_chains_ #ifdef __cplusplus } // extern "C" diff --git a/level_3/firewall/c/main/operate/default.c b/level_3/firewall/c/main/operate/default.c index 0d46c96..c9e0f2f 100644 --- a/level_3/firewall/c/main/operate/default.c +++ b/level_3/firewall/c/main/operate/default.c @@ -17,7 +17,7 @@ extern "C" { f_string_static_t argument_array[arguments.used]; arguments.array = argument_array; - arguments.array[0] = firewall_action_policy_command_s; + arguments.array[0] = firewall_action_policy_operation_s; arguments.array[2] = firewall_chain_drop_s; int return_code = 0; @@ -30,14 +30,14 @@ extern "C" { for (j = 0; j < 2; ++j) { - firewall_print_debug_tool(data->main->warning, tools[j], arguments); + firewall_print_debug_tool(&main->program.warning, tools[j], arguments); return_code = 0; main->setting.state.status = fll_execute_program(tools[j], arguments, 0, 0, (void *) &return_code); if (main->setting.state.status == F_child) { - data->main->child = return_code; + main->program.child = return_code; return; } @@ -46,7 +46,7 @@ extern "C" { if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_failure) { - firewall_print_error_operation(main->program->error, tools[j], arguments); + firewall_print_error_operation(&main->program.error, tools[j], arguments); } else { firewall_print_error(&main->program.error, macro_firewall_f(fll_execute_program)); diff --git a/level_3/firewall/c/main/operate/delete.c b/level_3/firewall/c/main/operate/delete.c index 03670e0..c198d1c 100644 --- a/level_3/firewall/c/main/operate/delete.c +++ b/level_3/firewall/c/main/operate/delete.c @@ -10,14 +10,14 @@ extern "C" { if (!main || F_status_is_error_not(main->setting.state.status) && main->setting.state.status == F_child) return; const f_string_static_t tools[2] = { firewall_tool_iptables_s, firewall_tool_ip6tables_s }; - const f_string_static_t command[2] = { firewall_chain_flush_command_s, firewall_chain_delete_command_s }; + const f_string_static_t command[2] = { firewall_chain_flush_operation_s, firewall_chain_delete_operation_s }; f_string_statics_t arguments = f_string_statics_t_initialize; arguments.used = 1; f_string_static_t argument_array[arguments.used]; arguments.array = argument_array; - argument_array[0] = firewall_chain_flush_command_s; + argument_array[0] = firewall_chain_flush_operation_s; int return_code = 0; uint8_t i = 0; @@ -33,19 +33,19 @@ extern "C" { return_code = 0; - firewall_print_debug_tool(data->main->warning, tools[j], arguments); + firewall_print_debug_tool(&main->program.warning, tools[j], arguments); main->setting.state.status = fll_execute_program(tools[j], arguments, 0, 0, (void *) &return_code); if (main->setting.state.status == F_child) { - data->main->child = return_code; + main->program.child = return_code; return; } if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_failure) { - firewall_print_error_operation(main->program->error, tools[j], arguments); + firewall_print_error_operation(&main->program.error, tools[j], arguments); } else { firewall_print_error(&main->program.error, macro_firewall_f(fll_execute_program)); diff --git a/level_3/firewall/c/main/operate/load.c b/level_3/firewall/c/main/operate/load.c deleted file mode 100644 index 0a7ebda..0000000 --- a/level_3/firewall/c/main/operate/load.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "../firewall.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _di_firewall_operate_load_chains_ - void firewall_operate_load_chains(firewall_main_t * const main) { - - if (!main || F_status_is_error_not(main->setting.state.status) && main->setting.state.status == F_child) return; - - for (i = 0; i < local.chain_contents.used; ++i) { - - main->data.range = local.chain_contents.array[i].array[0]; - - if ((main->data.has & firewall_data_has_main_e) && i == main->data.main) { - main->data.is |= firewall_data_is_main_e; - } - else { - main->data.is &= ~firewall_data_is_main_e; - } - - main->data.chain = i; - - firewall_operate_load_rules(main); - if (F_status_is_error(main->setting.state.status) || (main->setting.flag & firewall_main_flag_operation_stop_e) || main->setting.state.status == F_child) return; - } // for - - main->setting.state.status = F_okay; - } -#endif // _di_firewall_operate_load_chains_ - -#ifndef _di_firewall_operate_load_rules_ - void firewall_operate_load_rules(firewall_main_t * const main) { - - if (!main || F_status_is_error_not(main->setting.state.status) && main->setting.state.status == F_child) return; - - main->data.buffer.used = 0; - main->data.delimits.used = 0; - main->data.rule_objects.used = 0; - main->data.rule_contents.used = 0; - -// @fixme the data.rule_objects and rule_contents may be in use by a caller function (specifically in operate.c via firewall_operate_buffer_rules()). - main->setting.state.status = fll_fss_extended_read(main->data.buffer, main->setting.state, main->data.range, &main->data.rule_objects, &main->data.rule_contents, 0, 0, &main->data.delimits, 0); - - if (F_status_is_error(main->setting.state.status)) { - firewall_print_error(&main->program.error, macro_firewall_f(fll_fss_extended_read)); - - return; - } - - main->setting.state.status = f_fss_apply_delimit(main->setting.state, main->data.delimits, &main->data.buffer); - - if (F_status_is_error(main->setting.state.status)) { - firewall_print_error(&main->program.error, macro_firewall_f(f_fss_apply_delimit)); - - return; - } - - firewall_operate_process_rules(main); - - if (F_status_is_error(main->setting.state.status)) { - if (F_status_set_fine(main->setting.state.status) != F_failure) { - firewall_print_error_unhandled(&main->error, macro_firewall_f(firewall_operate_process_rules)); - } - - return; - } - - main->setting.state.status = F_okay; - } -#endif // _di_firewall_operate_load_rules_ - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_3/firewall/c/main/operate/load.h b/level_3/firewall/c/main/operate/load.h deleted file mode 100644 index 0a030ae..0000000 --- a/level_3/firewall/c/main/operate/load.h +++ /dev/null @@ -1,75 +0,0 @@ -/** - * FLL - Level 3 - * - * Project: Firewall - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * Provides the load functionality. - * - * This is auto-included and should not need to be explicitly included. - */ -#ifndef _firewall_operate_load_h -#define _firewall_operate_load_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Load and process the Content chains. - * - * @param main - * The main program and setting data. - * - * This alters: - * - main.data.is. - * - main.data.range. - * - * This alters main.setting.state.status: - * F_okay on success. - * - * F_interrupt (with error bit) on interrupt signal received. - * - * Errors (with error bit) from: firewall_operate_load_rules() - * - * @see firewall_operate_load_rules() - */ -#ifndef _di_firewall_operate_load_chains_ - extern void firewall_operate_load_chains(firewall_main_t * const main); -#endif // _di_firewall_operate_load_chains_ - -/** - * Load and process the rules. - * - * @param main - * The main program and setting data. - * - * This alters: - * - main.data.buffer. - * - main.data.delimits. - * - main.data.rule_objects. - * - main.data.rule_contents. - * - * This alters main.setting.state.status: - * F_okay on success. - * - * F_interrupt (with error bit) on interrupt signal received. - * - * Errors (with error bit) from: f_fss_apply_delimit() - * Errors (with error bit) from: firewall_operate_process_rules() - * Errors (with error bit) from: fll_fss_extended_read() - * - * @see f_fss_apply_delimit() - * @see firewall_operate_process_rules() - * @see fll_fss_extended_read() - */ -#ifndef _di_firewall_operate_load_rules_ - extern void firewall_operate_load_rules(firewall_main_t * const main); -#endif // _di_firewall_operate_load_rules_ - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _firewall_operate_load_h diff --git a/level_3/firewall/c/main/operate/process.c b/level_3/firewall/c/main/operate/process.c index d0f5378..9496f5a 100644 --- a/level_3/firewall/c/main/operate/process.c +++ b/level_3/firewall/c/main/operate/process.c @@ -24,14 +24,14 @@ extern "C" { f_number_unsigned_t repeat = 2; f_string_static_t tool = firewall_tool_iptables_s; - f_ranges_t * const rule_objects = &data->main.rule_objects; - f_rangess_t * const rule_contents = data->main.rule_contents; + f_ranges_t * const rule_objects = &main->data.rule_objects; + f_rangess_t * const rule_contents = &main->data.rule_contents; if (!(main->data.is & firewall_data_is_global_e)) { - if (data->devices.array[data->main.device].used) { + if (main->setting.devices.array[main->data.device].used) { main->cache.device.used = 0; - main->setting.state.status = f_string_dynamic_append(data->devices.array[data->main.device], &main->cache.device); + main->setting.state.status = f_string_dynamic_append(main->setting.devices.array[main->data.device], &main->cache.device); if (F_status_is_error(main->setting.state.status)) return; } } @@ -52,7 +52,7 @@ extern "C" { main->cache.ip_list.used = 0; // Process chain rule. - if (f_compare_dynamic_partial_string(firewall_chain_s.string, data->main.buffer, firewall_chain_s.used, rule_objects->array[i]) == F_equal_to) { + if (f_compare_dynamic_partial_string(firewall_chain_s.string, main->data.buffer, firewall_chain_s.used, rule_objects->array[i]) == F_equal_to) { if (chain == firewall_chain_custom_e) { // Custom chains can only apply to themselves, so silently ignore chain commands specified within a custom chain. @@ -64,22 +64,22 @@ extern "C" { if (rule_contents->array[i].used != 1) { valid = F_false; } - else if (f_compare_dynamic_partial_string(firewall_chain_input_s.string, data->main.buffer, firewall_chain_input_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_chain_input_s.string, main->data.buffer, firewall_chain_input_s.used, rule_contents->array[i].array[0]) == F_equal_to) { chain = firewall_chain_input_e; } - else if (f_compare_dynamic_partial_string(firewall_chain_output_s.string, data->main.buffer, firewall_chain_output_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_chain_output_s.string, main->data.buffer, firewall_chain_output_s.used, rule_contents->array[i].array[0]) == F_equal_to) { chain = firewall_chain_output_e; } - else if (f_compare_dynamic_partial_string(firewall_chain_forward_s.string, data->main.buffer, firewall_chain_forward_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_chain_forward_s.string, main->data.buffer, firewall_chain_forward_s.used, rule_contents->array[i].array[0]) == F_equal_to) { chain = firewall_chain_forward_e; } - else if (f_compare_dynamic_partial_string(firewall_chain_postrouting_s.string, data->main.buffer, firewall_chain_postrouting_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_chain_postrouting_s.string, main->data.buffer, firewall_chain_postrouting_s.used, rule_contents->array[i].array[0]) == F_equal_to) { chain = firewall_chain_postrouting_e; } - else if (f_compare_dynamic_partial_string(firewall_chain_prerouting_s.string, data->main.buffer, firewall_chain_prerouting_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_chain_prerouting_s.string, main->data.buffer, firewall_chain_prerouting_s.used, rule_contents->array[i].array[0]) == F_equal_to) { chain = firewall_chain_prerouting_e; } - else if (f_compare_dynamic_partial_string(firewall_chain_none_s.string, data->main.buffer, firewall_chain_none_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_chain_none_s.string, main->data.buffer, firewall_chain_none_s.used, rule_contents->array[i].array[0]) == F_equal_to) { chain = firewall_chain_none_e; } else { @@ -90,17 +90,17 @@ extern "C" { } // Process direction rule - else if (f_compare_dynamic_partial_string(firewall_direction_s.string, data->main.buffer, firewall_direction_s.used, rule_objects->array[i]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_direction_s.string, main->data.buffer, firewall_direction_s.used, rule_objects->array[i]) == F_equal_to) { if (rule_contents->array[i].used != 1) { valid = F_false; } - else if (f_compare_dynamic_partial_string(firewall_direction_input_s.string, data->main.buffer, firewall_direction_input_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_direction_input_s.string, main->data.buffer, firewall_direction_input_s.used, rule_contents->array[i].array[0]) == F_equal_to) { direction = firewall_direction_input_e; } - else if (f_compare_dynamic_partial_string(firewall_direction_output_s.string, data->main.buffer, firewall_direction_output_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_direction_output_s.string, main->data.buffer, firewall_direction_output_s.used, rule_contents->array[i].array[0]) == F_equal_to) { direction = firewall_direction_output_e; } - else if (f_compare_dynamic_partial_string(firewall_direction_none_s.string, data->main.buffer, firewall_direction_none_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_direction_none_s.string, main->data.buffer, firewall_direction_none_s.used, rule_contents->array[i].array[0]) == F_equal_to) { direction = firewall_direction_none_e; } else { @@ -113,18 +113,18 @@ extern "C" { } // Process device rule. - else if (f_compare_dynamic_partial_string(firewall_device_s.string, data->main.buffer, firewall_device_s.used, rule_objects->array[i]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_device_s.string, main->data.buffer, firewall_device_s.used, rule_objects->array[i]) == F_equal_to) { if (rule_contents->array[i].used != 1) { valid = F_false; } - else if (f_compare_dynamic_partial_string(firewall_device_all_s.string, data->main.buffer, firewall_device_all_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_device_all_s.string, main->data.buffer, firewall_device_all_s.used, rule_contents->array[i].array[0]) == F_equal_to) { main->cache.device.used = 0; continue; } - else if (f_compare_dynamic_partial_string(firewall_device_this_s.string, data->main.buffer, firewall_device_this_s.used, rule_contents->array[i].array[0]) == F_equal_to) { - if (data->devices.array[data->main.device].used) { - main->setting.state.status = f_string_dynamic_append(data->devices.array[data->main.device], &main->cache.device); + else if (f_compare_dynamic_partial_string(firewall_device_this_s.string, main->data.buffer, firewall_device_this_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + if (main->setting.devices.array[main->data.device].used) { + main->setting.state.status = f_string_dynamic_append(main->setting.devices.array[main->data.device], &main->cache.device); } else { main->cache.device.used = 0; @@ -138,7 +138,7 @@ extern "C" { if (valid) { main->cache.device.used = 0; - main->setting.state.status = f_string_dynamic_partial_append(data->main.buffer, rule_contents->array[i].array[0], &main->cache.device); + main->setting.state.status = f_string_dynamic_partial_append(main->data.buffer, rule_contents->array[i].array[0], &main->cache.device); if (F_status_is_error(main->setting.state.status)) return; continue; @@ -146,20 +146,20 @@ extern "C" { } // Process action rule. - else if (f_compare_dynamic_partial_string(firewall_action_s.string, data->main.buffer, firewall_action_s.used, rule_objects->array[i]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_action_s.string, main->data.buffer, firewall_action_s.used, rule_objects->array[i]) == F_equal_to) { if (rule_contents->array[i].used != 1) { valid = F_false; } - else if (f_compare_dynamic_partial_string(firewall_action_append_s.string, data->main.buffer, firewall_action_append_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_action_append_s.string, main->data.buffer, firewall_action_append_s.used, rule_contents->array[i].array[0]) == F_equal_to) { action = firewall_action_append_e; } - else if (f_compare_dynamic_partial_string(firewall_action_insert_s.string, data->main.buffer, firewall_action_insert_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_action_insert_s.string, main->data.buffer, firewall_action_insert_s.used, rule_contents->array[i].array[0]) == F_equal_to) { action = firewall_action_insert_e; } - else if (f_compare_dynamic_partial_string(firewall_action_policy_s.string, data->main.buffer, firewall_action_policy_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_action_policy_s.string, main->data.buffer, firewall_action_policy_s.used, rule_contents->array[i].array[0]) == F_equal_to) { action = firewall_action_policy_e; } - else if (f_compare_dynamic_partial_string(firewall_action_none_s.string, data->main.buffer, firewall_action_none_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_action_none_s.string, main->data.buffer, firewall_action_none_s.used, rule_contents->array[i].array[0]) == F_equal_to) { action = firewall_action_none_e; } else { @@ -170,31 +170,31 @@ extern "C" { } // Process ip_list rule. - else if (f_compare_dynamic_partial_string(firewall_ip_list.string, data->main.buffer, firewall_ip_list.used, rule_objects->array[i]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_ip_list.string, main->data.buffer, firewall_ip_list.used, rule_objects->array[i]) == F_equal_to) { is_ip_list = F_true; - if (f_compare_dynamic_partial_string(firewall_ip_list_source_s.string, data->main.buffer, firewall_ip_list_source_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + if (f_compare_dynamic_partial_string(firewall_ip_list_source_s.string, main->data.buffer, firewall_ip_list_source_s.used, rule_contents->array[i].array[0]) == F_equal_to) { ip_list_direction = F_false; } - else if (f_compare_dynamic_partial_string(firewall_ip_list_destination_s.string, data->main.buffer, firewall_ip_list_destination_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_ip_list_destination_s.string, main->data.buffer, firewall_ip_list_destination_s.used, rule_contents->array[i].array[0]) == F_equal_to) { ip_list_direction = F_true; } else { valid = F_false; } } - else if (f_compare_dynamic_partial_string(firewall_protocol_s.string, data->main.buffer, firewall_protocol_s.used, rule_objects->array[i]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_protocol_s.string, main->data.buffer, firewall_protocol_s.used, rule_objects->array[i]) == F_equal_to) { if (rule_contents->array[i].used != 1) { valid = F_false; } else { - if (f_compare_dynamic_partial_string(firewall_protocol_none_s.string, data->main.buffer, firewall_protocol_none_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + if (f_compare_dynamic_partial_string(firewall_protocol_none_s.string, main->data.buffer, firewall_protocol_none_s.used, rule_contents->array[i].array[0]) == F_equal_to) { use_protocol = F_false; } else if (rule_contents->array[i].array[0].start <= rule_contents->array[i].array[0].stop) { main->cache.protocol.used = 0; - main->setting.state.status = f_string_dynamic_partial_append(data->main.buffer, rule_contents->array[i].array[0], &main->cache.protocol); + main->setting.state.status = f_string_dynamic_partial_append(main->data.buffer, rule_contents->array[i].array[0], &main->cache.protocol); if (F_status_is_error(main->setting.state.status)) return; use_protocol = F_true; @@ -208,20 +208,20 @@ extern "C" { } // Process tool rule. - else if (f_compare_dynamic_partial_string(firewall_tool_s.string, data->main.buffer, firewall_tool_s.used, rule_objects->array[i]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_tool_s.string, main->data.buffer, firewall_tool_s.used, rule_objects->array[i]) == F_equal_to) { if (rule_contents->array[i].used != 1) { valid = F_false; } else { - if (f_compare_dynamic_partial_string(firewall_tool_iptables_s.string, data->main.buffer, firewall_tool_iptables_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + if (f_compare_dynamic_partial_string(firewall_tool_iptables_s.string, main->data.buffer, firewall_tool_iptables_s.used, rule_contents->array[i].array[0]) == F_equal_to) { tool = firewall_tool_iptables_s; repeat = 1; } - else if (f_compare_dynamic_partial_string(firewall_tool_ip6tables_s.string, data->main.buffer, firewall_tool_ip6tables_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_tool_ip6tables_s.string, main->data.buffer, firewall_tool_ip6tables_s.used, rule_contents->array[i].array[0]) == F_equal_to) { tool = firewall_tool_ip6tables_s; repeat = 1; } - else if (f_compare_dynamic_partial_string(firewall_tool_ip46tables_s.string, data->main.buffer, firewall_tool_ip46tables_s.used, rule_contents->array[i].array[0]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_tool_ip46tables_s.string, main->data.buffer, firewall_tool_ip46tables_s.used, rule_contents->array[i].array[0]) == F_equal_to) { tool = firewall_tool_iptables_s; repeat = 2; } @@ -234,7 +234,7 @@ extern "C" { } // If the remaining rule does not match as firewall_rule_s, then it is an invalid rule. - else if (f_compare_dynamic_partial_string(firewall_rule_s.string, data->main.buffer, firewall_rule_s.used, rule_objects->array[i]) == F_equal_to) { + else if (f_compare_dynamic_partial_string(firewall_rule_s.string, main->data.buffer, firewall_rule_s.used, rule_objects->array[i]) == F_equal_to) { firewall_print_warning_object_invalid_missing_line(&main->program.warning, i, main->data.buffer, main->data.rule_objects.array[i]); continue; @@ -253,7 +253,7 @@ extern "C" { // First add the program name. main->cache.arguments.used = 0; - main->setting.state.status = f_memory_array_increase(firewall_default_allocation_step_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); + main->setting.state.status = f_memory_array_increase(firewall_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); if (F_status_is_error(main->setting.state.status)) return; if (tool.string == firewall_tool_ip46tables_s.string) { @@ -262,19 +262,19 @@ extern "C" { // Process the action when a non-none chain is specified. if (chain != firewall_chain_none_e && action != firewall_action_none_e) { - main->setting.state.status = f_memory_array_increase(firewall_default_allocation_step_d, sizeof(f_string_dynamic_t), (void **) &arguments.array, &arguments.used, &arguments.size); + main->setting.state.status = f_memory_array_increase(firewall_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); if (F_status_is_error(main->setting.state.status)) return; main->cache.arguments.array[main->cache.arguments.used].used = 0; if (action == firewall_action_append_e) { - main->setting.state.status = f_string_dynamic_append(firewall_action_append_command_s, &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_append(firewall_action_append_operation_s, &main->cache.arguments.array[main->cache.arguments.used]); } else if (action == firewall_action_insert_e) { - main->setting.state.status = f_string_dynamic_append(firewall_action_insert_command_s, &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_append(firewall_action_insert_operation_s, &main->cache.arguments.array[main->cache.arguments.used]); } else if (action == firewall_action_policy_e) { - main->setting.state.status = f_string_dynamic_append(firewall_action_policy_command_s, &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_append(firewall_action_policy_operation_s, &main->cache.arguments.array[main->cache.arguments.used]); } if (F_status_is_error(main->setting.state.status)) return; @@ -282,7 +282,7 @@ extern "C" { if (action == firewall_action_append_e || action == firewall_action_insert_e || action == firewall_action_policy_e) { ++main->cache.arguments.used; - main->setting.state.status = f_memory_array_increase(firewall_default_allocation_step_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); + main->setting.state.status = f_memory_array_increase(firewall_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); if (F_status_is_error(main->setting.state.status)) return; main->cache.arguments.array[main->cache.arguments.used].used = 0; @@ -290,7 +290,7 @@ extern "C" { // Process the chain, which is required by the action. if (chain == firewall_chain_custom_e) { - main->setting.state.status = f_string_dynamic_append(data->chains.array[data->main.chain_ids.array[main->data.chain]], &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_append(main->setting.chains.array[main->data.chain_ids.array[main->data.chain]], &main->cache.arguments.array[main->cache.arguments.used]); } else if (chain == firewall_chain_forward_e) { main->setting.state.status = f_string_dynamic_append(firewall_chain_forward_s, &main->cache.arguments.array[main->cache.arguments.used]); @@ -320,21 +320,21 @@ extern "C" { } // Add the device if and only if a non-none direction is specified. - if (device.used && (direction == firewall_direction_input_e || direction == firewall_direction_output_e)) { - if (f_compare_dynamic_partial_string(firewall_device_all_s.string, data->main.buffer, firewall_device_all_s.used, rule_contents->array[i].array[0]) == F_equal_to_not) { - main->setting.state.status = f_memory_array_increase(firewall_default_allocation_step_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); + if (main->cache.device.used && (direction == firewall_direction_input_e || direction == firewall_direction_output_e)) { + if (f_compare_dynamic_partial_string(firewall_device_all_s.string, main->data.buffer, firewall_device_all_s.used, rule_contents->array[i].array[0]) == F_equal_to_not) { + main->setting.state.status = f_memory_array_increase(firewall_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); if (F_status_is_error(main->setting.state.status)) return; main->cache.arguments.array[main->cache.arguments.used].used = 0; if (direction == firewall_direction_input_e) { - main->setting.state.status = f_string_dynamic_append(firewall_device_input_command_s, &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_append(firewall_device_input_operation_s, &main->cache.arguments.array[main->cache.arguments.used]); if (F_status_is_error(main->setting.state.status)) return; ++main->cache.arguments.used; } else if (direction == firewall_direction_output_e) { - main->setting.state.status = f_string_dynamic_append(firewall_device_output_command_s, &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_append(firewall_device_output_operation_s, &main->cache.arguments.array[main->cache.arguments.used]); if (F_status_is_error(main->setting.state.status)) return; ++main->cache.arguments.used; @@ -343,7 +343,7 @@ extern "C" { // Add the device. if (main->cache.device.used) { - main->setting.state.status = f_memory_array_increase(firewall_default_allocation_step_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); + main->setting.state.status = f_memory_array_increase(firewall_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); if (F_status_is_error(main->setting.state.status)) return; main->cache.arguments.array[main->cache.arguments.used].used = 0; @@ -356,18 +356,18 @@ extern "C" { } if (use_protocol) { - main->setting.state.status = f_memory_array_increase(firewall_default_allocation_step_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); + main->setting.state.status = f_memory_array_increase(firewall_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); if (F_status_is_error(main->setting.state.status)) return; main->cache.arguments.array[main->cache.arguments.used].used = 0; - main->setting.state.status = f_string_dynamic_append(firewall_protocol_command_s, &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_append(firewall_protocol_operation_s, &main->cache.arguments.array[main->cache.arguments.used]); if (F_status_is_error(main->setting.state.status)) return; ++main->cache.arguments.used; if (main->cache.protocol.used) { - main->setting.state.status = f_memory_array_increase(firewall_default_allocation_step_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); + main->setting.state.status = f_memory_array_increase(firewall_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &main->cache.arguments.array, &main->cache.arguments.used, &main->cache.arguments.size); if (F_status_is_error(main->setting.state.status)) return; main->cache.arguments.array[main->cache.arguments.used].used = 0; @@ -389,9 +389,9 @@ extern "C" { ++j; if (rule_contents->array[i].array[j].start <= rule_contents->array[i].array[j].stop) { - ip_list.used = 0; + main->cache.ip_list.used = 0; - main->setting.state.status = f_string_dynamic_partial_append(data->main.buffer, rule_contents->array[i].array[j], &ip_list); + main->setting.state.status = f_string_dynamic_partial_append(main->data.buffer, rule_contents->array[i].array[j], &main->cache.ip_list); if (F_status_is_error(main->setting.state.status)) { @@ -414,7 +414,7 @@ extern "C" { if (rule_contents->array[i].array[j].start <= rule_contents->array[i].array[j].stop) { main->cache.arguments.array[main->cache.arguments.used].used = 0; - main->setting.state.status = f_string_dynamic_partial_append(data->main.buffer, rule_contents->array[i].array[j], &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_partial_append(main->data.buffer, rule_contents->array[i].array[j], &main->cache.arguments.array[main->cache.arguments.used]); if (F_status_is_error(main->setting.state.status)) return; ++main->cache.arguments.used; @@ -430,15 +430,16 @@ extern "C" { // Now execute the generated commands. if (main->cache.arguments.used > 1) { if (is_ip_list) { - data->cache.path_file_specific.used = 0; - data->cache.local_buffer.used = 0; - data->cache.basic_objects.used = 0; - data->cache.basic_contents.used = 0; + main->cache.basic_objects.used = 0; + main->cache.basic_contents.used = 0; + main->cache.buffer.used = 0; + main->cache.delimits.used = 0; + main->cache.path_file_specific.used = 0; - main->setting.state.status = f_string_dynamic_append(firewall_network_path_s, &data->cache.path_file_specific); + main->setting.state.status = f_string_dynamic_append(firewall_network_path_s, &main->cache.path_file_specific); if (F_status_is_error_not(main->setting.state.status)) { - main->setting.state.status = f_string_dynamic_append(main->cache.ip_list, &data->cache.path_file_specific); + main->setting.state.status = f_string_dynamic_append(main->cache.ip_list, &main->cache.path_file_specific); } if (F_status_is_error(main->setting.state.status)) { @@ -447,44 +448,51 @@ extern "C" { return; } - main->setting.state.status = f_file_open(data->cache.path_file_specific, 0, &data->cache.file); + main->setting.state.status = f_file_open(main->cache.path_file_specific, 0, &main->cache.file); if (F_status_is_error(main->setting.state.status)) { - firewall_print_error_file(&main->program.error, macro_firewall_f(f_file_open), data->cache.path_file_specific, f_file_operation_open_s, fll_error_file_type_file_e); + firewall_print_error_file(&main->program.error, macro_firewall_f(f_file_open), main->cache.path_file_specific, f_file_operation_open_s, fll_error_file_type_file_e); - f_file_stream_close(&data->cache.file); + f_file_stream_close(&main->cache.file); return; } - main->setting.state.status = f_file_read(data->cache.file, &data->cache.local_buffer); + main->setting.state.status = f_file_read(main->cache.file, &main->cache.buffer); - f_file_stream_close(&data->cache.file); + f_file_stream_close(&main->cache.file); if (F_status_is_error(main->setting.state.status)) { - firewall_print_error_file(&main->program.error, macro_firewall_f(f_file_read), data->cache.path_file_specific, f_file_operation_read_s, fll_error_file_type_file_e); + firewall_print_error_file(&main->program.error, macro_firewall_f(f_file_read), main->cache.path_file_specific, f_file_operation_read_s, fll_error_file_type_file_e); return; } - main->data.delimits.used = 0; - main->data.range.start = 0; - main->data.range.stop = data->cache.local_buffer.used - 1; + main->cache.delimits.used = 0; - main->setting.state.status = fll_fss_basic_read(data->cache.local_buffer, main->setting.state.status, &input, &data->cache.basic_objects, &data->cache.basic_contents, 0, &main->data.delimits, 0); + if (main->cache.buffer.used) { + main->data.range.start = 0; + main->data.range.stop = main->cache.buffer.used - 1; + } + else { + main->data.range.start = 1; + main->data.range.stop = 0; + } + + fll_fss_basic_read(main->cache.buffer, &main->data.range, &main->cache.basic_objects, &main->cache.basic_contents, 0, &main->cache.delimits, 0, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_data_not_eos || F_status_set_fine(main->setting.state.status) == F_data_not || F_status_set_fine(main->setting.state.status) == F_data_not_stop) { // Empty files are to be silently ignored. } else { - firewall_print_error_file(&main->program.error, macro_firewall_f(fll_fss_basic_read), data->cache.path_file_specific, f_file_operation_read_s, fll_error_file_type_file_e); + firewall_print_error_file(&main->program.error, macro_firewall_f(fll_fss_basic_read), main->cache.path_file_specific, f_file_operation_read_s, fll_error_file_type_file_e); return; } } - main->setting.state.status = f_fss_apply_delimit(main->setting.state, main->data.delimits, &data->cache.local_buffer); + f_fss_apply_delimit(main->cache.delimits, &main->cache.buffer, &main->setting.state); if (F_status_is_error(main->setting.state.status)) { firewall_print_error(&main->program.error, macro_firewall_f(f_fss_apply_delimit)); @@ -512,13 +520,13 @@ extern "C" { ++main->cache.arguments.used; // The ip_list file contains objects and no content, all objects are what matter an nothing else. - for (at = 0; at < data->cache.basic_objects.used; ++at) { + for (at = 0; at < main->cache.basic_objects.used; ++at) { if (firewall_signal_check(main)) return; main->cache.arguments.array[main->cache.arguments.used].used = 0; - main->setting.state.status = f_string_dynamic_partial_append(data->cache.local_buffer, data->cache.basic_objects.array[at], &main->cache.arguments.array[main->cache.arguments.used]); + main->setting.state.status = f_string_dynamic_partial_append(main->cache.buffer, main->cache.basic_objects.array[at], &main->cache.arguments.array[main->cache.arguments.used]); if (F_status_is_error(main->setting.state.status)) { firewall_print_error(&main->program.error, macro_firewall_f(f_string_dynamic_partial_append)); @@ -528,12 +536,12 @@ extern "C" { ++main->cache.arguments.used; - firewall_print_debug_tool(data->main->warning, tool, main->cache.arguments); + firewall_print_debug_tool(&main->program.warning, tool, main->cache.arguments); main->setting.state.status = fll_execute_program(tool, main->cache.arguments, 0, 0, (void *) &return_code); if (main->setting.state.status == F_child) { - data->main->child = return_code; + main->program.child = return_code; return; } @@ -543,7 +551,7 @@ extern "C" { if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_failure) { - firewall_print_error_operation(main->program->error, tool, main->cache.arguments); + firewall_print_error_operation(&main->program.error, tool, main->cache.arguments); } else { firewall_print_error(&main->program.error, macro_firewall_f(fll_execute_program)); @@ -560,19 +568,19 @@ extern "C" { if (F_status_set_fine(main->setting.state.status) == F_failure || F_status_set_fine(main->setting.state.status) == F_parameter) return; } else { - firewall_print_debug_tool(data->main->warning, tool, main->cache.arguments); + firewall_print_debug_tool(&main->program.warning, tool, main->cache.arguments); main->setting.state.status = fll_execute_program(tool, main->cache.arguments, 0, 0, (void *) &return_code); if (main->setting.state.status == F_child) { - data->main->child = return_code; + main->program.child = return_code; return; } if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_failure) { - firewall_print_error_operation(main->program->error, tool, main->cache.arguments); + firewall_print_error_operation(&main->program.error, tool, main->cache.arguments); } else { firewall_print_error(&main->program.error, macro_firewall_f(fll_execute_program)); diff --git a/level_3/firewall/c/main/print/debug.c b/level_3/firewall/c/main/print/debug.c index d310f21..c380486 100644 --- a/level_3/firewall/c/main/print/debug.c +++ b/level_3/firewall/c/main/print/debug.c @@ -5,21 +5,24 @@ extern "C" { #endif #ifndef _di_firewall_print_debug_tool_ - void firewall_print_debug_tool(const fl_print_t output, const f_string_static_t tool, const f_string_statics_t arguments) { + f_status_t firewall_print_debug_tool(fl_print_t * const print, const f_string_static_t tool, const f_string_statics_t arguments) { - if (output.verbosity != f_console_verbosity_debug_e) return; + if (!print) return F_status_set_error(F_output_not); + if (print->verbosity != f_console_verbosity_debug_e) return F_output_not; - f_file_stream_lock(output.to); + f_file_stream_lock(print->to); - fl_print_format("%[%r", output.to, output.context, tool); + fl_print_format("%[%Q", print->to, print->context, tool); for (f_number_unsigned_t i = 0; i < arguments.used; ++i) { - fl_print_format(" %Q", output.to, arguments.array[i]); + fl_print_format(" %Q", print->to, arguments.array[i]); } // for - fl_print_format("%]%r", output.to, output.context, f_string_eol_s); + fl_print_format("%]%r", print->to, print->context, f_string_eol_s); - f_file_stream_unlock(output.to); + f_file_stream_unlock(print->to); + + return F_okay; } #endif // _di_firewall_print_debug_tool_ diff --git a/level_3/firewall/c/main/print/debug.h b/level_3/firewall/c/main/print/debug.h index 84a8f0a..fd45e4f 100644 --- a/level_3/firewall/c/main/print/debug.h +++ b/level_3/firewall/c/main/print/debug.h @@ -19,15 +19,24 @@ extern "C" { /** * Print debug information about tool execution. * - * @param output - * The output to print to. + * @param print + * The output structure to print to. + * + * This does not alter print.custom.setting.state.status. * @param tool - * The iptables tool. + * The name of the function associated with the error. * @param arguments - * The arguments passed to the tool. + * The name of the file, if this error is assocaited with a file. + * Otherwise, set file.used to 0 to not have an file related error message. + * + * @return + * F_okay on success. + * F_output_not on success, but no printing is performed. + * + * F_output_not (with error bit) if setting is NULL. */ #ifndef _di_firewall_print_debug_tool_ - extern void firewall_print_debug_tool(const fl_print_t output, const f_string_static_t tool, const f_string_statics_t arguments); + extern f_status_t firewall_print_debug_tool(fl_print_t * const print, const f_string_static_t tool, const f_string_statics_t arguments); #endif // _di_firewall_print_debug_tool_ #ifdef __cplusplus diff --git a/level_3/firewall/c/main/print/error.c b/level_3/firewall/c/main/print/error.c index edea597..2222001 100644 --- a/level_3/firewall/c/main/print/error.c +++ b/level_3/firewall/c/main/print/error.c @@ -31,7 +31,7 @@ extern "C" { #endif // _di_firewall_print_error_file_ #ifndef _di_firewall_print_error_file_empty_ - f_status_t firewall_print_error_file_empty(fl_print_t * const print, const f_string_static_t section, const f_string_static_t file) { + f_status_t firewall_print_error_file_empty(fl_print_t * const print, const f_string_static_t file) { if (!print) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -39,7 +39,7 @@ extern "C" { f_file_stream_lock(print->to); fl_print_format("%[%QNo relevant data is found within the file '%]", print->to, print->context, print->prefix, print->context); - fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, operation, print->notable); + fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, file, print->notable); fl_print_format(f_string_format_sentence_end_quote_s.string, print->to, print->set->error, print->set->error, f_string_eol_s); f_file_stream_unlock(print->to); @@ -66,17 +66,15 @@ extern "C" { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; - firewall_main_t * const main = (firewall_main_t *) print->custom); - - if (output.verbosity == f_console_verbosity_quiet_e) return; + firewall_main_t * const main = (firewall_main_t *) print->custom; f_file_stream_lock(print->to); if (F_status_set_fine(main->setting.state.status) == F_memory_not) { - fl_print_format("%[%QOut of memory while performing requested %r operation:%]", print->to, print->context, output.prefix, tool, print->context); + fl_print_format("%[%QOut of memory while performing requested %r operation:%]", print->to, print->context, print->prefix, tool, print->context); } else { - fl_print_format("%[%QFailed to perform requested %r operation:%]", print->to, print->context, output.prefix, tool, print->context); + fl_print_format("%[%QFailed to perform requested %r operation:%]", print->to, print->context, print->prefix, tool, print->context); } fl_print_format("%r %[%Q", print->to, f_string_eol_s, print->context, tool); @@ -101,11 +99,11 @@ extern "C" { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not; - firewall_main_t * const main = (firewall_main_t *) print->custom); + firewall_main_t * const main = (firewall_main_t *) print->custom; f_file_stream_lock(print->to); - fl_print_format("%[%QFailed to perform%] ", print->to, print->context, output.prefix); + fl_print_format("%[%QFailed to perform%] ", print->to, print->context, print->prefix); fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, operation, print->notable); fl_print_format(" %[request because the%] ", print->to, print->context, print->prefix, print->context); fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, operation, print->notable); @@ -131,41 +129,20 @@ extern "C" { } #endif // _di_firewall_print_error_operation_specified_not_ -#ifndef _di_firewall_print_error_directory_read_ - f_status_t firewall_print_error_directory_read(fl_print_t * const print, const f_string_static_t ) { - - if (!print) return F_status_set_error(F_output_not); - if (print->verbosity < f_console_verbosity_error_e) return F_output_not; - - f_file_stream_lock(print->to); - - fl_print_format("%[%QFailed to read the device directory '%]", print->to, print->context, print->prefix, print->context); - fl_print_format(firewall_operation_show_s.string, print->to, print->notable, option, print->notable); - fl_print_format(" %[option '%]", print->to, print->context, print->prefix, print->context); - fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, option, print->notable); - fl_print_format("%[' is not known.%]%r", print->to, print->context, print->context, f_string_eol_s); - - f_file_stream_unlock(print->to); - f_file_stream_flush(print->to); - - return F_okay; - } -#endif // _di_firewall_print_error_directory_read_ - #ifndef _di_firewall_print_error_unhandled_ - void firewall_print_error_unhandled(const fl_print_t print, const f_string_t function, const f_string_static_t file) { + f_status_t firewall_print_error_unhandled(fl_print_t * const print, const f_string_t function, const f_string_static_t file) { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; - f_file_stream_lock(print->to); + firewall_main_t * const main = (firewall_main_t *) print->custom; - firewall_main_t * const main = (firewall_main_t *) print->custom); + f_file_stream_lock(print->to); fl_print_format("%[%QAn unhandled error (%]", print->to, f_string_eol_s, print->context, print->prefix, print->context); fl_print_format(f_string_format_ui_single_s.string, print->to, print->notable, F_status_set_fine(main->setting.state.status), print->notable); fl_print_format("%[) has occurred while calling%] ", print->to, print->context, print->prefix, print->context); - fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, operation, print->notable); + fl_print_format(f_string_format_S_single_s.string, print->to, print->notable, function, print->notable); if (file.used) { fl_print_format("%[() for the file%] ", print->to, print->context, print->prefix, print->context); diff --git a/level_3/firewall/c/main/print/error.h b/level_3/firewall/c/main/print/error.h index 0316e01..f42d843 100644 --- a/level_3/firewall/c/main/print/error.h +++ b/level_3/firewall/c/main/print/error.h @@ -196,7 +196,7 @@ extern "C" { * F_output_not (with error bit) if setting is NULL. */ #ifndef _di_firewall_print_error_unhandled_ - extern f_status_t firewall_print_error_unhandled(const fl_print_t print, const f_string_t function, const f_string_static_t file); + extern f_status_t firewall_print_error_unhandled(fl_print_t * const print, const f_string_t function, const f_string_static_t file); #endif // _di_firewall_print_error_unhandled_ #ifdef __cplusplus diff --git a/level_3/firewall/c/main/print/message.c b/level_3/firewall/c/main/print/message.c index 71507b9..7c6bf35 100644 --- a/level_3/firewall/c/main/print/message.c +++ b/level_3/firewall/c/main/print/message.c @@ -27,7 +27,7 @@ extern "C" { f_print_dynamic_raw(f_string_eol_s, print->to); - fll_program_print_help_usage(print, firewall_program_name_s, firewall_program_help_commands_s); + fll_program_print_help_usage(print, firewall_program_name_s, firewall_program_help_parameters_s); f_file_stream_flush(print->to); f_file_stream_unlock(print->to); @@ -44,13 +44,13 @@ extern "C" { f_file_stream_lock(print->to); if (left.used) { - fl_print_format("%[%Q%] ", print->to, print->set.standout, left, print->set.standout); + fl_print_format("%[%Q%] ", print->to, print->set->standout, left, print->set->standout); } - fll_print_format("%[%Q%]", print->to, print->set.standout, print->set.standout, print->set.title, print->set.title, print->set.standout, print->set.standout, f_string_eol_s); + fll_print_format("%[%Q%]", print->to, print->set->standout, print->set->standout, print->set->title, print->set->title, print->set->standout, print->set->standout, f_string_eol_s); if (left.used) { - fl_print_format(" %[%Q%]", print->to, print->set.standout, right, print->set.standout); + fl_print_format(" %[%Q%]", print->to, print->set->standout, right, print->set->standout); } f_print_dynamic_raw(f_string_eol_s, print->to); diff --git a/level_3/firewall/data/build/settings b/level_3/firewall/data/build/settings index 781b406..6029200 100644 --- a/level_3/firewall/data/build/settings +++ b/level_3/firewall/data/build/settings @@ -38,14 +38,14 @@ build_libraries-monolithic -lfll build_sources_library main/common.c main/common/define.c main/common/enumeration.c main/common/print.c main/common/string.c main/common/type.c build_sources_library main/print/debug.c main/print/error.c main/print/message.c main/print/warning.c -build_sources_library main/operate.c main/operate/buffer.c main/operate/create.c main/operate/default.c main/operate/delete.c main/operate/load.c main/operate/process.c +build_sources_library main/operate.c main/operate/buffer.c main/operate/create.c main/operate/default.c main/operate/delete.c main/operate/process.c build_sources_library main/firewall.c main/signal.c main/thread.c build_sources_program main/main.c build_sources_headers main/common.h main/common/define.h main/common/enumeration.h main/common/print.h main/common/string.h main/common/type.h build_sources_headers main/print/debug.h main/print/error.h main/print/message.h main/print/warning.h -build_sources_headers main/operate.h main/operate/buffer.h main/operate/create.h main/operate/default.h main/operate/delete.h main/operate/load.h main/operate/process.h +build_sources_headers main/operate.h main/operate/buffer.h main/operate/create.h main/operate/default.h main/operate/delete.h main/operate/process.h build_sources_headers main/firewall.h main/operate.h main/signal.h main/thread.h build_sources_documentation man