]> Kevux Git Server - kevux-tools/commitdiff
Progress: Fix dependencies and start adding network processing code.
authorKevin Day <kevin@kevux.org>
Fri, 30 Jun 2023 02:47:38 +0000 (21:47 -0500)
committerKevin Day <kevin@kevux.org>
Fri, 30 Jun 2023 02:47:38 +0000 (21:47 -0500)
Remove not needed dependencies and add needed dependencies.

This now processes socket files and network addresses for use by the program.

data/build/tacocat/dependencies
data/build/tacocat/settings
sources/c/tacocat/main/common.c
sources/c/tacocat/main/common/print.c
sources/c/tacocat/main/common/print.h
sources/c/tacocat/main/tacocat.h

index 6a0ace919bc1bef986a271d21d3bea9621541f3d..7eba949d8499e7ff0c059b7f1393ac2ac1dfe9e2 100644 (file)
@@ -8,14 +8,13 @@ f_string
 f_utf
 f_color
 f_console
-f_conversion
+f_network
 f_path
 f_pipe
 f_print
 f_signal
 f_thread
 
-fl_conversion
 fl_print
 
 fll_error
index 6ab16e581f065321b795bdffb5a0837382044bb5..b9cb1d32d94a9c59902569b751005c0454f0fe54 100644 (file)
@@ -32,7 +32,7 @@ build_indexer_arguments rcs
 build_language c
 
 build_libraries -lc
-build_libraries-individual -lfll_error -lfll_print -lfll_program -lfl_conversion -lfl_print -lf_color -lf_console -lf_conversion -lf_memory -lf_path -lf_pipe -lf_print -lf_signal -lf_string -lf_type_array -lf_utf
+build_libraries-individual -lfll_error -lfll_print -lfll_program -lfl_print -lf_color -lf_console -lf_memory -lf_network -lf_path -lf_pipe -lf_print -lf_signal -lf_string -lf_type_array -lf_utf
 build_libraries-individual_thread -lf_thread
 build_libraries-level -lfll_2 -lfll_1 -lfll_0
 build_libraries-monolithic -lfll
index 1753197f82045a4d7d9dedcd9a929f3acb5e2efe..5681d332fcd6cae994c093d68631bdd9794b782b 100644 (file)
@@ -174,7 +174,8 @@ extern "C" {
       } // for
     }
 
