From e14302e7d4ba6113fdba2ecff92bbfe5511da6de Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sun, 28 Dec 2025 14:58:27 -0600 Subject: Use _cryptscan_args struct to pass values in cryptscan helper functions --- src/encryption.c | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'src/encryption.c') diff --git a/src/encryption.c b/src/encryption.c index 23c8a4d..5e667c6 100644 --- a/src/encryption.c +++ b/src/encryption.c @@ -458,14 +458,39 @@ static int _cryptscan__selector(const struct dirent *de) { return 1; } +struct _cryptscan_args { + char *folder; + taskqueue *toscan; + ctqueue *tocrypt; +}; + +void _cryptscan_args_free(void *data) { + if(!data) return; + struct _cryptscan_args *real = data; + + free(real->folder); + free(real); + return; +} + // TODO: Implement int _cryptscan__crypt(void *data) { + if(!data) return -1; + struct _cryptscan_args *real = data; + // Do things + + return 0; } // TODO: Implement int _cryptscan__scan(void *data) { + if(!data) return -1; + struct _cryptscan_args *real = data; + // Do things + + return 0; } /// helper function to deduplicate code for dealing with scandir. Scans the directory at `folder` and places dirents into their respective lists @@ -477,10 +502,18 @@ int _cryptscan__process_scandir(const char * const folder, taskqueue *toscan, ct int entries = scandir(folder, &namelist, _cryptscan__selector, alphasort); if(!toscan || !tocrypt || entries < 0) {res = -1; goto _cryptscan__process_scandir_CLEANUP;} - struct stat sb; char *tmpname = NULL; task *tmptsk = NULL; char tflag = 0; + struct stat sb; + task *tmptsk = NULL; + struct _cryptscan_args *args = NULL; char tflag = 0; for(int i = 0; i < entries; i++) { - tmpname = strdup(namelist[i]->d_name); - if(!tmpname) {if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not duplicate file \"%s\"s name for processing",, namelist[i]->d_name); continue;} + args = calloc(1, sizeof(*args)); + if(!args) { + if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not create arg holder for task",); + } + args->folder = strdup(namelist[i]->d_name); + args->tocrypt = tocrypt; + args->toscan = toscan; + if(!args->folder) {if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not duplicate file \"%s\"s name for processing",, namelist[i]->d_name); continue;} switch(namelist[i]->d_type) { // Try to stat the file if it's unknown @@ -493,9 +526,9 @@ int _cryptscan__process_scandir(const char * const folder, taskqueue *toscan, ct // Add it to the ctq case DT_REG: CRYPT: - tmptsk = task_new(_cryptscan__crypt, free, tmpname); + tmptsk = task_new(_cryptscan__crypt, _cryptscan_args_free, args); if(!tmptsk) { - if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not generate crypt task for \"%s\"",, tmpname); + if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not generate crypt task for \"%s\"",, args->folder); break; } @@ -512,9 +545,9 @@ int _cryptscan__process_scandir(const char * const folder, taskqueue *toscan, ct // Add it to the scanlist case DT_DIR: SCAN: - tmptsk = task_new(_cryptscan__scan, free, tmpname); + tmptsk = task_new(_cryptscan__scan, _cryptscan_args_free, args); if(!tmptsk) { - if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not generate scan task for \"%s\"",, tmpname); + if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not generate scan task for \"%s\"",, args->folder); break; } @@ -535,7 +568,7 @@ int _cryptscan__process_scandir(const char * const folder, taskqueue *toscan, ct WARN(ENOSYS, "<_cryptscan__process_scandir> Info: file \"%s\"s type is unsupported",, namelist[i]->d_name); break; } - if(!tflag) free(tmpname); + if(!tflag) _cryptscan_args_free(args); tflag = 0; } -- cgit v1.2.3