Hatch and Magic processing now use the regexp library
This commit is contained in:
parent
cb7b34b7de
commit
e83107196f
@ -4761,8 +4761,8 @@ v0.33.20 10-Feb-2002
|
|||||||
Added more checks to processing of file_id.diz files. Also
|
Added more checks to processing of file_id.diz files. Also
|
||||||
when it is illegal formatted the already processed lines are
|
when it is illegal formatted the already processed lines are
|
||||||
cleared to prevent later malformatted descriptions.
|
cleared to prevent later malformatted descriptions.
|
||||||
Added experimental debugging only code in magic and hatch
|
The hatch and magic processors now scan the filenames to test
|
||||||
name testing.
|
using the regexp library, this should be more reliable.
|
||||||
|
|
||||||
mbmsg:
|
mbmsg:
|
||||||
When creating non-existend message bases, the path is created
|
When creating non-existend message bases, the path is created
|
||||||
|
322
mbfido/hatch.c
322
mbfido/hatch.c
@ -41,198 +41,180 @@
|
|||||||
|
|
||||||
|
|
||||||
extern int do_quiet;
|
extern int do_quiet;
|
||||||
|
int Days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
|
||||||
|
int Hatched = 0;
|
||||||
|
|
||||||
int Days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
|
|
||||||
int Hatched = 0;
|
|
||||||
|
|
||||||
int CheckHatch(char *);
|
int CheckHatch(char *);
|
||||||
|
|
||||||
|
|
||||||
void Hatch()
|
void Hatch()
|
||||||
{
|
{
|
||||||
char *temp;
|
char *temp;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct tm *Tm;
|
struct tm *Tm;
|
||||||
time_t Now;
|
time_t Now;
|
||||||
int LastDay;
|
int LastDay;
|
||||||
int HatchToday;
|
int HatchToday;
|
||||||
|
|
||||||
temp = calloc(128, sizeof(char));
|
temp = calloc(PATH_MAX, sizeof(char));
|
||||||
Syslog('+', "Pass: hatch files");
|
Syslog('+', "Pass: hatch files");
|
||||||
Now = time(NULL);
|
Now = time(NULL);
|
||||||
Tm = localtime(&Now);
|
Tm = localtime(&Now);
|
||||||
|
|
||||||
LastDay = Days[Tm->tm_mon];
|
LastDay = Days[Tm->tm_mon];
|
||||||
if (Tm->tm_mon == 1) {
|
if (Tm->tm_mon == 1) {
|
||||||
/*
|
/*
|
||||||
* Note that with this method each century change is a leapyear,
|
* Note that with this method each century change is a leapyear,
|
||||||
* but take in mind that fidonet will no longer exist in 2100.
|
* but take in mind that fidonet will no longer exist in 2100.
|
||||||
*/
|
*/
|
||||||
if (!(Tm->tm_year % 4))
|
if (!(Tm->tm_year % 4))
|
||||||
LastDay++;
|
LastDay++;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(temp, "%s/etc/hatch.data", getenv("MBSE_ROOT"));
|
sprintf(temp, "%s/etc/hatch.data", getenv("MBSE_ROOT"));
|
||||||
if ((fp = fopen(temp, "r")) == NULL) {
|
if ((fp = fopen(temp, "r")) == NULL) {
|
||||||
WriteError("$Can't open %s", temp);
|
WriteError("$Can't open %s", temp);
|
||||||
free(temp);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fread(&hatchhdr, sizeof(hatchhdr), 1, fp);
|
|
||||||
|
|
||||||
while (fread(&hatch, hatchhdr.recsize, 1, fp) == 1) {
|
|
||||||
if (hatch.Active) {
|
|
||||||
HatchToday = FALSE;
|
|
||||||
if (hatch.Days[Diw])
|
|
||||||
HatchToday = TRUE;
|
|
||||||
if ((hatch.Month[Tm->tm_mday -1]) ||
|
|
||||||
(hatch.Month[31] && (LastDay == Tm->tm_mday)))
|
|
||||||
HatchToday = TRUE;
|
|
||||||
sprintf(temp, "%s", hatch.Spec);
|
|
||||||
|
|
||||||
if (HatchToday)
|
|
||||||
CheckHatch(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
free(temp);
|
free(temp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fread(&hatchhdr, sizeof(hatchhdr), 1, fp);
|
||||||
|
|
||||||
|
while (fread(&hatch, hatchhdr.recsize, 1, fp) == 1) {
|
||||||
|
if (hatch.Active) {
|
||||||
|
HatchToday = FALSE;
|
||||||
|
if (hatch.Days[Diw])
|
||||||
|
HatchToday = TRUE;
|
||||||
|
if ((hatch.Month[Tm->tm_mday -1]) || (hatch.Month[31] && (LastDay == Tm->tm_mday)))
|
||||||
|
HatchToday = TRUE;
|
||||||
|
sprintf(temp, "%s", hatch.Spec);
|
||||||
|
|
||||||
|
if (HatchToday)
|
||||||
|
CheckHatch(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
free(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int CheckHatch(char *temp)
|
int CheckHatch(char *temp)
|
||||||
{
|
{
|
||||||
DIR *dp;
|
DIR *dp;
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
char *fn, tf[81], tmp[4], *temp2;
|
char *fn, *tf, tmp[4], *temp2;
|
||||||
int i, Match, hatched = FALSE;
|
int i, hatched = FALSE;
|
||||||
char *Temp, *p, *q, mask[256];
|
char *p, *q, mask[256];
|
||||||
FILE *Tf;
|
FILE *Tf;
|
||||||
|
|
||||||
fn = xstrcpy(strrchr(temp, '/') + 1);
|
fn = xstrcpy(strrchr(temp, '/') + 1);
|
||||||
|
|
||||||
while (temp[strlen(temp) -1] != '/')
|
while (temp[strlen(temp) -1] != '/')
|
||||||
temp[strlen(temp) -1] = '\0';
|
|
||||||
temp[strlen(temp) -1] = '\0';
|
temp[strlen(temp) -1] = '\0';
|
||||||
|
temp[strlen(temp) -1] = '\0';
|
||||||
|
|
||||||
if (chdir(temp)) {
|
if (chdir(temp)) {
|
||||||
WriteError("$Can't chdir(%s)", temp);
|
WriteError("$Can't chdir(%s)", temp);
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((dp = opendir(temp)) == NULL) {
|
|
||||||
WriteError("$Can't opendir(%s)", temp);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Temp = xstrcpy(fn);
|
|
||||||
p = tl(Temp);
|
|
||||||
q = mask;
|
|
||||||
*q++ = '^';
|
|
||||||
while ((*p) && (q < (mask + sizeof(mask) - 4))) {
|
|
||||||
switch(*p) {
|
|
||||||
case '\\': *q++ = '\\'; *q++ = '\\'; break;
|
|
||||||
case '?': *q++ = '.'; break;
|
|
||||||
case '.': *q++ = '\\'; *q++ = '.'; break;
|
|
||||||
case '+': *q++ = '\\'; *q++ = '+'; break;
|
|
||||||
case '*': *q++ = '.'; *q++ = '*'; break;
|
|
||||||
case '@': sprintf(q, "[A-Za-z]"); while (*q) q++; break;
|
|
||||||
case '#': sprintf(q, "[0-9]"); while (*q) q++; break;
|
|
||||||
default: *q++ = *p; break;
|
|
||||||
}
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
*q++ = '$';
|
|
||||||
*q = '\0';
|
|
||||||
Syslog('f', "Hatch mask \"%s\" -> \"%s\"", MBSE_SS(Temp), MBSE_SS(mask));
|
|
||||||
if ((re_comp(mask)) == NULL)
|
|
||||||
Syslog('f', "re_comp() accepted");
|
|
||||||
else
|
|
||||||
Syslog('f', "re_comp() returned NULL");
|
|
||||||
|
|
||||||
while ((de = readdir(dp))) {
|
|
||||||
Match = FALSE;
|
|
||||||
if (strlen(fn) == strlen(de->d_name)) {
|
|
||||||
Match = TRUE;
|
|
||||||
for (i = 0; i < strlen(fn); i++) {
|
|
||||||
switch(fn[i]) {
|
|
||||||
case '?' : break;
|
|
||||||
case '#' : if (!isdigit(de->d_name[i]))
|
|
||||||
Match = FALSE;
|
|
||||||
break;
|
|
||||||
case '@' : if (!isalpha(de->d_name[i]))
|
|
||||||
Match = FALSE;
|
|
||||||
break;
|
|
||||||
default : if (fn[i] != de->d_name[i])
|
|
||||||
Match = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (re_exec(de->d_name))
|
|
||||||
Syslog('f', "%s matched using regexp", de->d_name);
|
|
||||||
else
|
|
||||||
Syslog('f', "%s no match using regexp", de->d_name);
|
|
||||||
|
|
||||||
if (Match) {
|
|
||||||
hatched = TRUE;
|
|
||||||
Syslog('+', "Hatch %s in area %s", de->d_name, hatch.Name);
|
|
||||||
sprintf(tf, "%s/%s", CFG.pinbound, MakeTicName());
|
|
||||||
if ((Tf = fopen(tf, "a+")) == NULL)
|
|
||||||
WriteError("Can't create %s", tf);
|
|
||||||
else {
|
|
||||||
fprintf(Tf, "Hatch\r\n");
|
|
||||||
fprintf(Tf, "Created MBSE BBS v%s, %s\r\n", VERSION, SHORTRIGHT);
|
|
||||||
fprintf(Tf, "Area %s\r\n", hatch.Name);
|
|
||||||
if (SearchTic(hatch.Name)) {
|
|
||||||
fprintf(Tf, "Origin %s\r\n", aka2str(tic.Aka));
|
|
||||||
fprintf(Tf, "From %s\r\n", aka2str(tic.Aka));
|
|
||||||
} else {
|
|
||||||
fprintf(Tf, "Origin %s\r\n", aka2str(CFG.aka[0]));
|
|
||||||
fprintf(Tf, "From %s\r\n", aka2str(CFG.aka[0]));
|
|
||||||
Syslog('?', "Warning: TIC group not found");
|
|
||||||
}
|
|
||||||
if (strlen(hatch.Replace))
|
|
||||||
fprintf(Tf, "Replaces %s\r\n", hatch.Replace);
|
|
||||||
if (strlen(hatch.Magic))
|
|
||||||
fprintf(Tf, "Magic %s\r\n", hatch.Magic);
|
|
||||||
temp2 = calloc(strlen(de->d_name) + 1, sizeof(char));
|
|
||||||
sprintf(temp2, "%s", de->d_name);
|
|
||||||
name_mangle(temp2);
|
|
||||||
fprintf(Tf, "File %s\r\n", temp2);
|
|
||||||
free(temp2);
|
|
||||||
fprintf(Tf, "Fullname %s\r\n", de->d_name);
|
|
||||||
fprintf(Tf, "Pth %s\r\n", temp);
|
|
||||||
fprintf(Tf, "Desc ");
|
|
||||||
for (i = 0; i < strlen(hatch.Desc); i++) {
|
|
||||||
if (hatch.Desc[i] != '%') {
|
|
||||||
fprintf(Tf, "%c", hatch.Desc[i]);
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
memset(&tmp, 0, sizeof(tmp));
|
|
||||||
if (isdigit(hatch.Desc[i]))
|
|
||||||
tmp[0] = hatch.Desc[i];
|
|
||||||
if (isdigit(hatch.Desc[i+1])) {
|
|
||||||
tmp[1] = hatch.Desc[i+1];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
fprintf(Tf, "%c", de->d_name[atoi(tmp) -1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(Tf, "\r\n");
|
|
||||||
fprintf(Tf, "Crc %08lx\r\n", file_crc(de->d_name, CFG.slow_util && do_quiet));
|
|
||||||
fprintf(Tf, "Pw %s\r\n", CFG.hatchpasswd);
|
|
||||||
fclose(Tf);
|
|
||||||
Hatched++;
|
|
||||||
StatAdd(&hatch.Hatched , 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
closedir(dp);
|
|
||||||
free(fn);
|
free(fn);
|
||||||
return hatched;
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((dp = opendir(temp)) == NULL) {
|
||||||
|
WriteError("$Can't opendir(%s)", temp);
|
||||||
|
free(fn);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&mask, 0, sizeof(mask));
|
||||||
|
p = fn;
|
||||||
|
q = mask;
|
||||||
|
*q++ = '^';
|
||||||
|
while ((*p) && (q < (mask + sizeof(mask) - 4))) {
|
||||||
|
switch(*p) {
|
||||||
|
case '\\': *q++ = '\\'; *q++ = '\\'; break;
|
||||||
|
case '?': *q++ = '.'; break;
|
||||||
|
case '.': *q++ = '\\'; *q++ = '.'; break;
|
||||||
|
case '+': *q++ = '\\'; *q++ = '+'; break;
|
||||||
|
case '*': *q++ = '.'; *q++ = '*'; break;
|
||||||
|
case '@': sprintf(q, "[A-Za-z]"); while (*q) q++; break;
|
||||||
|
case '#': sprintf(q, "[0-9]"); while (*q) q++; break;
|
||||||
|
default: *q++ = *p; break;
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
*q++ = '$';
|
||||||
|
*q = '\0';
|
||||||
|
Syslog('f', "Hatch mask \"%s\" -> \"%s\"", MBSE_SS(fn), MBSE_SS(mask));
|
||||||
|
|
||||||
|
if ((re_comp(mask)) == NULL) {
|
||||||
|
tf = calloc(PATH_MAX, sizeof(char));
|
||||||
|
while ((de = readdir(dp))) {
|
||||||
|
if (re_exec(de->d_name)) {
|
||||||
|
hatched = TRUE;
|
||||||
|
Syslog('+', "Hatch %s in area %s", de->d_name, hatch.Name);
|
||||||
|
sprintf(tf, "%s/%s", CFG.pinbound, MakeTicName());
|
||||||
|
|
||||||
|
if ((Tf = fopen(tf, "a+")) == NULL) {
|
||||||
|
WriteError("Can't create %s", tf);
|
||||||
|
} else {
|
||||||
|
fprintf(Tf, "Hatch\r\n");
|
||||||
|
fprintf(Tf, "Created MBSE BBS v%s, %s\r\n", VERSION, SHORTRIGHT);
|
||||||
|
fprintf(Tf, "Area %s\r\n", hatch.Name);
|
||||||
|
if (SearchTic(hatch.Name)) {
|
||||||
|
fprintf(Tf, "Origin %s\r\n", aka2str(tic.Aka));
|
||||||
|
fprintf(Tf, "From %s\r\n", aka2str(tic.Aka));
|
||||||
|
} else {
|
||||||
|
fprintf(Tf, "Origin %s\r\n", aka2str(CFG.aka[0]));
|
||||||
|
fprintf(Tf, "From %s\r\n", aka2str(CFG.aka[0]));
|
||||||
|
Syslog('?', "Warning: TIC group not found");
|
||||||
|
}
|
||||||
|
if (strlen(hatch.Replace))
|
||||||
|
fprintf(Tf, "Replaces %s\r\n", hatch.Replace);
|
||||||
|
if (strlen(hatch.Magic))
|
||||||
|
fprintf(Tf, "Magic %s\r\n", hatch.Magic);
|
||||||
|
temp2 = calloc(strlen(de->d_name) + 1, sizeof(char));
|
||||||
|
sprintf(temp2, "%s", de->d_name);
|
||||||
|
name_mangle(temp2);
|
||||||
|
fprintf(Tf, "File %s\r\n", temp2);
|
||||||
|
free(temp2);
|
||||||
|
fprintf(Tf, "Fullname %s\r\n", de->d_name);
|
||||||
|
fprintf(Tf, "Pth %s\r\n", temp);
|
||||||
|
fprintf(Tf, "Desc ");
|
||||||
|
for (i = 0; i < strlen(hatch.Desc); i++) {
|
||||||
|
if (hatch.Desc[i] != '%') {
|
||||||
|
fprintf(Tf, "%c", hatch.Desc[i]);
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
memset(&tmp, 0, sizeof(tmp));
|
||||||
|
if (isdigit(hatch.Desc[i]))
|
||||||
|
tmp[0] = hatch.Desc[i];
|
||||||
|
if (isdigit(hatch.Desc[i+1])) {
|
||||||
|
tmp[1] = hatch.Desc[i+1];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
fprintf(Tf, "%c", de->d_name[atoi(tmp) -1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(Tf, "\r\n");
|
||||||
|
fprintf(Tf, "Crc %08lx\r\n", file_crc(de->d_name, CFG.slow_util && do_quiet));
|
||||||
|
fprintf(Tf, "Pw %s\r\n", CFG.hatchpasswd);
|
||||||
|
fclose(Tf);
|
||||||
|
Hatched++;
|
||||||
|
StatAdd(&hatch.Hatched , 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(tf);
|
||||||
|
} else {
|
||||||
|
WriteError("Could not create regexp from %s", fn);
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dp);
|
||||||
|
free(fn);
|
||||||
|
return hatched;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,8 +100,7 @@ char *Magic_Macro(int C)
|
|||||||
|
|
||||||
int GetMagicRec(int Typ, int First)
|
int GetMagicRec(int Typ, int First)
|
||||||
{
|
{
|
||||||
int Eof = FALSE, DoMagic = TRUE;
|
int Eof = FALSE;
|
||||||
int i;
|
|
||||||
char *temp, *p, *q, mask[256];
|
char *temp, *p, *q, mask[256];
|
||||||
FILE *FeM;
|
FILE *FeM;
|
||||||
|
|
||||||
@ -154,44 +153,15 @@ int GetMagicRec(int Typ, int First)
|
|||||||
*q++ = '$';
|
*q++ = '$';
|
||||||
*q = '\0';
|
*q = '\0';
|
||||||
Syslog('f', "Magic mask \"%s\" -> \"%s\"", MBSE_SS(magic.Mask), MBSE_SS(mask));
|
Syslog('f', "Magic mask \"%s\" -> \"%s\"", MBSE_SS(magic.Mask), MBSE_SS(mask));
|
||||||
|
|
||||||
if ((re_comp(mask)) == NULL) {
|
if ((re_comp(mask)) == NULL) {
|
||||||
if (re_exec(TIC.NewName))
|
if (re_exec(TIC.NewName)) {
|
||||||
Syslog('f', "Should matched using regexp");
|
fclose(FeM);
|
||||||
else
|
free(temp);
|
||||||
Syslog('f', "No match using regexp");
|
return TRUE;
|
||||||
} else {
|
|
||||||
Syslog('f', "re_comp() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Comparing of the filename must be done in
|
|
||||||
* two parts, before and after the dot.
|
|
||||||
*/
|
|
||||||
if (strlen(magic.Mask) == strlen(TIC.NewName)) {
|
|
||||||
for (i = 0; i < strlen(magic.Mask); i++) {
|
|
||||||
switch (magic.Mask[i]) {
|
|
||||||
case '?': break;
|
|
||||||
case '@': if (!isalpha(TIC.NewName[i]))
|
|
||||||
DoMagic = FALSE;
|
|
||||||
break;
|
|
||||||
case '#': if (!isdigit(TIC.NewName[i]))
|
|
||||||
DoMagic = FALSE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: if (toupper(TIC.NewName[i]) != toupper(magic.Mask[i]))
|
|
||||||
DoMagic = FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DoMagic = FALSE;
|
WriteError("Magic: re_comp(%s) failed", mask);
|
||||||
}
|
|
||||||
|
|
||||||
Syslog('f', "Old test, found %s", DoMagic ? "True":"False");
|
|
||||||
|
|
||||||
if (DoMagic) {
|
|
||||||
fclose(FeM);
|
|
||||||
free(temp);
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user