Commit e8944f5b authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

Create/use file_type_match() for viewing, testing, and download-events

Allows for more/better wildcard matching in viewable and testable
file types and download-events (e.g. "tar.gz" or "tar.*").

This solves the "double-dot" problem in some file types/extensions.
An implicit "*." is prepended before the configured file type/extension.
parent 4e1ca83a
Pipeline #3630 passed with stage
in 6 minutes and 18 seconds
......@@ -798,6 +798,13 @@ int archive_type(const char* archive, char* str, size_t size)
return result;
}
bool file_type_match(const char* filename, const char* type)
{
char filespec[MAX_PATH + 1];
SAFEPRINTF(filespec, "*.%s", type);
return wildmatch(filename, filespec, /* path: */false, /* case-sensitive: */false);
}
str_list_t directory(const char* path)
{
int flags = GLOB_MARK;
......@@ -1058,13 +1065,8 @@ bool extract_diz(scfg_t* cfg, file_t* f, str_list_t diz_fnames, char* path, size
}
}
char* fext = getfext(f->name);
if(fext == NULL)
return false;
for(i = 0; i < cfg->total_fextrs; i++)
if(stricmp(cfg->fextr[i]->ext, fext + 1) == 0 && chk_ar(cfg, cfg->fextr[i]->ar, /* user: */NULL, /* client: */NULL))
if(file_type_match(f->name, cfg->fextr[i]->ext) && chk_ar(cfg, cfg->fextr[i]->ar, /* user: */NULL, /* client: */NULL))
break;
if(i >= cfg->total_fextrs)
return false;
......
......@@ -77,6 +77,7 @@ DLLEXPORT long extract_files_from_archive(const char* archive, const char* out
,bool with_path, bool overwrite, long max_files, str_list_t file_list, char* error, size_t);
DLLEXPORT int archive_type(const char* archive, char* str, size_t size);
extern const char* supported_archive_formats[];
DLLEXPORT bool file_type_match(const char* filename, const char* type);
/* Batch file transfer queues */
DLLEXPORT char* batch_list_name(scfg_t* , uint usernumber, enum XFER_TYPE, char* fname, size_t);
......
......@@ -1019,16 +1019,13 @@ int sbbs_t::listfileinfo(uint dirnum, const char *filespec, long mode)
}
CRLF;
}
const char* file_ext = getfext(f->name);
if(file_ext != NULL) {
for(j=0; j<cfg.total_dlevents; j++) {
if(!stricmp(cfg.dlevent[j]->ext, file_ext + 1)
&& chk_ar(cfg.dlevent[j]->ar,&useron,&client)) {
bputs(cfg.dlevent[j]->workstr);
external(cmdstr(cfg.dlevent[j]->cmd,path,nulstr,NULL)
,EX_OUTL);
clearline();
}
for(j=0; j<cfg.total_dlevents; j++) {
if(file_type_match(f->name, cfg.dlevent[j]->ext)
&& chk_ar(cfg.dlevent[j]->ar,&useron,&client)) {
bputs(cfg.dlevent[j]->workstr);
external(cmdstr(cfg.dlevent[j]->cmd,path,nulstr,NULL)
,EX_OUTL);
clearline();
}
}
action = NODE_DLNG;
......
......@@ -53,9 +53,8 @@ bool sbbs_t::uploadfile(file_t* f)
return false;
}
f->hdr.when_written.time = (uint32_t)fdate(path);
char* fext = getfext(f->name);
for(i=0;i<cfg.total_ftests;i++)
if(cfg.ftest[i]->ext[0]=='*' || (fext != NULL && stricmp(fext + 1, cfg.ftest[i]->ext) == 0)) {
if(file_type_match(f->name, cfg.ftest[i]->ext)) {
if(!chk_ar(cfg.ftest[i]->ar,&useron,&client))
continue;
attr(LIGHTGRAY);
......
......@@ -97,18 +97,13 @@ bool sbbs_t::viewfile(const char* inpath)
bputs(text[FileNotFound]);
return false;
}
char* file_ext = getfext(path);
if(file_ext == NULL) {
bprintf(text[NonviewableFile], getfname(path));
return false;
}
for(i=0;i<cfg.total_fviews;i++)
if(wildmatchi(file_ext + 1, cfg.fview[i]->ext, /* path: */false) && chk_ar(cfg.fview[i]->ar,&useron,&client)) {
if(file_type_match(path, cfg.fview[i]->ext) && chk_ar(cfg.fview[i]->ar,&useron,&client)) {
SAFECOPY(viewcmd,cfg.fview[i]->cmd);
break;
}
if(i >= cfg.total_fviews) {
bprintf(text[NonviewableFile], file_ext);
bprintf(text[NonviewableFile], getfname(path));
return false;
}
if((i=external(cmdstr(viewcmd, path, path, NULL), EX_STDIO|EX_SH))!=0) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment