]> git.seodisparate.com - SimpleArchiver/commitdiff
Refactor white/black-list code
authorStephen Seo <seo.disparate@gmail.com>
Tue, 18 Feb 2025 04:10:14 +0000 (13:10 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 18 Feb 2025 04:10:14 +0000 (13:10 +0900)
src/archiver.c
src/helpers.c
src/helpers.h

index 6a4005c0a117ca58803f05c6eecfe2463816b3ed..b4f4f3cc1d3c39dbfe219b7127ad62ad27aa56da 100644 (file)
@@ -1708,12 +1708,7 @@ int symlinks_and_files_from_files(void *data, void *ud) {
     if (!simple_archiver_helper_string_allowed_lists(
         file_info->filename,
         state->parsed->flags & 0x20000 ? 1 : 0,
-        state->parsed->whitelist_contains,
-        state->parsed->whitelist_begins,
-        state->parsed->whitelist_ends,
-        state->parsed->blacklist_contains,
-        state->parsed->blacklist_begins,
-        state->parsed->blacklist_ends)) {
+        state->parsed)) {
       return 0;
     }
 
@@ -7043,12 +7038,7 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
     const uint_fast8_t lists_allowed = simple_archiver_helper_string_allowed_lists(
       link_name,
       state->parsed->flags & 0x20000 ? 1 : 0,
-      state->parsed->whitelist_contains,
-      state->parsed->whitelist_begins,
-      state->parsed->whitelist_ends,
-      state->parsed->blacklist_contains,
-      state->parsed->blacklist_begins,
-      state->parsed->blacklist_ends);
+      state->parsed);
 
     if (lists_allowed) {
       fprintf(stderr, "SYMLINK %3" PRIu32 " of %3" PRIu32 "\n", idx + 1, u32);
@@ -7399,12 +7389,7 @@ int simple_archiver_parse_archive_version_1(FILE *in_f, int_fast8_t do_extract,
       if (simple_archiver_helper_string_allowed_lists(
           file_info->filename,
           state->parsed->flags & 0x20000 ? 1 : 0,
-          state->parsed->whitelist_contains,
-          state->parsed->whitelist_begins,
-          state->parsed->whitelist_ends,
-          state->parsed->blacklist_contains,
-          state->parsed->blacklist_begins,
-          state->parsed->blacklist_ends)) {
+          state->parsed)) {
         file_info->other_flags |= 2;
       }
 
@@ -8069,12 +8054,7 @@ int simple_archiver_parse_archive_version_2(FILE *in_f, int_fast8_t do_extract,
     const uint_fast8_t lists_allowed = simple_archiver_helper_string_allowed_lists(
       buf,
       state->parsed->flags & 0x20000 ? 1 : 0,
-      state->parsed->whitelist_contains,
-      state->parsed->whitelist_begins,
-      state->parsed->whitelist_ends,
-      state->parsed->blacklist_contains,
-      state->parsed->blacklist_begins,
-      state->parsed->blacklist_ends);
+      state->parsed);
 
     uint8_t perms_flags[4];
     if (fread(perms_flags, 1, 2, in_f) != 2) {
@@ -8429,12 +8409,7 @@ int simple_archiver_parse_archive_version_3(FILE *in_f,
     const uint_fast8_t lists_allowed = simple_archiver_helper_string_allowed_lists(
       link_name,
       state->parsed->flags & 0x20000 ? 1 : 0,
-      state->parsed->whitelist_contains,
-      state->parsed->whitelist_begins,
-      state->parsed->whitelist_ends,
-      state->parsed->blacklist_contains,
-      state->parsed->blacklist_begins,
-      state->parsed->blacklist_ends);
+      state->parsed);
 
     if (!do_extract && lists_allowed) {
       fprintf(stderr, "SYMLINK %3" PRIu32 " of %3" PRIu32 "\n", idx + 1, count);
@@ -9044,12 +9019,7 @@ int simple_archiver_parse_archive_version_3(FILE *in_f,
       } else if (simple_archiver_helper_string_allowed_lists(
           file_info->filename,
           state->parsed->flags & 0x20000 ? 1 : 0,
-          state->parsed->whitelist_contains,
-          state->parsed->whitelist_begins,
-          state->parsed->whitelist_ends,
-          state->parsed->blacklist_contains,
-          state->parsed->blacklist_begins,
-          state->parsed->blacklist_ends)) {
+          state->parsed)) {
         file_info->other_flags |= 2;
       }
 
@@ -9776,12 +9746,7 @@ int simple_archiver_parse_archive_version_3(FILE *in_f,
       simple_archiver_helper_string_allowed_lists(
         archive_dir_name,
         state->parsed->flags & 0x20000 ? 1 : 0,
-        state->parsed->whitelist_contains,
-        state->parsed->whitelist_begins,
-        state->parsed->whitelist_ends,
-        state->parsed->blacklist_contains,
-        state->parsed->blacklist_begins,
-        state->parsed->blacklist_ends);
+        state->parsed);
 
     uint8_t perms_flags[4];
     if (fread(perms_flags, 1, 2, in_f) != 2) {
index 7f5ac95abe502078258245494486b7e412bcb8e1..d8e1068aca7be30a4ec2a8461367879acac62c50 100644 (file)
@@ -722,15 +722,10 @@ uint_fast8_t simple_archiver_helper_string_ends(const char *cstring,
 uint_fast8_t simple_archiver_helper_string_allowed_lists(
     const char *cstring,
     uint_fast8_t case_i,
-    const SDArchiverLinkedList *w_contains,
-    const SDArchiverLinkedList *w_begins,
-    const SDArchiverLinkedList *w_ends,
-    const SDArchiverLinkedList *b_contains,
-    const SDArchiverLinkedList *b_begins,
-    const SDArchiverLinkedList *b_ends) {
-  if (w_contains) {
-    for (const SDArchiverLLNode *node = w_contains->head->next;
-        node != w_contains->tail;
+    const SDArchiverParsed *parsed) {
+  if (parsed->whitelist_contains) {
+    for (const SDArchiverLLNode *node = parsed->whitelist_contains->head->next;
+        node != parsed->whitelist_contains->tail;
         node = node->next) {
       if (node->data) {
         if (!simple_archiver_helper_string_contains(
@@ -740,9 +735,9 @@ uint_fast8_t simple_archiver_helper_string_allowed_lists(
       }
     }
   }
-  if (w_begins) {
-    for (const SDArchiverLLNode *node = w_begins->head->next;
-        node != w_begins->tail;
+  if (parsed->whitelist_begins) {
+    for (const SDArchiverLLNode *node = parsed->whitelist_begins->head->next;
+        node != parsed->whitelist_begins->tail;
         node = node->next) {
       if (node->data) {
         if (!simple_archiver_helper_string_starts(
@@ -752,9 +747,9 @@ uint_fast8_t simple_archiver_helper_string_allowed_lists(
       }
     }
   }
-  if (w_ends) {
-    for (const SDArchiverLLNode *node = w_ends->head->next;
-        node != w_ends->tail;
+  if (parsed->whitelist_ends) {
+    for (const SDArchiverLLNode *node = parsed->whitelist_ends->head->next;
+        node != parsed->whitelist_ends->tail;
         node = node->next) {
       if (node->data) {
         if (!simple_archiver_helper_string_ends(cstring, node->data, case_i)) {
@@ -764,10 +759,10 @@ uint_fast8_t simple_archiver_helper_string_allowed_lists(
     }
   }
 
-  if (b_contains) {
+  if (parsed->blacklist_contains) {
     uint_fast8_t contains_all = 1;
-    for (const SDArchiverLLNode *node = b_contains->head->next;
-        node != b_contains->tail;
+    for (const SDArchiverLLNode *node = parsed->blacklist_contains->head->next;
+        node != parsed->blacklist_contains->tail;
         node = node->next) {
       if (node->data) {
         if (!simple_archiver_helper_string_contains(
@@ -782,9 +777,9 @@ uint_fast8_t simple_archiver_helper_string_allowed_lists(
       return 0;
     }
   }
-  if (b_begins) {
-    for (const SDArchiverLLNode *node = b_begins->head->next;
-        node != b_begins->tail;
+  if (parsed->blacklist_begins) {
+    for (const SDArchiverLLNode *node = parsed->blacklist_begins->head->next;
+        node != parsed->blacklist_begins->tail;
         node = node->next) {
       if (node->data) {
         if (simple_archiver_helper_string_starts(cstring, node->data, case_i)) {
@@ -793,9 +788,9 @@ uint_fast8_t simple_archiver_helper_string_allowed_lists(
       }
     }
   }
-  if (b_ends) {
-    for (const SDArchiverLLNode *node = b_ends->head->next;
-        node != b_ends->tail;
+  if (parsed->blacklist_ends) {
+    for (const SDArchiverLLNode *node = parsed->blacklist_ends->head->next;
+        node != parsed->blacklist_ends->tail;
         node = node->next) {
       if (node->data) {
         if (simple_archiver_helper_string_ends(cstring, node->data, case_i)) {
index 04936cd0e7be6459f57b889f308a1cfcdf2c552a..676e1a8336f5f70c266f610b61ce2f75d96ca316 100644 (file)
@@ -25,6 +25,7 @@
 
 // Local includes.
 #include "data_structures/linked_list.h"
+#include "parser.h"
 
 static const uint32_t MAX_SYMBOLIC_LINK_SIZE = 512;
 
@@ -142,11 +143,6 @@ uint_fast8_t simple_archiver_helper_string_ends(const char *cstring,
 uint_fast8_t simple_archiver_helper_string_allowed_lists(
   const char *cstring,
   uint_fast8_t case_i,
-  const SDArchiverLinkedList *w_contains,
-  const SDArchiverLinkedList *w_begins,
-  const SDArchiverLinkedList *w_ends,
-  const SDArchiverLinkedList *b_contains,
-  const SDArchiverLinkedList *b_begins,
-  const SDArchiverLinkedList *b_ends);
+  const SDArchiverParsed *parsed);
 
 #endif