From 99229d75187a823aa60aa06d0749a4c433c25de2 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 3 Jan 2024 20:08:17 -0600 Subject: [PATCH] Progress: Further work in TacocaT. Begin processing header. --- sources/c/tacocat/main/common.c | 24 +-- sources/c/tacocat/main/common/define.h | 18 +- sources/c/tacocat/main/common/enumeration.h | 14 +- sources/c/tacocat/main/common/print.c | 2 + sources/c/tacocat/main/common/print.h | 2 + sources/c/tacocat/main/common/type.c | 50 +++++- sources/c/tacocat/main/common/type.h | 68 +++++++- sources/c/tacocat/main/receive.c | 260 +++++++++++++++++++++++++--- sources/c/tacocat/main/receive.h | 110 ++++++++++++ sources/c/tacocat/main/send.c | 1 + sources/c/tacocat/main/tacocat.h | 1 + 11 files changed, 497 insertions(+), 53 deletions(-) diff --git a/sources/c/tacocat/main/common.c b/sources/c/tacocat/main/common.c index 522a32b..d978c82 100644 --- a/sources/c/tacocat/main/common.c +++ b/sources/c/tacocat/main/common.c @@ -18,14 +18,14 @@ extern "C" { // Identify and pocess first/last parameters. if (main->program.parameters.array[kt_tacocat_parameter_line_first_no_e].result & f_console_result_found_e) { - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_print_first_e; + main->setting.flag &= ~kt_tacocat_main_flag_print_first_e; } else { main->setting.flag |= kt_tacocat_main_flag_print_first_e; } if (main->program.parameters.array[kt_tacocat_parameter_line_last_no_e].result & f_console_result_found_e) { - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_print_last_e; + main->setting.flag &= ~kt_tacocat_main_flag_print_last_e; } else { main->setting.flag |= kt_tacocat_main_flag_print_last_e; @@ -86,21 +86,21 @@ extern "C" { main->setting.flag |= kt_tacocat_main_flag_help_e; } else { - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_help_e; + main->setting.flag &= ~kt_tacocat_main_flag_help_e; } if (main->program.parameters.array[kt_tacocat_parameter_version_e].result & f_console_result_found_e) { main->setting.flag |= kt_tacocat_main_flag_version_e; } else { - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_version_e; + main->setting.flag &= ~kt_tacocat_main_flag_version_e; } if (main->program.parameters.array[kt_tacocat_parameter_copyright_e].result & f_console_result_found_e) { main->setting.flag |= kt_tacocat_main_flag_copyright_e; } else { - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_copyright_e; + main->setting.flag &= ~kt_tacocat_main_flag_copyright_e; } if (main->program.parameters.array[kt_tacocat_parameter_resolve_e].result & f_console_result_found_e) { @@ -114,11 +114,11 @@ extern "C" { index = main->program.parameters.array[kt_tacocat_parameter_resolve_e].values.array[main->program.parameters.array[kt_tacocat_parameter_resolve_e].values.used - 1]; if (f_compare_dynamic(main->program.parameters.arguments.array[index], kt_tacocat_classic_s) == F_equal_to) { - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_resolve_kevux_e; + main->setting.flag &= ~kt_tacocat_main_flag_resolve_kevux_e; main->setting.flag |= kt_tacocat_main_flag_resolve_classic_e; } else if (f_compare_dynamic(main->program.parameters.arguments.array[index], kt_tacocat_kevux_s) == F_equal_to) { - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_resolve_classic_e; + main->setting.flag &= ~kt_tacocat_main_flag_resolve_classic_e; main->setting.flag |= kt_tacocat_main_flag_resolve_kevux_e; } else { @@ -131,10 +131,10 @@ extern "C" { } else { #ifdef _kt_resolve_default_kevux_ - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_resolve_classic_e; + main->setting.flag &= ~kt_tacocat_main_flag_resolve_classic_e; main->setting.flag |= kt_tacocat_main_flag_resolve_kevux_e; #else - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_resolve_kevux_e; + main->setting.flag &= ~kt_tacocat_main_flag_resolve_kevux_e; main->setting.flag |= kt_tacocat_main_flag_resolve_classic_e; #endif // _kt_resolve_default_kevux_ } @@ -200,7 +200,7 @@ extern "C" { else if (main->setting.state.status == F_number_negative) { if (number == 1) { main->setting.max_buffer = 0; - main->setting.flag -= main->setting.flag & kt_tacocat_main_flag_max_buffer_e; + main->setting.flag &= ~kt_tacocat_main_flag_max_buffer_e; } else { main->setting.state.status = F_status_set_error(F_parameter); @@ -620,7 +620,7 @@ extern "C" { } // for } else if (main->program.parameters.array[parameters[i]].result & f_console_result_found_e) { - main->setting.flag -= main->setting.flag & flags[i]; + main->setting.flag &= ~flags[i]; main->setting.state.status = F_status_set_error(F_parameter); macro_setting_load_print_first(); @@ -634,7 +634,7 @@ extern "C" { continue; } else { - main->setting.flag -= main->setting.flag & flags[i]; + main->setting.flag &= ~flags[i]; } } // for diff --git a/sources/c/tacocat/main/common/define.h b/sources/c/tacocat/main/common/define.h index 1e59c7f..ae75031 100644 --- a/sources/c/tacocat/main/common/define.h +++ b/sources/c/tacocat/main/common/define.h @@ -66,7 +66,7 @@ extern "C" { #define kt_tacocat_allocation_large_d 0x800 #define kt_tacocat_allocation_small_d 0x80 - #define kt_tacocat_block_size_d 0xffff + #define kt_tacocat_block_size_d 0xffff // @todo set this to something small like 0xff to easily test and design sending and receiving multiple parts. #define kt_tacocat_block_size_receive_d kt_tacocat_block_size_d #define kt_tacocat_block_size_send_d kt_tacocat_block_size_d @@ -113,6 +113,9 @@ extern "C" { * Intended to be used for handling an error during the receive process while not processing within flag kt_tacocat_socket_flag_receive_control_e. * The parameter id_data and is set to 0 to disable and is otherwise an address pointer. * + * macro_kt_receive_process_handle_error_exit_2: + * A version of macro_kt_receive_process_handle_error_exit_1 that uses a void return statement. + * * macro_kt_receive_process_begin_handle_error_exit_1: * Intended to be used for handling an error during the receive process while processing within flag kt_tacocat_socket_flag_receive_control_e. * @@ -180,6 +183,19 @@ extern "C" { return F_done_not; \ } + #define macro_kt_receive_process_handle_error_exit_2(main, method, network, status, name, flag, id_data) \ + if (F_status_is_error(status)) { \ + kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(method), kt_tacocat_receive_s, network, status, name); \ + \ + if (id_data) { \ + f_file_close_id(id_data); \ + } \ + \ + flag = 0; \ + \ + return; \ + } + #define macro_kt_receive_process_begin_handle_error_exit_1(main, method, network, status, name, flag) \ if (F_status_is_error(status)) { \ kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(method), kt_tacocat_receive_s, network, status, name); \ diff --git a/sources/c/tacocat/main/common/enumeration.h b/sources/c/tacocat/main/common/enumeration.h index 6f042ad..7a74040 100644 --- a/sources/c/tacocat/main/common/enumeration.h +++ b/sources/c/tacocat/main/common/enumeration.h @@ -132,9 +132,10 @@ extern "C" { * kt_tacocat_socket_flag_receive_*_e: * - none: No flags set. * - control: Reading and processing the Control block and Size block. - * - packet: Reading and processing the rest of the Packet block (the Header and Payload). - * - find: Find the Header block and everything else up until the Payload block. - * - check: Process and check the loaded Payload block, processing the Header block. + * - packet: Reading and processing the rest of the Packet block (the Header and Payload sections). + * - find: Find the Header section and everything else up until the Payload section. + * - extract: Process the loaded data, extracting the Header and Signature sections. + * - check: Check the loaded data, doing size checks, interpreting the status, and performing any signature checks. * - write: Save the loaded Payload block to the file (write to the file). * - done: Done processing file. */ @@ -144,9 +145,10 @@ extern "C" { kt_tacocat_socket_flag_receive_control_e = 0x1, kt_tacocat_socket_flag_receive_packet_e = 0x2, kt_tacocat_socket_flag_receive_find_e = 0x4, - kt_tacocat_socket_flag_receive_check_e = 0x8, - kt_tacocat_socket_flag_receive_write_e = 0x10, - kt_tacocat_socket_flag_receive_done_e = 0x20, + kt_tacocat_socket_flag_receive_extract_e = 0x8, + kt_tacocat_socket_flag_receive_check_e = 0x10, + kt_tacocat_socket_flag_receive_write_e = 0x20, + kt_tacocat_socket_flag_receive_done_e = 0x40, }; // enum #endif // _di_kt_tacocat_socket_flag_receive_e_ diff --git a/sources/c/tacocat/main/common/print.c b/sources/c/tacocat/main/common/print.c index 0cb7f20..405f9eb 100644 --- a/sources/c/tacocat/main/common/print.c +++ b/sources/c/tacocat/main/common/print.c @@ -40,6 +40,8 @@ extern "C" { "fl_conversion_dynamic_partial_to_unsigned_detect", "fl_conversion_dynamic_to_unsigned_detect", "fl_fss_payload_header_map", + "fll_fss_extended_read", + "fll_fss_payload_read", "fll_program_parameter_process_context", "fll_program_parameter_process_verbosity", "kt_tacocat_process_socket_set_error_has", diff --git a/sources/c/tacocat/main/common/print.h b/sources/c/tacocat/main/common/print.h index b157657..08c5acf 100644 --- a/sources/c/tacocat/main/common/print.h +++ b/sources/c/tacocat/main/common/print.h @@ -73,6 +73,8 @@ extern "C" { kt_tacocat_f_fl_conversion_dynamic_partial_to_unsigned_detect_e, kt_tacocat_f_fl_conversion_dynamic_to_unsigned_detect_e, kt_tacocat_f_fl_fss_payload_header_map_e, + kt_tacocat_f_fll_fss_extended_read_e, + kt_tacocat_f_fll_fss_payload_read_e, kt_tacocat_f_fll_program_parameter_process_context_e, kt_tacocat_f_fll_program_parameter_process_verbosity_e, kt_tacocat_f_kt_tacocat_process_socket_set_error_has_e, diff --git a/sources/c/tacocat/main/common/type.c b/sources/c/tacocat/main/common/type.c index 8c5ba3d..1b0ccf0 100644 --- a/sources/c/tacocat/main/common/type.c +++ b/sources/c/tacocat/main/common/type.c @@ -54,18 +54,66 @@ extern "C" { f_memory_array_resize(0, sizeof(f_range_t), (void **) &array[i].objects.array, &array[i].objects.used, &array[i].objects.size); } + if (array[i].objects_header.size) { + f_memory_array_resize(0, sizeof(f_range_t), (void **) &array[i].objects_header.array, &array[i].objects_header.used, &array[i].objects_header.size); + } + + if (array[i].objects_signature.size) { + f_memory_array_resize(0, sizeof(f_range_t), (void **) &array[i].objects_signature.array, &array[i].objects_signature.used, &array[i].objects_signature.size); + } + if (array[i].contents.size) { f_memory_arrays_resize(0, sizeof(f_range_t), (void **) &array[i].contents.array, &array[i].contents.used, &array[i].contents.size, &f_rangess_delete_callback); } + if (array[i].contents_header.size) { + f_memory_arrays_resize(0, sizeof(f_range_t), (void **) &array[i].contents_header.array, &array[i].contents_header.used, &array[i].contents_header.size, &f_rangess_delete_callback); + } + + if (array[i].contents_signature.size) { + f_memory_arrays_resize(0, sizeof(f_range_t), (void **) &array[i].contents_signature.array, &array[i].contents_signature.used, &array[i].contents_signature.size, &f_rangess_delete_callback); + } + if (array[i].objects_delimits.size) { f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &array[i].objects_delimits.array, &array[i].objects_delimits.used, &array[i].objects_delimits.size); } - if (array[i].objects_delimits.size) { + if (array[i].objects_delimits_header.size) { + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &array[i].objects_delimits_header.array, &array[i].objects_delimits_header.used, &array[i].objects_delimits_header.size); + } + + if (array[i].objects_delimits_signature.size) { + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &array[i].objects_delimits_signature.array, &array[i].objects_delimits_signature.used, &array[i].objects_delimits_signature.size); + } + + if (array[i].contents_delimits.size) { f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &array[i].contents_delimits.array, &array[i].contents_delimits.used, &array[i].contents_delimits.size); } + if (array[i].contents_delimits_header.size) { + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &array[i].contents_delimits_header.array, &array[i].contents_delimits_header.used, &array[i].contents_delimits_header.size); + } + + if (array[i].contents_delimits_signature.size) { + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &array[i].contents_delimits_signature.array, &array[i].contents_delimits_signature.used, &array[i].contents_delimits_signature.size); + } + + if (array[i].objects_quoted_header.size) { + f_memory_array_resize(0, sizeof(uint8_t), (void **) &array[i].objects_quoted_header.array, &array[i].objects_quoted_header.used, &array[i].objects_quoted_header.size); + } + + if (array[i].objects_quoted_signature.size) { + f_memory_array_resize(0, sizeof(uint8_t), (void **) &array[i].objects_quoted_signature.array, &array[i].objects_quoted_signature.used, &array[i].objects_quoted_signature.size); + } + + if (array[i].contents_quoted_header.size) { + f_memory_arrays_resize(0, sizeof(uint8_t), (void **) &array[i].contents_quoted_header.array, &array[i].contents_quoted_header.used, &array[i].contents_quoted_header.size, &f_uint8ss_delete_callback); + } + + if (array[i].contents_quoted_signature.size) { + f_memory_arrays_resize(0, sizeof(uint8_t), (void **) &array[i].contents_quoted_signature.array, &array[i].contents_quoted_signature.used, &array[i].contents_quoted_signature.size, &f_uint8ss_delete_callback); + } + if (array[i].comments.size) { f_memory_array_resize(0, sizeof(f_range_t), (void **) &array[i].comments.array, &array[i].comments.used, &array[i].comments.size); } diff --git a/sources/c/tacocat/main/common/type.h b/sources/c/tacocat/main/common/type.h index 25ae0d1..27b96f8 100644 --- a/sources/c/tacocat/main/common/type.h +++ b/sources/c/tacocat/main/common/type.h @@ -29,13 +29,25 @@ extern "C" { * socket: Socket structure. * status: The status of the socket operations. * - * range: A generic range, often used for FSS processing. - * objects: An array of FSS Objects. - * contents: An array of FSS Contents. - * objects_delimits: An array of FSS Object delimits. - * contents_delimits: An array of FSS Content delimits. - * comments: An array of FSS comments. - * state: Basic state information, usually passed to the FSS functions. + * range: A generic range, often used for FSS processing. + * objects: An array of FSS Objects. + * objects_header: An array of FSS Objects, for the Header section. + * objects_signature: An array of FSS Objects, for the Signature section. + * contents: An array of FSS Contents. + * contents_header: An array of FSS Contents, for the Header section. + * contents_signature: An array of FSS Contents, for the Signature section. + * objects_delimits: An array of FSS Object delimits. + * objects_delimits_header: An array of FSS Object delimits, for the Header section. + * objects_delimits_signature: An array of FSS Object delimits, for the Signature section. + * contents_delimits: An array of FSS Content delimits. + * contents_delimits_header: An array of FSS Content delimits, for the Header section. + * contents_delimits_signature: An array of FSS Content delimits, for the Signature section. + * objects_quoted_header: An array of FSS Objects quoted flags, for the Header section. + * objects_quoted_signature: An array of FSS Objects quoted flags, for the Header section. + * contents_quoted_header: An array of FSS Content quoted flags, for the Header section. + * contents_quoted_signature: An array of FSS Content quoted flags, for the Header section. + * comments: An array of FSS comments. + * state: Basic state information, usually passed to the FSS functions. * * buffer: A buffer for sending or receiving data between clients. * cache: A cache used for various purposes, but primarily for the building of the send packet. @@ -63,9 +75,21 @@ extern "C" { f_range_t range; f_ranges_t objects; + f_ranges_t objects_header; + f_ranges_t objects_signature; f_rangess_t contents; + f_rangess_t contents_header; + f_rangess_t contents_signature; f_number_unsigneds_t objects_delimits; + f_number_unsigneds_t objects_delimits_header; + f_number_unsigneds_t objects_delimits_signature; f_number_unsigneds_t contents_delimits; + f_number_unsigneds_t contents_delimits_header; + f_number_unsigneds_t contents_delimits_signature; + f_uint8s_t objects_quoted_header; + f_uint8s_t objects_quoted_signature; + f_uint8ss_t contents_quoted_header; + f_uint8ss_t contents_quoted_signature; f_ranges_t comments; f_state_t state; @@ -94,9 +118,19 @@ extern "C" { f_status_t_initialize, \ f_range_t_initialize, \ f_ranges_t_initialize, \ + f_ranges_t_initialize, \ + f_ranges_t_initialize, \ + f_rangess_t_initialize, \ f_rangess_t_initialize, \ + f_rangess_t_initialize, \ + f_number_unsigneds_t_initialize, \ f_number_unsigneds_t_initialize, \ f_number_unsigneds_t_initialize, \ + f_number_unsigneds_t_initialize, \ + f_uint8s_t_initialize, \ + f_uint8s_t_initialize, \ + f_uint8ss_t_initialize, \ + f_uint8ss_t_initialize, \ f_ranges_t_initialize, \ f_state_t_initialize, \ f_string_dynamic_t_initialize, \ @@ -124,9 +158,19 @@ extern "C" { f_status_t_initialize, \ f_range_t_initialize, \ f_ranges_t_initialize, \ + f_ranges_t_initialize, \ + f_ranges_t_initialize, \ + f_rangess_t_initialize, \ f_rangess_t_initialize, \ + f_rangess_t_initialize, \ + f_number_unsigneds_t_initialize, \ + f_number_unsigneds_t_initialize, \ f_number_unsigneds_t_initialize, \ f_number_unsigneds_t_initialize, \ + f_uint8s_t_initialize, \ + f_uint8s_t_initialize, \ + f_uint8ss_t_initialize, \ + f_uint8ss_t_initialize, \ f_ranges_t_initialize, \ f_state_t_initialize, \ f_string_dynamic_t_initialize, \ @@ -154,9 +198,19 @@ extern "C" { f_status_t_initialize, \ f_range_t_initialize, \ f_ranges_t_initialize, \ + f_ranges_t_initialize, \ + f_ranges_t_initialize, \ f_rangess_t_initialize, \ + f_rangess_t_initialize, \ + f_rangess_t_initialize, \ + f_number_unsigneds_t_initialize, \ + f_number_unsigneds_t_initialize, \ f_number_unsigneds_t_initialize, \ f_number_unsigneds_t_initialize, \ + f_uint8s_t_initialize, \ + f_uint8s_t_initialize, \ + f_uint8ss_t_initialize, \ + f_uint8ss_t_initialize, \ f_ranges_t_initialize, \ f_state_t_initialize, \ f_string_dynamic_t_initialize, \ diff --git a/sources/c/tacocat/main/receive.c b/sources/c/tacocat/main/receive.c index 6f5fe7b..aca37d2 100644 --- a/sources/c/tacocat/main/receive.c +++ b/sources/c/tacocat/main/receive.c @@ -224,13 +224,12 @@ extern "C" { if (set->buffer.used == set->packet.size) { // The packet is fully loaded and there is no "payload" section. - set->flag = kt_tacocat_socket_flag_receive_check_e; + set->flag = kt_tacocat_socket_flag_receive_extract_e; } else { // Seek the left-most new line from the current position to ensure that the next pass potentially reads a complete line. while (set->range.start && set->buffer.string[set->range.start] != f_string_eol_s.string[0]) { - --set->range.start; } // while @@ -244,7 +243,6 @@ extern "C" { // Seek the left-most new line from the current position to ensure that the next pass potentially reads a complete line. while (set->range.start && set->buffer.string[set->range.start] != f_string_eol_s.string[0]) { - --set->range.start; } // while @@ -266,7 +264,7 @@ extern "C" { case F_data_not_eos: case F_data_not_stop: case F_fss_found_object_content_not: - set->flag = kt_tacocat_socket_flag_receive_check_e; + set->flag = kt_tacocat_socket_flag_receive_extract_e; break; @@ -278,30 +276,15 @@ extern "C" { } } - if (set->flag & kt_tacocat_socket_flag_receive_check_e) { + if (set->flag & kt_tacocat_socket_flag_receive_extract_e) { + kt_tacocat_receive_process_extract(main, set); + if (F_status_is_error(set->status)) return F_data_not; - // @todo this probably should be in a separate function, similar to how kt_tacocat_receive_process_control() is. - { - uint8_t found_not = F_true; - - for (f_number_unsigned_t i = 0; i < set->objects.used; ++i) { - - if (f_compare_dynamic_partial_string(f_fss_payload_object_header_s.string, set->buffer, f_fss_payload_object_header_s.used, set->objects.array[i]) == F_equal_to) { - // @todo walk through header, mapping it. - } - else if (f_compare_dynamic_partial_string(f_fss_payload_object_signature_s.string, set->buffer, f_fss_payload_object_signature_s.used, set->objects.array[i]) == F_equal_to) { - // @todo walk through signature, mapping it. - } - else if (f_compare_dynamic_partial_string(f_fss_payload_object_payload_s.string, set->buffer, f_fss_payload_object_payload_s.used, set->objects.array[i]) == F_equal_to) { - if (found_not) { - set->packet.payload = set->contents.array[i].array[0]; - found_not = F_false; - } - } - } // for - } + set->flag = kt_tacocat_socket_flag_receive_write_e; + } - // @todo walk through each set->objects and their respective set->contents, checking and processing the data. + if (set->flag & kt_tacocat_socket_flag_receive_check_e) { + // @todo set->flag = kt_tacocat_socket_flag_receive_write_e; } @@ -459,6 +442,231 @@ extern "C" { } #endif // _di_kt_tacocat_receive_process_control_ +#ifndef _di_kt_tacocat_receive_process_extract_ + void kt_tacocat_receive_process_extract(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set) { + + if (!main || !set) return; + + set->status = f_memory_array_increase_by(kt_tacocat_packet_headers_d, sizeof(f_abstruse_map_t), (void **) &set->abstruses.array, &set->abstruses.used, &set->abstruses.size); + + if (F_status_is_error(set->status)) { + macro_kt_receive_process_handle_error_exit_2(main, f_memory_array_increase_by, set->network, set->status, set->name, set->flag, &set->socket.id_data); + } + + // 0x1 = did not find payload, 0x2 = did not find header. + uint8_t found_not = 0x3; + + for (f_number_unsigned_t i = 0; i < set->objects.used; ++i) { + + if (f_compare_dynamic_partial_string(f_fss_payload_object_header_s.string, set->buffer, f_fss_payload_object_header_s.used, set->objects.array[i]) == F_equal_to) { + kt_tacocat_receive_process_extract_header(main, set, i); + + if (F_status_is_error(set->status)) { + ++set->retry; + + return; + } + + found_not &= ~0x2; + } + else if (f_compare_dynamic_partial_string(f_fss_payload_object_signature_s.string, set->buffer, f_fss_payload_object_signature_s.used, set->objects.array[i]) == F_equal_to) { + kt_tacocat_receive_process_extract_signature(main, set, i); + + if (F_status_is_error(set->status)) { + ++set->retry; + + return; + } + } + else if (f_compare_dynamic_partial_string(f_fss_payload_object_payload_s.string, set->buffer, f_fss_payload_object_payload_s.used, set->objects.array[i]) == F_equal_to) { + if (found_not & 0x1) { + set->packet.payload = set->contents.array[i].array[0]; + found_not &= ~0x1; + } + } + } // for + + set->status = F_okay; + } +#endif // _di_kt_tacocat_receive_process_extract_ + +#ifndef _di_kt_tacocat_receive_process_extract_header_ + void kt_tacocat_receive_process_extract_header(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set, const f_number_unsigned_t at) { + + if (!main || !set) return; + + if (set->objects.array[at].start > set->objects.array[at].stop || !set->contents.array[at].used) { + set->status = F_data_not; + + return; + } + + set->range = set->contents.array[at].array[0]; + + fll_fss_extended_read(set->buffer, &set->range, &set->objects_header, &set->contents_header, &set->objects_quoted_header, &set->contents_quoted_header, &set->objects_delimits_header, &set->contents_delimits_header, &set->state); + + if (F_status_is_error(set->state.status)) { + kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(fll_fss_extended_read), kt_tacocat_receive_s, set->network, set->status, set->name); + + set->status = set->state.status; + + return; + } + + switch (set->state.status) { + case F_okay: + case F_okay_stop: + case F_okay_eos: + break; + + default: + set->status = F_data_not; + + return; + } + + for (f_number_unsigned_t i = 0; i < set->objects_header.used; ++i) { + + // Index 0 is the status. + if (f_compare_dynamic_partial_string(f_fss_payload_object_status_s.string, set->buffer, f_fss_payload_object_status_s.used, set->objects_header.array[i]) == F_equal_to) { + + // Require Content to exist. + if (!set->contents_header.array[i].used) { + set->abstruses.array[0].value.type = f_abstruse_none_e; + + continue; + } + + set->abstruses.array[0].key = f_fss_payload_object_status_s; + set->abstruses.array[0].value.type = f_abstruse_range_e; + set->abstruses.array[0].value.is.a_range = set->contents_header.array[i].array[0]; + } + + // Index 1 is the type. + else if (f_compare_dynamic_partial_string(f_fss_payload_object_type_s.string, set->buffer, f_fss_payload_object_type_s.used, set->objects_header.array[i]) == F_equal_to) { + + // Require Content to exist. + if (!set->contents_header.array[i].used) { + set->abstruses.array[0].value.type = f_abstruse_none_e; + + continue; + } + + set->abstruses.array[0].key = f_fss_payload_object_type_s; + set->abstruses.array[0].value.type = f_abstruse_range_e; + set->abstruses.array[0].value.is.a_range = set->contents_header.array[i].array[0]; + } + + // Index 2 is the length. + else if (f_compare_dynamic_partial_string(f_fss_payload_object_length_s.string, set->buffer, f_fss_payload_object_length_s.used, set->objects_header.array[i]) == F_equal_to) { + + // Require Content to exist. + if (!set->contents_header.array[i].used) { + set->abstruses.array[1].value.type = f_abstruse_none_e; + + continue; + } + + set->abstruses.array[1].key = f_fss_payload_object_length_s; + set->abstruses.array[1].value.type = f_abstruse_range_e; + set->abstruses.array[1].value.is.a_range = set->contents_header.array[i].array[0]; + } + + // Index 3 is the part. + else if (f_compare_dynamic_partial_string(f_fss_payload_object_part_s.string, set->buffer, f_fss_payload_object_part_s.used, set->objects_header.array[i]) == F_equal_to) { + + // Require Content to exist. + if (!set->contents_header.array[i].used) { + set->abstruses.array[2].value.type = f_abstruse_none_e; + + continue; + } + + set->abstruses.array[2].key = f_fss_payload_object_part_s; + set->abstruses.array[2].value.type = f_abstruse_range_e; + set->abstruses.array[2].value.is.a_range = set->contents_header.array[i].array[0]; + } + + // Index 4 is the total number of packets (based on block size). + else if (f_compare_dynamic_partial_string(f_fss_payload_object_total_s.string, set->buffer, f_fss_payload_object_total_s.used, set->objects_header.array[i]) == F_equal_to) { + + // Require Content to exist. + if (!set->contents_header.array[i].used) { + set->abstruses.array[3].value.type = f_abstruse_none_e; + + continue; + } + + set->abstruses.array[3].key = f_fss_payload_object_total_s; + set->abstruses.array[3].value.type = f_abstruse_range_e; + set->abstruses.array[3].value.is.a_range = set->contents_header.array[i].array[0]; + } + + // Index 5 is the name (file name). + else if (f_compare_dynamic_partial_string(f_fss_payload_object_name_s.string, set->buffer, f_fss_payload_object_name_s.used, set->objects_header.array[i]) == F_equal_to) { + + // Require Content to exist. + if (!set->contents_header.array[i].used) { + set->abstruses.array[4].value.type = f_abstruse_none_e; + + continue; + } + + set->abstruses.array[4].key = f_fss_payload_object_name_s; + set->abstruses.array[4].value.type = f_abstruse_range_e; + set->abstruses.array[4].value.is.a_range = set->contents_header.array[i].array[0]; + } + + // Index 5 is the name (file name). + else if (f_compare_dynamic_partial_string(kt_tacocat_salt_s.string, set->buffer, kt_tacocat_salt_s.used, set->objects_header.array[i]) == F_equal_to) { + + // Require Content to exist. + if (!set->contents_header.array[i].used) { + set->abstruses.array[5].value.type = f_abstruse_none_e; + + continue; + } + + set->abstruses.array[5].key = kt_tacocat_salt_s; + set->abstruses.array[5].value.type = f_abstruse_range_e; + set->abstruses.array[5].value.is.a_range = set->contents_header.array[i].array[0]; + } + } // for + + set->abstruses.used = 6; + set->status = F_okay; + } +#endif // _di_kt_tacocat_receive_process_extract_header_ + +#ifndef _di_kt_tacocat_receive_process_extract_signature_ + void kt_tacocat_receive_process_extract_signature(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set, const f_number_unsigned_t at) { + + if (!main || !set) return; + + if (set->objects.array[at].start > set->objects.array[at].stop || !set->contents.array[at].used) { + set->status = F_data_not; + + return; + } + + set->range = set->contents.array[at].array[0]; + + fll_fss_extended_read(set->buffer, &set->range, &set->objects_signature, &set->contents_signature, &set->objects_quoted_header, &set->contents_quoted_header, &set->objects_delimits_signature, &set->contents_delimits_signature, &set->state); + + if (F_status_is_error(set->state.status)) { + kt_tacocat_print_error_on(&main->program.error, macro_kt_tacocat_f(fll_fss_extended_read), kt_tacocat_receive_s, set->network, set->status, set->name); + + set->status = set->state.status; + + return; + } + + // @todo maybe 7 and beyond in the abstruse shall represent signatures? + + set->status = F_okay; + } +#endif // _di_kt_tacocat_receive_process_extract_signature_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/tacocat/main/receive.h b/sources/c/tacocat/main/receive.h index d1e79ac..e75c5d2 100644 --- a/sources/c/tacocat/main/receive.h +++ b/sources/c/tacocat/main/receive.h @@ -27,8 +27,16 @@ extern "C" { * * F_interrupt (with error bit set) on interrupt received. * + * Errors (with error bit) from: f_file_close(). + * Errors (with error bit) from: f_file_poll(). + * Errors (with error bit) from: kt_tacocat_receive_process(). + * * @return * 0, always. + * + * @see f_file_close() + * @see f_file_poll() + * @see kt_tacocat_receive_process() */ #ifndef _di_kt_tacocat_receive_ extern void * kt_tacocat_receive(void * const main); @@ -60,7 +68,12 @@ extern "C" { * Errors (with error bit) from: f_socket_read_stream(). * Errors (with error bit) from: kt_tacocat_receive_process_control(). * + * @see f_file_open() + * @see f_file_write() + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() * @see f_socket_read_stream() + * @see kt_tacocat_receive_process_control() */ #ifndef _di_kt_tacocat_receive_process_ extern f_status_t kt_tacocat_receive_process(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set); @@ -83,12 +96,109 @@ extern "C" { * F_packet_too_large (with error bit) on total packet size is too large. * F_payload_too_large (with error bit) on total payload size is too large. * + * Errors (with error bit) from: f_fss_simple_packet_decode_range(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * Errors (with error bit) from: f_socket_accept(). + * Errors (with error bit) from: f_socket_read_stream(). + * + * @see f_fss_simple_packet_decode_range() + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() + * @see f_socket_accept() * @see f_socket_read_stream() */ #ifndef _di_kt_tacocat_receive_process_control_ extern void kt_tacocat_receive_process_control(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set); #endif // _di_kt_tacocat_receive_process_control_ +/** + * Process the header and signature strings, extracting the data. + * + * Another function should perform some of the validation on the header. + * @todo This other function needs to return a status code such as F_continue to designate to continue to the next iteration. + * Ideally, the flag will be set to how to continue, such as "continue loading the entire payload". + * This situation would arise when the payload needs to be validated, such as the size. + * + * @param main + * The main program and settings data. + * + * This does not alter main.setting.state.status, except on interrupt signal. + * @param set + * The socket set to process. + * Must not be NULL. + * + * This alters set.status: + * F_okay on success. + * + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: kt_tacocat_receive_process_extract_header(). + * Errors (with error bit) from: kt_tacocat_receive_process_extract_signature(). + * + * @see f_memory_array_increase_by() + * @see kt_tacocat_receive_process_extract_header() + * @see kt_tacocat_receive_process_extract_signature() + */ +#ifndef _di_kt_tacocat_receive_process_extract_ + extern void kt_tacocat_receive_process_extract(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set); +#endif // _di_kt_tacocat_receive_process_extract_ + +/** + * Extract the header strings using the given index for an Object and Content. + * + * The positions in the abstruse are hard-coded with specific representations. + * + * Index Positions: + * - 0: Status string (such as F_okay). + * - 1: Type string (type of packet). + * - 2: Length number (the length of the Payload section). + * - 3: Packet part number. + * - 4: Total packet parts number. + * - 5: Name string (file name). + * - 6: Salt string (for making packet unique, if encrypted, signed, or something similar). + * + * @param main + * The main program and settings data. + * + * This does not alter main.setting.state.status, except on interrupt signal. + * @param set + * The socket set to process. + * Must not be NULL. + * + * This alters set.status: + * F_okay on success. + * F_data_not on success, but no data to process. + * + * Errors (with error bit) from: fll_fss_extended_read(). + * @param at + * The index position representing which Object and Contents set to use. + * + * @see fll_fss_extended_read() + */ +#ifndef _di_kt_tacocat_receive_process_extract_header_ + extern void kt_tacocat_receive_process_extract_header(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set, const f_number_unsigned_t at); +#endif // _di_kt_tacocat_receive_process_extract_header_ + +/** + * Extract the signature strings using the given index for an Object and Content. + * + * @param main + * The main program and settings data. + * + * This does not alter main.setting.state.status, except on interrupt signal. + * @param set + * The socket set to process. + * Must not be NULL. + * + * This alters set.status: + * F_okay on success. + * @param at + * The index position representing which Object and Contents set to use. + */ +#ifndef _di_kt_tacocat_receive_process_extract_signature_ + extern void kt_tacocat_receive_process_extract_signature(kt_tacocat_main_t * const main, kt_tacocat_socket_set_t * const set, const f_number_unsigned_t at); +#endif // _di_kt_tacocat_receive_process_extract_signature_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/tacocat/main/send.c b/sources/c/tacocat/main/send.c index bd4bac8..bd0b521 100644 --- a/sources/c/tacocat/main/send.c +++ b/sources/c/tacocat/main/send.c @@ -178,6 +178,7 @@ extern "C" { return F_done; } + // @todo when total > 1, then this needs to build each part, incrementing part each time (every time this needs to be done, the entire header structure needs to be rebuilt until part == total - 1) (the receive code needs to also be sure to handle multiple parts). if (set->flag & kt_tacocat_socket_flag_send_size_e) { if (set->file.id == -1) { set->status = f_file_open(set->name, F_file_mode_all_r_d, &set->file); diff --git a/sources/c/tacocat/main/tacocat.h b/sources/c/tacocat/main/tacocat.h index b15ea95..1153e30 100644 --- a/sources/c/tacocat/main/tacocat.h +++ b/sources/c/tacocat/main/tacocat.h @@ -50,6 +50,7 @@ #include #include #include +#include #include #include -- 1.8.3.1