From: Stephen Seo Date: Mon, 17 Feb 2025 04:53:27 +0000 (+0900) Subject: WIP white/black-list: refactoring X-Git-Tag: 1.16^2~24 X-Git-Url: https://git.seodisparate.com/stephenseo/LD52?a=commitdiff_plain;h=a69016822ee429a4852122bc5949db5dc9a3bdbf;p=SimpleArchiver WIP white/black-list: refactoring --- diff --git a/src/archiver.c b/src/archiver.c index 59b6797..ea07a74 100644 --- a/src/archiver.c +++ b/src/archiver.c @@ -1704,86 +1704,15 @@ int symlinks_and_files_from_files(void *data, void *ud) { if (file_info->filename) { // Check white/black lists. - if (state->parsed->whitelist_contains) { - for (SDArchiverLLNode *node = - state->parsed->whitelist_contains->head->next; - node != state->parsed->whitelist_contains->tail; - node = node->next) { - if (node->data) { - if (!simple_archiver_helper_string_contains(file_info->filename, - node->data)) { - // Skipping since filename does not contain whitelist text. - return 0; - } - } - } - } - if (state->parsed->whitelist_begins) { - for (SDArchiverLLNode *node = state->parsed->whitelist_begins->head->next; - node != state->parsed->whitelist_begins->tail; - node = node->next) { - if (node->data) { - if (!simple_archiver_helper_string_starts(file_info->filename, - node->data)) { - // Skipping since filename does not start with whitelist text. - return 0; - } - } - } - } - if (state->parsed->whitelist_ends) { - for (SDArchiverLLNode *node = state->parsed->whitelist_ends->head->next; - node != state->parsed->whitelist_ends->tail; - node = node->next) { - if (node->data) { - if (!simple_archiver_helper_string_ends(file_info->filename, - node->data)) { - // Skipping since filename does not end with whitelist text. - return 0; - } - } - } - } - - if (state->parsed->blacklist_contains) { - for (SDArchiverLLNode *node = - state->parsed->blacklist_contains->head->next; - node != state->parsed->blacklist_contains->tail; - node = node->next) { - if (node->data) { - if (simple_archiver_helper_string_contains(file_info->filename, - node->data)) { - // Skipping since filename contains blacklist text. - return 0; - } - } - } - } - if (state->parsed->blacklist_begins) { - for (SDArchiverLLNode *node = state->parsed->blacklist_begins->head->next; - node != state->parsed->blacklist_begins->tail; - node = node->next) { - if (node->data) { - if (simple_archiver_helper_string_starts(file_info->filename, - node->data)) { - // Skipping since filename starts with blacklist text. - return 0; - } - } - } - } - if (state->parsed->blacklist_ends) { - for (SDArchiverLLNode *node = state->parsed->blacklist_ends->head->next; - node != state->parsed->blacklist_ends->tail; - node = node->next) { - if (node->data) { - if (simple_archiver_helper_string_ends(file_info->filename, - node->data)) { - // Skipping since filename ends with blacklist text. - return 0; - } - } - } + if (!simple_archiver_helper_string_allowed_lists( + file_info->filename, + state->parsed->whitelist_contains, + state->parsed->whitelist_begins, + state->parsed->whitelist_ends, + state->parsed->blacklist_contains, + state->parsed->blacklist_begins, + state->parsed->blacklist_ends)) { + return 0; } if (file_info->link_dest) { diff --git a/src/helpers.c b/src/helpers.c index 6c65f27..5d102e0 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -682,3 +682,82 @@ uint_fast8_t simple_archiver_helper_string_ends(const char *cstring, return 0; } + +uint_fast8_t simple_archiver_helper_string_allowed_lists( + const char *cstring, + 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; + node = node->next) { + if (node->data) { + if (!simple_archiver_helper_string_contains(cstring, node->data)) { + return 0; + } + } + } + } + if (w_begins) { + for (const SDArchiverLLNode *node = w_begins->head->next; + node != w_begins->tail; + node = node->next) { + if (node->data) { + if (!simple_archiver_helper_string_starts(cstring, node->data)) { + return 0; + } + } + } + } + if (w_ends) { + for (const SDArchiverLLNode *node = w_ends->head->next; + node != w_ends->tail; + node = node->next) { + if (node->data) { + if (!simple_archiver_helper_string_ends(cstring, node->data)) { + return 0; + } + } + } + } + + if (b_contains) { + for (const SDArchiverLLNode *node = b_contains->head->next; + node != b_contains->tail; + node = node->next) { + if (node->data) { + if (simple_archiver_helper_string_contains(cstring, node->data)) { + return 0; + } + } + } + } + if (b_begins) { + for (const SDArchiverLLNode *node = b_begins->head->next; + node != b_begins->tail; + node = node->next) { + if (node->data) { + if (simple_archiver_helper_string_starts(cstring, node->data)) { + return 0; + } + } + } + } + if (b_ends) { + for (const SDArchiverLLNode *node = b_ends->head->next; + node != b_ends->tail; + node = node->next) { + if (node->data) { + if (simple_archiver_helper_string_ends(cstring, node->data)) { + return 0; + } + } + } + } + + return 1; +} diff --git a/src/helpers.h b/src/helpers.h index 8a5f18e..37d5493 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -131,4 +131,14 @@ uint_fast8_t simple_archiver_helper_string_starts(const char *cstring, uint_fast8_t simple_archiver_helper_string_ends(const char *cstring, const char *ends); +// Returns non-zero if "cstring" is allowed by lists. +uint_fast8_t simple_archiver_helper_string_allowed_lists( + const char *cstring, + const SDArchiverLinkedList *w_contains, + const SDArchiverLinkedList *w_begins, + const SDArchiverLinkedList *w_ends, + const SDArchiverLinkedList *b_contains, + const SDArchiverLinkedList *b_begins, + const SDArchiverLinkedList *b_ends); + #endif