-    {
+    // Only process these when needed to avoid unnecessary operations.
+    if (!(main->setting.flag & (kt_tacocat_main_flag_copyright_e | kt_tacocat_main_flag_version_e |kt_tacocat_main_flag_help_e))) {
       const uint8_t parameters[] = {
         kt_tacocat_parameter_from_e,
         kt_tacocat_parameter_to_e,
@@ -190,12 +191,17 @@ extern "C" {
         &main->setting.tos,
       };
 
-      const bool const exists[] = {
+      const bool const must_exists[] = {
         F_true,
         F_false,
       };
 
       f_number_unsigned_t j = 0;
+      f_number_unsigned_t k = 0;
+      f_number_unsigned_t length = 0;
+      f_status_t failed = F_none;
+      struct hostent host;
+      f_network_family_ip_t family = f_network_family_ip_t_initialize;
 
       for (i = 0; i < 2; ++i) {
 
@@ -209,28 +215,55 @@ extern "C" {
 
             kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_string_dynamics_increase_by));
 
-            return;
+            if (F_status_is_error_not(failed)) {
+              failed = main->setting.state.status;
+            }
+
+            continue;
           }
 
           for (j = 0; j < main->program.parameters.array[parameters[i]].values.used; ++j) {
 
             index = main->program.parameters.array[parameters[i]].values.array[j];
+            strings[i]->array[j].used = 0;
 
             if (main->program.parameters.arguments.array[index].used) {
-              strings[i]->array[j].used = 0;
+              if (f_path_is_absolute(main->program.parameters.arguments.array[index]) == F_true || f_path_is_relative_current(main->program.parameters.arguments.array[index]) == F_true) {
 
-              main->setting.state.status = f_string_dynamic_append_nulless(main->program.parameters.arguments.array[index], &strings[i]->array[j]);
+                // Two is added to support a trailing NULL and a type character.
+                main->setting.state.status = f_string_dynamic_increase_by(main->program.parameters.arguments.array[index].used + 2, &strings[i]->array[j]);
 
-              if (F_status_is_error(main->setting.state.status)) {
-                macro_setting_load_print_first();
+                if (F_status_is_error(main->setting.state.status)) {
+                  macro_setting_load_print_first();
 
-                kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_string_dynamic_append_nulless));
+                  kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_string_dynamic_increase_by));
 
-                return;
-              }
+                  if (F_status_is_error_not(failed)) {
+                    failed = main->setting.state.status;
+                  }
+
+                  continue;
+                }
+
+                main->setting.state.status = f_string_dynamic_append_nulless(main->program.parameters.arguments.array[index], &strings[i]->array[j]);
 
-              if (f_path_is_absolute(strings[i]->array[j]) == F_true || f_path_is_relative_current(strings[i]->array[j]) == F_true) {
-                if (exists[i]) {
+                if (F_status_is_error(main->setting.state.status)) {
+                  macro_setting_load_print_first();
+
+                  kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_string_dynamic_append_nulless));
+
+                  if (F_status_is_error_not(failed)) {
+                    failed = main->setting.state.status;
+                  }
+
+                  continue;
+                }
+
+                // Designate this as a socket file by appending after the terminating NULL, past the used length.
+                strings[i]->array[j].string[strings[i]->array[j].used] = 0;
+                strings[i]->array[j].string[strings[i]->array[j].used + 1] = f_string_ascii_slash_forward_s.string[0];
+
+                if (must_exists[i]) {
                   main->setting.state.status = f_file_exists(strings[i]->array[j], F_true);
 
                   if (F_status_is_error(main->setting.state.status)) {
@@ -238,12 +271,118 @@ extern "C" {
 
                     kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_string_dynamic_append_nulless));
 
-                    return;
+                    if (F_status_is_error_not(failed)) {
+                      failed = main->setting.state.status;
+                    }
+
+                    continue;
                   }
                 }
               }
               else {
-                // @todo is network address, do validation.
+                memset(&host, 0, sizeof(struct hostent));
+
+                main->setting.state.status = f_network_from_ip_name(main->program.parameters.arguments.array[index], &host);
+
+                if (F_status_is_error(main->setting.state.status)) {
+                  macro_setting_load_print_first();
+
+                  // @todo provide network-specific error messages.
+                  kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_network_from_ip_name));
+
+                  if (F_status_is_error_not(failed)) {
+                    failed = main->setting.state.status;
+                  }
+
+                  continue;
+                }
+
+                if (main->setting.state.status == F_data_not || !host.h_addr_list || !host.h_addr_list[0]) {
+                  macro_setting_load_print_first();
+
+                  // @todo provide network-specific error messages for when no hosts are returned.
+                  kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_network_from_ip_name));
+
+                  if (F_status_is_error_not(failed)) {
+                    failed = main->setting.state.status;
+                  }
+
+                  continue;
+                }
+
+                // Two is added to support a trailing NULL and a type character.
+                main->setting.state.status = f_string_dynamic_increase_by(INET6_ADDRSTRLEN + 2, &strings[i]->array[j]);
+
+                if (F_status_is_error(main->setting.state.status)) {
+                  macro_setting_load_print_first();
+
+                  kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_string_dynamic_increase_by));
+
+                  if (F_status_is_error_not(failed)) {
+                    failed = main->setting.state.status;
+                  }
+
+                  continue;
+                }
+
+                // Randomly select one of the addresses when there are more than one.
+                if (host.h_addr_list[1]) {
+                  k = 2;
+
+                  while (host.h_addr_list[k++]);
+
+                  // Real randomness or security is not needed here, so fiddle with predictable but somewhat dynamic numbers.
+                  srand(main->program.pid + j + host.h_addr_list[0][0]);
+                  k = rand() % (k - 1);
+                }
+                else {
+                  k = 0;
+                }
+
+                // Two is added to support a trailing NULL and a type character.
+                main->setting.state.status = f_string_dynamic_increase_by(INET6_ADDRSTRLEN + 2, &strings[i]->array[j]);
+
+                if (F_status_is_error(main->setting.state.status)) {
+                  macro_setting_load_print_first();
+
+                  kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_string_dynamic_increase_by));
+
+                  if (F_status_is_error_not(failed)) {
+                    failed = main->setting.state.status;
+                  }
+
+                  continue;
+                }
+
+                if (host.h_addrtype == AF_INET) {
+                  family.type = f_network_family_ip_4_e;
+                  family.address.v4 = *((struct in_addr *) host.h_addr_list[k]);
+                }
+                else {
+                  family.type = f_network_family_ip_6_e;
+                  family.address.v6 = *((struct in6_addr *) host.h_addr_list[k]);
+                }
+
+                main->setting.state.status = f_network_to_ip_string(family, &strings[i]->array[j]);
+
+                if (main->setting.state.status == F_data_not || !host.h_addr_list || !host.h_addr_list[0]) {
+                  macro_setting_load_print_first();
+
+                  // @todo provide network-specific error messages for when no hosts are returned.
+                  kt_tacocat_print_error(&main->program.error, macro_kt_tacocat_f(f_network_from_ip_name));
+
+                  if (F_status_is_error_not(failed)) {
+                    failed = main->setting.state.status;
+                  }
+
+                  continue;
+                }
+
+                // the terminating NULL, past the used length.
+                strings[i]->array[j].string[strings[i]->array[j].used] = 0;
+                strings[i]->array[j].string[strings[i]->array[j].used + 1] = (family.type & f_network_family_ip_4_e)
+                  ? f_string_ascii_4_s.string[0]
+                  : f_string_ascii_6_s.string[0];
               }
             }
             else {
@@ -253,7 +392,11 @@ extern "C" {
 
               fll_program_print_error_parameter_empty_value(&main->program.error, f_console_symbol_long_normal_s, longs[i]);
 
-              return;
+              if (F_status_is_error_not(failed)) {
+                failed = main->setting.state.status;
+              }
+
+              continue;
             }
           } // for
         }
