Updates for mbfile check and rearc

This commit is contained in:
Michiel Broek
2004-03-09 21:42:29 +00:00
parent 126eb3a84f
commit 66fb5827e8
13 changed files with 240 additions and 66 deletions

View File

@@ -146,6 +146,7 @@ pktname.o: ../config.h mbselib.h
mangle.o: ../config.h mbselib.h
sectest.o: ../config.h mbselib.h
proglock.o: ../config.h mbselib.h
magic.o: ../config.h mbselib.h
dostran.o: ../config.h mbselib.h
ftnmsg.o: ../config.h mbselib.h
mbfile.o: ../config.h mbselib.h

115
lib/magic.c Normal file
View File

@@ -0,0 +1,115 @@
/*****************************************************************************
*
* $Id$
* Purpose ...............: Magic filename handling
*
*****************************************************************************
* Copyright (C) 1997-2004
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MBSE BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MBSE BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*****************************************************************************/
#include "../config.h"
#include "mbselib.h"
/*
* Update magic alias with new filename.
*/
void magic_update(char *Alias, char *FileName)
{
char *path;
FILE *fp;
Syslog('f', "magic_update(%s) with %s", Alias, FileName);
if (!strlen(CFG.req_magic)) {
WriteError("No magic filename path configured");
return;
}
path = xstrcpy(CFG.req_magic);
path = xstrcat(path, (char *)"/");
path = xstrcat(path, Alias);
if ((fp = fopen(path, "w")) == NULL) {
WriteError("$Can't create %s", path);
free(path);
return;
}
fprintf(fp, "%s\n", FileName);
fclose(fp);
chmod(path, 0644);
free(path);
}
/*
* Check if magic filename is valid.
*/
int magic_check(char *Alias, char *FileName)
{
char *path;
FILE *fp;
int rc = -1;
Syslog('f', "magic_check(%s, %s)", Alias, FileName);
if (!strlen(CFG.req_magic)) {
WriteError("No magic filename path configured");
return -1;
}
path = xstrcpy(CFG.req_magic);
path = xstrcat(path, (char *)"/");
path = xstrcat(path, Alias);
if ((fp = fopen(path, "r")) == NULL) {
WriteError("$No magic alias %s", path);
free(path);
return -1;
}
free(path);
path = calloc(PATH_MAX, sizeof(char));
fgets(path, PATH_MAX -1, fp);
fclose(fp);
Striplf(path);
if (strcmp(path, FileName) == 0)
rc = 0;
free(path);
return rc;
}
/*
* Get record for a magic alias in area.
*/
long magic_get(char *Name, long AreaNum)
{
return -1;
}

View File

@@ -2441,6 +2441,22 @@ char *re_mask(char *, int); /* Bluid file mask */
/*
* rearc.c
*/
int rearc(char *, char *, int); /* Rearc command */
/*
* magic.c
*/
void magic_update(char *, char *); /* Update magic alias */
int magic_check(char *, char *); /* Check if magic alias exists */
long magic_get(char *, long); /* Get fdb record for magic name */
/************************************************************************
*
* Charset mapping
@@ -2481,12 +2497,6 @@ char *charset_alias_rfc(char *); /* Search RFC alias */
int charset_set_in_out(char *, char *); /* Setup mapping */
/*
* rearc.c
*/
int rearc(char *, char *, int); /* Rearc command */
/****************************************************************************
*