summaryrefslogtreecommitdiff
path: root/src/encryption.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/encryption.c')
-rw-r--r--src/encryption.c49
1 files changed, 41 insertions, 8 deletions
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) {
458 return 1; 458 return 1;
459} 459}
460 460
461struct _cryptscan_args {
462 char *folder;
463 taskqueue *toscan;
464 ctqueue *tocrypt;
465};
466
467void _cryptscan_args_free(void *data) {
468 if(!data) return;
469 struct _cryptscan_args *real = data;
470
471 free(real->folder);
472 free(real);
473 return;
474}
475
461// TODO: Implement 476// TODO: Implement
462int _cryptscan__crypt(void *data) { 477int _cryptscan__crypt(void *data) {
478 if(!data) return -1;
479 struct _cryptscan_args *real = data;
463 480
481 // Do things
482
483 return 0;
464} 484}
465 485
466// TODO: Implement 486// TODO: Implement
467int _cryptscan__scan(void *data) { 487int _cryptscan__scan(void *data) {
488 if(!data) return -1;
489 struct _cryptscan_args *real = data;
468 490
491 // Do things
492
493 return 0;
469} 494}
470 495
471/// helper function to deduplicate code for dealing with scandir. Scans the directory at `folder` and places dirents into their respective lists 496/// 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
477 int entries = scandir(folder, &namelist, _cryptscan__selector, alphasort); 502 int entries = scandir(folder, &namelist, _cryptscan__selector, alphasort);
478 if(!toscan || !tocrypt || entries < 0) {res = -1; goto _cryptscan__process_scandir_CLEANUP;} 503 if(!toscan || !tocrypt || entries < 0) {res = -1; goto _cryptscan__process_scandir_CLEANUP;}
479 504
480 struct stat sb; char *tmpname = NULL; task *tmptsk = NULL; char tflag = 0; 505 struct stat sb;
506 task *tmptsk = NULL;
507 struct _cryptscan_args *args = NULL; char tflag = 0;
481 for(int i = 0; i < entries; i++) { 508 for(int i = 0; i < entries; i++) {
482 tmpname = strdup(namelist[i]->d_name); 509 args = calloc(1, sizeof(*args));
483 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;} 510 if(!args) {
511 if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not create arg holder for task",);
512 }
513 args->folder = strdup(namelist[i]->d_name);
514 args->tocrypt = tocrypt;
515 args->toscan = toscan;
516 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;}
484 517
485 switch(namelist[i]->d_type) { 518 switch(namelist[i]->d_type) {
486 // Try to stat the file if it's unknown 519 // Try to stat the file if it's unknown
@@ -493,9 +526,9 @@ int _cryptscan__process_scandir(const char * const folder, taskqueue *toscan, ct
493 526
494 // Add it to the ctq 527 // Add it to the ctq
495 case DT_REG: CRYPT: 528 case DT_REG: CRYPT:
496 tmptsk = task_new(_cryptscan__crypt, free, tmpname); 529 tmptsk = task_new(_cryptscan__crypt, _cryptscan_args_free, args);
497 if(!tmptsk) { 530 if(!tmptsk) {
498 if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not generate crypt task for \"%s\"",, tmpname); 531 if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not generate crypt task for \"%s\"",, args->folder);
499 break; 532 break;
500 } 533 }
501 534
@@ -512,9 +545,9 @@ int _cryptscan__process_scandir(const char * const folder, taskqueue *toscan, ct
512 545
513 // Add it to the scanlist 546 // Add it to the scanlist
514 case DT_DIR: SCAN: 547 case DT_DIR: SCAN:
515 tmptsk = task_new(_cryptscan__scan, free, tmpname); 548 tmptsk = task_new(_cryptscan__scan, _cryptscan_args_free, args);
516 if(!tmptsk) { 549 if(!tmptsk) {
517 if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not generate scan task for \"%s\"",, tmpname); 550 if(___VXGG___VERBOSE_ERRORS___) WARN(errno, "<_cryptscan__process_scandir> Warning: Could not generate scan task for \"%s\"",, args->folder);
518 break; 551 break;
519 } 552 }
520 553
@@ -535,7 +568,7 @@ int _cryptscan__process_scandir(const char * const folder, taskqueue *toscan, ct
535 WARN(ENOSYS, "<_cryptscan__process_scandir> Info: file \"%s\"s type is unsupported",, namelist[i]->d_name); 568 WARN(ENOSYS, "<_cryptscan__process_scandir> Info: file \"%s\"s type is unsupported",, namelist[i]->d_name);
536 break; 569 break;
537 } 570 }
538 if(!tflag) free(tmpname); 571 if(!tflag) _cryptscan_args_free(args);
539 tflag = 0; 572 tflag = 0;
540 } 573 }
541 574