Store the numeric port on the set.
The received headers are not being fully printed yet.
Make sure file close warnings are printed on file close failure when receiving.
return;
}
+ if (main->program.parameters.array[kt_tacocat_parameter_headers_e].result & f_console_result_found_d) {
+ main->setting.flag |= kt_tacocat_main_flag_headers_d;
+ }
+ else {
+ main->setting.flag &= ~kt_tacocat_main_flag_headers_d;
+ }
+
// Only process these when needed to avoid unnecessary operations.
if (main->callback.setting_load_send_receive && !(main->setting.flag & (kt_tacocat_main_flag_copyright_d | kt_tacocat_main_flag_version_d |kt_tacocat_main_flag_help_d))) {
main->callback.setting_load_send_receive(arguments, main);
f_status_t failed = F_okay;
struct hostent host;
f_network_family_ip_t family = f_network_family_ip_t_initialize;
- f_number_unsigned_t port = 0;
f_string_static_t address = f_string_static_t_initialize;
for (uint8_t i = 0; i < 2; ++i) {
sets[i]->array[j].packet.size = 0;
sets[i]->array[j].packet.payload.start = 1;
sets[i]->array[j].packet.payload.stop = 0;
+ sets[i]->array[j].port = 0;
sets[i]->array[j].retry = 0;
sets[i]->array[j].status = F_okay;
sets[i]->array[j].range.start = 1;
sets[i]->array[j].socket.form = f_socket_address_form_generic_e;
}
- kt_tacocat_setting_load_address_port_extract(main, range_ip, &address, &port);
+ kt_tacocat_setting_load_address_port_extract(main, range_ip, &address, &sets[i]->array[j].port);
if (F_status_is_error(main->setting.state.status)) {
if (F_status_set_fine(main->setting.state.status) == F_parameter) {
}
// Fail forward if port number is not supported by the system.
- if (port != (in_port_t) port) {
- kt_tacocat_print_warning_port_number_overflow(&main->program.warning, main->program.parameters.arguments.array[index], port);
+ if (sets[i]->array[j].port != (in_port_t) sets[i]->array[j].port) {
+ kt_tacocat_print_warning_port_number_overflow(&main->program.warning, main->program.parameters.arguments.array[index], sets[i]->array[j].port);
- port = 0;
+ sets[i]->array[j].port = 0;
}
if (host.h_addrtype) {
main->setting.state.status = f_network_from_ip_string(address, &family);
macro_kt_tacocat_handle_load_send_receive_error_continue_2();
+
+ // @todo port here.
}
else {
main->setting.state.status = f_network_from_ip_name(address, &host);
if (host.h_addrtype == f_socket_address_family_inet4_e) {
sets[i]->array[j].socket.domain = f_socket_protocol_family_inet4_e;
sets[i]->array[j].socket.address.inet4.sin_family = f_socket_address_family_inet4_e;
- sets[i]->array[j].socket.address.inet4.sin_port = htons((in_port_t) port);
+ sets[i]->array[j].socket.address.inet4.sin_port = htons((in_port_t) sets[i]->array[j].port);
sets[i]->array[j].socket.address.inet4.sin_addr.s_addr = family.address.v4.s_addr;
}
else if (host.h_addrtype == f_socket_address_family_inet6_e) {
sets[i]->array[j].socket.domain = f_socket_protocol_family_inet6_e;
sets[i]->array[j].socket.address.inet4.sin_family = f_socket_address_family_inet6_e;
- sets[i]->array[j].socket.address.inet6.sin6_port = htons((in_port_t) port);
+ sets[i]->array[j].socket.address.inet6.sin6_port = htons((in_port_t) sets[i]->array[j].port);
sets[i]->array[j].socket.address.inet6.sin6_addr = family.address.v6;
}
}
* kt_tacocat_main_flag_*_d:
* - none: No flags set.
* - copyright: Print copyright.
+ * - headers: Print headers on send or receive.
+ * - help: Print help.
* - max_buffer: When set, a maximum buffer on receive is enforced.
* - receive: The address or socket to receive from is specified.
* - resolve_classic: Follow the classic Domain Name Resolution method.
* - resolve_kevux: Follow the Kevux Domain Name Resolution method.
* - send: The address or socket send to is specified.
- * - help: Print help.
* - version: Print version.
* - version_copyright_help: A helper flag representing version, copyright, and help flag bits being set.
*
#ifndef _di_kt_tacocat_main_flag_d_
#define kt_tacocat_main_flag_none_d 0x0
#define kt_tacocat_main_flag_copyright_d 0x1
- #define kt_tacocat_main_flag_help_d 0x2
- #define kt_tacocat_main_flag_max_buffer_d 0x4
- #define kt_tacocat_main_flag_receive_d 0x8
- #define kt_tacocat_main_flag_resolve_classic_d 0x10
- #define kt_tacocat_main_flag_resolve_kevux_d 0x20
- #define kt_tacocat_main_flag_resolve_d 0x40
+ #define kt_tacocat_main_flag_headers_d 0x2
+ #define kt_tacocat_main_flag_help_d 0x4
+ #define kt_tacocat_main_flag_max_buffer_d 0x8
+ #define kt_tacocat_main_flag_receive_d 0x10
+ #define kt_tacocat_main_flag_resolve_classic_d 0x20
+ #define kt_tacocat_main_flag_resolve_kevux_d 0x40
#define kt_tacocat_main_flag_send_d 0x80
#define kt_tacocat_main_flag_version_d 0x100
- #define kt_tacocat_main_flag_version_copyright_help_d 0x103
+ #define kt_tacocat_main_flag_version_copyright_help_d 0x105
#endif // _di_kt_tacocat_main_flag_d_
/**
kt_tacocat_parameter_verbosity_debug_e,
kt_tacocat_parameter_version_e,
+ kt_tacocat_parameter_headers_e,
kt_tacocat_parameter_interval_e,
kt_tacocat_parameter_max_buffer_e,
kt_tacocat_parameter_receive_e,
{ \
macro_fll_program_console_parameter_standard_initialize, \
\
- macro_f_console_parameter_t_initialize_3(kt_tacocat_short_interval_s, kt_tacocat_long_interval_s, 1, f_console_flag_normal_d), \
+ macro_f_console_parameter_t_initialize_3(kt_tacocat_short_headers_s, kt_tacocat_long_headers_s, 0, f_console_flag_normal_d), \
+ macro_f_console_parameter_t_initialize_3(kt_tacocat_short_interval_s, kt_tacocat_long_interval_s, 1, f_console_flag_normal_d), \
macro_f_console_parameter_t_initialize_3(kt_tacocat_short_max_buffer_s, kt_tacocat_long_max_buffer_s, 1, f_console_flag_normal_d), \
- macro_f_console_parameter_t_initialize_3(kt_tacocat_short_receive_s, kt_tacocat_long_receive_s, 2, f_console_flag_normal_d), \
- macro_f_console_parameter_t_initialize_3(kt_tacocat_short_resolve_s, kt_tacocat_long_resolve_s, 1, f_console_flag_normal_d), \
- macro_f_console_parameter_t_initialize_3(kt_tacocat_short_send_s, kt_tacocat_long_send_s, 2, f_console_flag_normal_d), \
+ macro_f_console_parameter_t_initialize_3(kt_tacocat_short_receive_s, kt_tacocat_long_receive_s, 2, f_console_flag_normal_d), \
+ macro_f_console_parameter_t_initialize_3(kt_tacocat_short_resolve_s, kt_tacocat_long_resolve_s, 1, f_console_flag_normal_d), \
+ macro_f_console_parameter_t_initialize_3(kt_tacocat_short_send_s, kt_tacocat_long_send_s, 2, f_console_flag_normal_d), \
}
- #define kt_tacocat_parameter_total_d (f_console_parameter_state_type_total_d + 5)
+ #define kt_tacocat_parameter_total_d (f_console_parameter_state_type_total_d + 6)
#endif // _di_kt_tacocat_parameter_e_
/**
const f_string_static_t kt_tacocat_network_or_socket_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_network_or_socket_s, 0, KT_TACOCAT_network_or_socket_s_length);
const f_string_static_t kt_tacocat_next_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_next_s, 0, KT_TACOCAT_next_s_length);
const f_string_static_t kt_tacocat_receive_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_receive_s, 0, KT_TACOCAT_receive_s_length);
+ const f_string_static_t kt_tacocat_receive_done_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_receive_done_s, 0, KT_TACOCAT_receive_done_s_length);
const f_string_static_t kt_tacocat_resend_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_resend_s, 0, KT_TACOCAT_resend_s_length);
const f_string_static_t kt_tacocat_send_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_s, 0, KT_TACOCAT_send_s_length);
const f_string_static_t kt_tacocat_send_build_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_send_build_s, 0, KT_TACOCAT_send_build_s_length);
#endif // _di_kt_tacocat_s_
#ifndef _di_kt_tacocat_parameter_s_
+ const f_string_static_t kt_tacocat_short_headers_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_short_headers_s, 0, KT_TACOCAT_short_headers_s_length);
const f_string_static_t kt_tacocat_short_interval_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_short_interval_s, 0, KT_TACOCAT_short_interval_s_length);
const f_string_static_t kt_tacocat_short_max_buffer_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_short_max_buffer_s, 0, KT_TACOCAT_short_max_buffer_s_length);
const f_string_static_t kt_tacocat_short_receive_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_short_receive_s, 0, KT_TACOCAT_short_receive_s_length);
const f_string_static_t kt_tacocat_short_resolve_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_short_resolve_s, 0, KT_TACOCAT_short_resolve_s_length);
const f_string_static_t kt_tacocat_short_send_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_short_send_s, 0, KT_TACOCAT_short_send_s_length);
+ const f_string_static_t kt_tacocat_long_headers_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_long_headers_s, 0, KT_TACOCAT_long_headers_s_length);
const f_string_static_t kt_tacocat_long_interval_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_long_interval_s, 0, KT_TACOCAT_long_interval_s_length);
const f_string_static_t kt_tacocat_long_max_buffer_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_long_max_buffer_s, 0, KT_TACOCAT_long_max_buffer_s_length);
const f_string_static_t kt_tacocat_long_receive_s = macro_f_string_static_t_initialize_1(KT_TACOCAT_long_receive_s, 0, KT_TACOCAT_long_receive_s_length);
#define KT_TACOCAT_network_or_socket_s "network / socket"
#define KT_TACOCAT_next_s "next"
#define KT_TACOCAT_receive_s "receive"
+ #define KT_TACOCAT_receive_done_s "receive done"
#define KT_TACOCAT_resend_s "resend"
#define KT_TACOCAT_send_s "send"
#define KT_TACOCAT_send_build_s "send build"
#define KT_TACOCAT_network_or_socket_s_length 16
#define KT_TACOCAT_next_s_length 4
#define KT_TACOCAT_receive_s_length 7
+ #define KT_TACOCAT_receive_done_s_length 12
#define KT_TACOCAT_resend_s_length 6
#define KT_TACOCAT_send_s_length 4
#define KT_TACOCAT_send_build_s_length 19
extern const f_string_static_t kt_tacocat_network_or_socket_s;
extern const f_string_static_t kt_tacocat_next_s;
extern const f_string_static_t kt_tacocat_receive_s;
+ extern const f_string_static_t kt_tacocat_receive_done_s;
extern const f_string_static_t kt_tacocat_resend_s;
extern const f_string_static_t kt_tacocat_send_s;
extern const f_string_static_t kt_tacocat_send_build_s;
* The main program parameters.
*/
#ifndef _di_kt_tacocat_parameter_s_
+ #define KT_TACOCAT_short_headers_s "H"
#define KT_TACOCAT_short_interval_s "I"
#define KT_TACOCAT_short_max_buffer_s "M"
#define KT_TACOCAT_short_receive_s "r"
#define KT_TACOCAT_short_resolve_s "R"
#define KT_TACOCAT_short_send_s "s"
+ #define KT_TACOCAT_long_headers_s "headers"
#define KT_TACOCAT_long_interval_s "interval"
#define KT_TACOCAT_long_max_buffer_s "max_buffer"
#define KT_TACOCAT_long_receive_s "receive"
#define KT_TACOCAT_long_resolve_s "resolve"
#define KT_TACOCAT_long_send_s "send"
+ #define KT_TACOCAT_short_headers_s_length 1
#define KT_TACOCAT_short_interval_s_length 1
#define KT_TACOCAT_short_max_buffer_s_length 1
#define KT_TACOCAT_short_receive_s_length 1
#define KT_TACOCAT_short_resolve_s_length 1
#define KT_TACOCAT_short_send_s_length 1
+ #define KT_TACOCAT_long_headers_s_length 7
#define KT_TACOCAT_long_interval_s_length 8
#define KT_TACOCAT_long_max_buffer_s_length 10
#define KT_TACOCAT_long_receive_s_length 7
#define KT_TACOCAT_long_resolve_s_length 7
#define KT_TACOCAT_long_send_s_length 4
+ extern const f_string_static_t kt_tacocat_short_headers_s;
extern const f_string_static_t kt_tacocat_short_interval_s;
extern const f_string_static_t kt_tacocat_short_max_buffer_s;
extern const f_string_static_t kt_tacocat_short_receive_s;
extern const f_string_static_t kt_tacocat_short_resolve_s;
extern const f_string_static_t kt_tacocat_short_send_s;
+ extern const f_string_static_t kt_tacocat_long_headers_s;
extern const f_string_static_t kt_tacocat_long_interval_s;
extern const f_string_static_t kt_tacocat_long_max_buffer_s;
extern const f_string_static_t kt_tacocat_long_receive_s;
* step: The current step the socket set is operating under.
* retry: The current number of retries performed.
* part: The current active part number.
+ * port: The current port number for the socket.
*
* file: The file structure.
* socket: Socket structure.
uint16_t step;
uint16_t retry;
f_number_unsigned_t part;
+ f_number_unsigned_t port;
f_file_t file;
f_socket_t socket;
0, \
0, \
0, \
+ 0, \
f_file_t_initialize, \
f_socket_t_initialize, \
f_status_t_initialize, \
0, \
0, \
0, \
+ 0, \
f_file_t_initialize, \
f_poll_t_initialize, \
f_socket_t_initialize, \
0, \
0, \
0, \
+ 0, \
f_file_t_initialize, \
f_poll_t_initialize, \
f_socket_t_initialize, \
return;
}
+ set->abstruses.used = 0;
+
+ 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)) {
+ kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, direction, set->network, set->status, set->name);
+
+ 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, F_status_debug_source_d, direction, set->network, set->status, set->name);
-
set->status = set->state.status;
+ kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, direction, set->network, set->status, set->name);
+
return;
}
for (; i < set->objects_header.used; ++i) {
- for (j = 0; j < 9; ++j) {
+ for (j = 0; j < kt_tacocat_packet_headers_d; ++j) {
if (f_compare_dynamic_partial_string(headers[j].string, set->buffer, headers[j].used, set->objects_header.array[i]) == F_equal_to) {
// Require Content to exist.
if (!set->contents_header.array[i].used) {
+ if (set->abstruses.array[j].value.type == f_abstruse_dynamic_e) {
+ }
+
set->abstruses.array[j].value.type = f_abstruse_none_e;
- break;
+ continue;
}
+ // @todo All of these need to be stored in another location so that re-assignments doesn't cause problems with dynamic allocation. Allocate these and make them available.
+ /*set->abstruses.array[i].value.type = f_abstruse_dynamic_e;
+ set->abstruses.array[i].value.is.a_dynamic.used = 0;
+
+ set->status = f_string_dynamic_partial_append(set->buffer, range, &set->abstruses.array[i].value.is.a_dynamic);
+
+ if (F_status_is_error(set->status)) {
+ kt_tacocat_print_error_on(&main->program.error, F_status_debug_source_d, direction, set->network, set->status, set->name);
+
+ return;
+ }*/
+
set->abstruses.array[j].value.type = f_abstruse_range_e;
set->abstruses.array[j].value.is.a_range = set->contents_header.array[i].array[0];
}
extern "C" {
#endif
+#ifndef _di_kt_tacocat_print_message_headers_
+ f_status_t kt_tacocat_print_message_headers(fl_print_t * const print, const kt_tacocat_socket_set_t set, const uint8_t sent) {
+
+ if (!print) return F_status_set_error(F_output_not);
+ if (print->verbosity < f_console_verbosity_normal_e) return F_output_not;
+
+ f_file_stream_lock(print->to);
+
+ fl_print_format(sent ? "Headers Sent to " : "Headers Received from ", print->to, f_string_eol_s);
+ fl_print_format(f_string_format_Q_single_s.string, print->to, print->set->notable, set.network, print->set->notable);
+
+ if (set.port) {
+ fl_print_format(" (port %[%ul%])", print->to, print->set->notable, set.port, print->set->notable);
+ }
+
+ fl_print_format(":%r", print->to, f_string_eol_s);
+
+ for (f_number_unsigned_t i = 0; i < set.abstruses.used; ++i) {
+
+ if (set.abstruses.array[i].value.type == f_abstruse_unsigned_e) {
+ fl_print_format(" - %Q: %ul%r", print->to, set.abstruses.array[i].key, set.abstruses.array[i].value.is.a_unsigned, f_string_eol_s);
+ }
+ else if (set.abstruses.array[i].value.type == f_abstruse_dynamic_e) {
+ fl_print_format(" - %Q: %Q%r", print->to, set.abstruses.array[i].key, set.abstruses.array[i].value.is.a_dynamic, f_string_eol_s);
+ }
+ } // for
+
+ fl_print_format("%r", print->to, f_string_eol_s);
+
+ f_file_stream_unlock(print->to);
+ }
+#endif // _di_kt_tacocat_print_message_headers_
+
#ifndef _di_kt_tacocat_print_message_help_
f_status_t kt_tacocat_print_message_help(fl_print_t * const print, const f_color_context_t context) {
f_print_dynamic_raw(f_string_eol_s, print->to);
+ fll_program_print_help_option(print, kt_tacocat_short_headers_s, kt_tacocat_long_headers_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Print the headers on send or on receive.");
fll_program_print_help_option(print, kt_tacocat_short_interval_s, kt_tacocat_long_interval_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Specify a custom poll interval in milliseconds to use.");
fll_program_print_help_option(print, kt_tacocat_short_max_buffer_s, kt_tacocat_long_max_buffer_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, "Specify a maximum buffer size to allow (in bytes) when receiving packets.");
fll_program_print_help_option(print, kt_tacocat_short_receive_s, kt_tacocat_long_receive_s, f_console_symbol_short_normal_s, f_console_symbol_long_normal_s, " Specify an address or socket file to listen to and a file to write to.");
#endif
/**
+ * Print message showing the sent or received headers.
+ *
+ * @param print
+ * The output structure to print to.
+ *
+ * This locks, uses, and unlocks the file stream.
+ *
+ * Must not be NULL.
+ *
+ * This does not alter print.custom.setting.state.status.
+ * @param set
+ * The socket set relating to the message.
+ * @param sent
+ * If TRUE, then these are sent headers.
+ * If FALSE, then these are received headers.
+ *
+ * @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_kt_tacocat_print_message_headers_
+ extern f_status_t kt_tacocat_print_message_headers(fl_print_t * const print, const kt_tacocat_socket_set_t set, const uint8_t sent);
+#endif // _di_kt_tacocat_print_message_headers_
+
+/**
* Print help.
*
* @param print
kt_tacocat_print_message_receive_operation_complete(&main->program.message, *set);
- f_file_close(&set->file);
+ if (main->setting.flag & kt_tacocat_main_flag_headers_d) {
+ kt_tacocat_print_message_headers(&main->program.message, *set, F_false);
+ }
+
+ set->status = f_file_close(&set->file);
+
+ if (F_status_is_error(set->status)) {
+ kt_tacocat_print_warning_on_file(&main->program.warning, F_status_debug_source_d, kt_tacocat_receive_done_s, set->network, set->status, set->name, f_file_operation_close_s);
+ }
set->step = 0;
set->status = F_okay;
set->packet.payload.stop = 0;
set->part = 0;
set->parts.used = 0;
+ set->port = 0;
set->flag = 0;
// For writes, the id_data is the same as the id.
//@todo send done packet.
+ if (main->setting.flag & kt_tacocat_main_flag_headers_d) {
+ kt_tacocat_print_message_headers(&main->program.message, *set, F_true);
+ }
+
set->status = f_file_close(&set->file);
if (F_status_is_error(set->status)) {