Add option for case insensitivity in ticproc

This commit is contained in:
Andrew Pamment 2017-10-18 20:50:33 +10:00
parent 7d2ebc7a71
commit 8cf56bfe8d
3 changed files with 74 additions and 5 deletions

View File

@ -1,5 +1,6 @@
[main] [main]
Ignore Password = true Ignore Password = true
Ignore Case = false
Inbound Directory = /home/andrew/ticfiles Inbound Directory = /home/andrew/ticfiles
Bad Files Directory = /home/andrew/ticfiles/bad Bad Files Directory = /home/andrew/ticfiles/bad

View File

@ -13,6 +13,27 @@
struct ticproc_t conf; struct ticproc_t conf;
char *find_file_nocase(char *filename) {
DIR *inb;
struct dirent *dent;
char *nocasefname;
inb = opendir(conf.inbound);
if (!inb) {
fprintf(stderr, "Error opening inbound directory\n");
return NULL;
}
while ((dent = readdir(inb)) != NULL) {
if (strcasecmp(dent->d_name, filename) == 0) {
ncasefname = strdup(dent->d_name);
closedir(inb);
return ncasefname;
}
}
closedir(inb);
return NULL;
}
static int handler(void* user, const char* section, const char* name, static int handler(void* user, const char* section, const char* name,
const char* value) const char* value)
{ {
@ -29,6 +50,12 @@ static int handler(void* user, const char* section, const char* name,
conf.inbound = strdup(value); conf.inbound = strdup(value);
} else if (strcasecmp(name, "bad files directory") == 0) { } else if (strcasecmp(name, "bad files directory") == 0) {
conf.bad = strdup(value); conf.bad = strdup(value);
} else if (strcasecmp(name, "ignore case") == 0) {
if (strcasecmp(value, "true") == 0) {
conf.case_insensitve = 1;
} else {
conf.case_insensitve = 0;
}
} }
} else { } else {
for (i=0;i<conf.filearea_count;i++) { for (i=0;i<conf.filearea_count;i++) {
@ -128,6 +155,8 @@ int add_file(struct ticfile_t *ticfile) {
int len; int len;
unsigned long crc; unsigned long crc;
time_t curtime; time_t curtime;
char *casename;
char *ncasename;
if (ticfile->area == NULL) { if (ticfile->area == NULL) {
return -1; return -1;
@ -177,21 +206,58 @@ int add_file(struct ticfile_t *ticfile) {
if (ticfile->lname != NULL) { if (ticfile->lname != NULL) {
snprintf(src_filename, 4096, "%s/%s", conf.inbound, ticfile->lname); snprintf(src_filename, 4096, "%s/%s", conf.inbound, ticfile->lname);
snprintf(dest_filename, 4096, "%s/%s", conf.file_areas[i]->path, ticfile->lname); snprintf(dest_filename, 4096, "%s/%s", conf.file_areas[i]->path, ticfile->lname);
if (stat(src_filename, &s) != 0) { if (stat(src_filename, &s) != 0) {
snprintf(src_filename, 4096, "%s/%s", conf.inbound, ticfile->file); snprintf(src_filename, 4096, "%s/%s", conf.inbound, ticfile->file);
snprintf(dest_filename, 4096, "%s/%s", conf.file_areas[i]->path, ticfile->file); snprintf(dest_filename, 4096, "%s/%s", conf.file_areas[i]->path, ticfile->file);
casename = ticfile->file;
} else {
casename = ticfile->lname;
} }
} else { } else {
snprintf(src_filename, 4096, "%s/%s", conf.inbound, ticfile->file); snprintf(src_filename, 4096, "%s/%s", conf.inbound, ticfile->file);
snprintf(dest_filename, 4096, "%s/%s", conf.file_areas[i]->path, ticfile->file); snprintf(dest_filename, 4096, "%s/%s", conf.file_areas[i]->path, ticfile->file);
casename = ticfile->file;
} }
// check crc // check crc
fptr = fopen(src_filename, "rb"); fptr = fopen(src_filename, "rb");
if (!fptr) { if (!fptr) {
fprintf(stderr, "Error Opening %s\n", src_filename);
sqlite3_free(err_msg); if (conf.case_insensitve) {
sqlite3_close(db); nocasename = find_file_nocase(casename);
return -1; if (nocasename == NULL) {
if (casename == ticfile->lname) {
nocasename = find_file_nocase(ticfile->file);
if (nocasename == NULL) {
fprintf(stderr, "Error Opening %s\n", src_filename);
sqlite3_free(err_msg);
sqlite3_close(db);
return -1;
}
} else {
fprintf(stderr, "Error Opening %s\n", src_filename);
sqlite3_free(err_msg);
sqlite3_close(db);
return -1;
}
}
snprintf(src_filename, 4096, "%s/%s", conf.inbound, nocasename);
free(nocasename);
fptr = fopen(src_filename, "rb");
if (!fptr) {
fprintf(stderr, "Error Opening %s\n", src_filename);
sqlite3_free(err_msg);
sqlite3_close(db);
return -1;
}
} else {
fprintf(stderr, "Error Opening %s\n", src_filename);
sqlite3_free(err_msg);
sqlite3_close(db);
return -1;
}
} }
if (ticfile->crc != NULL) { if (ticfile->crc != NULL) {
@ -422,6 +488,7 @@ int main(int argc, char **argv) {
struct dirent *dent; struct dirent *dent;
conf.filearea_count = 0; conf.filearea_count = 0;
conf.case_insensitve = 0;
if (ini_parse(argv[1], handler, NULL) <0) { if (ini_parse(argv[1], handler, NULL) <0) {
fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]); fprintf(stderr, "Unable to load configuration ini (%s)!\n", argv[1]);
exit(-1); exit(-1);

View File

@ -10,6 +10,7 @@ struct filearea_t {
struct ticproc_t { struct ticproc_t {
int ignore_pass; int ignore_pass;
int case_insensitve;
char *inbound; char *inbound;
char *bad; char *bad;
int filearea_count; int filearea_count;