@@ -264,9 +407,17 @@ extern "C" {
 
           fll_program_print_error_parameter_missing_value(&main->program.error, f_console_symbol_long_normal_s, longs[i]);
 
-          return;
+          if (F_status_is_error_not(failed)) {
+            failed = main->setting.state.status;
+          }
+
+          continue;
         }
       } // for
+
+      if (F_status_is_error(failed)) {
+        main->setting.state.status = failed;
+      }
     }
   }
 #endif // _di_kt_tacocat_setting_load_
index 40fdc1ee4d3e764f0989cfcbae7bba226170954d..33cfd6b8db123133c21f0e085554efe15d6ca362 100644 (file)
@@ -7,7 +7,10 @@ extern "C" {
 #ifndef _di_kt_tacocat_f_a_
   const f_string_t kt_tacocat_f_a[] = {
     "f_console_parameter_process",
+    "f_network_from_ip_name",
+    "f_string_append_nulless",
     "f_string_dynamic_append_nulless",
+    "f_string_dynamic_increase_by",
     "f_string_dynamics_increase_by",
     "f_thread_create",
     "fll_program_parameter_process_context",
index 40507b78ba2cea6819416d3e71239e1c283a7bd0..88830981e4865da559f92019f1b84489218d6bd5 100644 (file)
@@ -40,7 +40,10 @@ extern "C" {
 #ifndef _di_kt_tacocat_f_e_
   enum {
     kt_tacocat_f_f_console_parameter_process_e,
+    kt_tacocat_f_f_network_from_ip_name_e,
+    kt_tacocat_f_f_string_append_nulless_e,
     kt_tacocat_f_f_string_dynamic_append_nulless_e,
+    kt_tacocat_f_f_string_dynamic_increase_by_e,
     kt_tacocat_f_f_string_dynamics_increase_by_e,
     kt_tacocat_f_f_thread_create_e,
     kt_tacocat_f_fll_program_parameter_process_context_e,
index 2f04f94158a75adc5375e37fbaf28914af983e2e..60d571d6cb4ba60e5e38fcbb2b8b660d363af1e3 100644 (file)
 #include <fll/level_0/status.h>
 #include <fll/level_0/memory.h>
 #include <fll/level_0/string.h>
-#include <fll/level_0/utf.h>
-#include <fll/level_0/account.h>
 #include <fll/level_0/color.h>
-#include <fll/level_0/compare.h>
 #include <fll/level_0/console.h>
-#include <fll/level_0/conversion.h>
-#include <fll/level_0/directory.h>
 #include <fll/level_0/file.h>
-#include <fll/level_0/fss.h>
+#include <fll/level_0/network.h>
+#include <fll/level_0/path.h>
 #include <fll/level_0/pipe.h>
 #include <fll/level_0/print.h>
-#include <fll/level_0/rip.h>
 #include <fll/level_0/signal.h>
 #include <fll/level_0/thread.h>
 
 // FLL-1 includes.
-#include <fll/level_1/conversion.h>
-#include <fll/level_1/directory.h>
 #include <fll/level_1/print.h>
 
 // FLL-2 includes.