This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/lib/pktname.c

294 lines
6.2 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2001-12-23 16:44:18 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: BinkleyTerm outbound naming
*
*****************************************************************************
2003-12-04 22:07:33 +00:00
* Copyright (C) 1997-2003
2001-08-17 05:46:24 +00:00
*
* 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
2003-08-15 20:05:34 +00:00
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
2001-08-17 05:46:24 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2001-08-17 05:46:24 +00:00
#include "libs.h"
#include "structs.h"
2002-01-07 19:16:03 +00:00
#include "users.h"
2001-08-17 05:46:24 +00:00
#include "records.h"
#include "clcomm.h"
#include "common.h"
#ifndef PATH_MAX
#define PATH_MAX 512
#endif
#define ptyp "ut"
#define ftyp "lo"
#define ttyp "pk"
#define rtyp "req"
#define styp "spl"
#define btyp "bsy"
#define qtyp "sts"
#define ltyp "pol"
2003-12-04 22:07:33 +00:00
char *prepbuf(faddr *);
2001-08-17 05:46:24 +00:00
char *prepbuf(faddr *addr)
{
2003-12-04 22:07:33 +00:00
static char buf[PATH_MAX];
char *p, *domain=NULL, zpref[8];
int i;
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
sprintf(buf, "%s", CFG.outbound);
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
if (CFG.addr4d) {
Syslog('o', "Use 4d addressing, zone is %d", addr->zone);
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
if ((addr->zone == 0) || (addr->zone == CFG.aka[0].zone))
zpref[0] = '\0';
else
sprintf(zpref, ".%03x", addr->zone);
} else {
/*
* If we got a 5d address we use the given domain, if
* we got a 4d address, we look for a matching domain name.
*/
if (addr && addr->domain && strlen(addr->domain)) {
domain = xstrcpy(addr->domain);
} else
for (i = 0; i < 40; i++)
if (CFG.aka[i].zone == addr->zone) {
domain = xstrcpy(CFG.aka[i].domain);
break;
2001-08-17 05:46:24 +00:00
}
2003-12-04 22:07:33 +00:00
if ((domain != NULL) && (strlen(CFG.aka[0].domain) != 0) && (strcasecmp(domain,CFG.aka[0].domain) != 0)) {
if ((p = strrchr(buf,'/')))
p++;
else
p = buf;
strcpy(p, domain);
for (; *p; p++)
*p = tolower(*p);
for (i = 0; i < 40; i++)
if ((strlen(CFG.aka[i].domain)) && (strcasecmp(CFG.aka[i].domain, domain) == 0))
break;
/*
* The default zone must be the first one in the
* setup, other zones get the hexadecimal zone
* number appended.
*/
if (CFG.aka[i].zone == addr->zone)
zpref[0] = '\0';
else
sprintf(zpref, ".%03x", addr->zone);
} else {
/*
* this is our primary domain
*/
if ((addr->zone == 0) || (addr->zone == CFG.aka[0].zone))
zpref[0]='\0';
else
sprintf(zpref,".%03x",addr->zone);
2001-08-17 05:46:24 +00:00
}
2003-12-04 22:07:33 +00:00
}
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
p = buf + strlen(buf);
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
if (addr->point)
sprintf(p,"%s/%04x%04x.pnt/%08x.", zpref,addr->net,addr->node,addr->point);
else
sprintf(p,"%s/%04x%04x.",zpref,addr->net,addr->node);
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
if (domain)
free(domain);
return buf;
2001-08-17 05:46:24 +00:00
}
char *pktname(faddr *addr, char flavor)
{
2003-12-04 22:07:33 +00:00
static char *p, *q;
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
p = prepbuf(addr);
if (flavor == 'f')
flavor = 'o';
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
q = p + strlen(p);
sprintf(q, "%c%s", flavor, ptyp);
Syslog('O', "packet name is \"%s\"", p);
return p;
2001-08-17 05:46:24 +00:00
}
char *floname(faddr *addr, char flavor)
{
2003-12-04 22:07:33 +00:00
static char *p, *q;
p = prepbuf(addr);
if (flavor == 'o')
flavor = 'f';
q = p + strlen(p);
sprintf(q, "%c%s", flavor, ftyp);
Syslog('O', "flo file name is \"%s\"", p);
return p;
2001-08-17 05:46:24 +00:00
}
char *reqname(faddr *addr)
{
2003-12-04 22:07:33 +00:00
static char *p, *q;
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
p = prepbuf(addr);
q = p + strlen(p);
sprintf(q, "%s", rtyp);
Syslog('O', "req file name is \"%s\"", p);
return p;
2001-08-17 05:46:24 +00:00
}
char *splname(faddr *addr)
{
2003-12-04 22:07:33 +00:00
static char *p, *q;
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
p = prepbuf(addr);
q = p + strlen(p);
sprintf(q, "%s", styp);
Syslog('O', "spl file name is \"%s\"", p);
return p;
2001-08-17 05:46:24 +00:00
}
char *bsyname(faddr *addr)
{
2003-12-04 22:07:33 +00:00
static char *p, *q;
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
p = prepbuf(addr);
q = p + strlen(p);
sprintf(q, "%s", btyp);
Syslog('O', "bsy file name is \"%s\"", p);
return p;
2001-08-17 05:46:24 +00:00
}
char *stsname(faddr *addr)
{
2003-12-04 22:07:33 +00:00
static char *p, *q;
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
p = prepbuf(addr);
q = p + strlen(p);
sprintf(q, "%s", qtyp);
Syslog('O', "sts file name is \"%s\"", p);
return p;
2001-08-17 05:46:24 +00:00
}
char *polname(faddr *addr)
{
2003-12-04 22:07:33 +00:00
static char *p, *q;
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
p = prepbuf(addr);
q = p + strlen(p);
sprintf(q, "%s", ltyp);
Syslog('O', "pol file name is \"%s\"", p);
return p;
2001-08-17 05:46:24 +00:00
}
static char *dow[] = {(char *)"su", (char *)"mo", (char *)"tu", (char *)"we",
(char *)"th", (char *)"fr", (char *)"sa"};
char *dayname(void)
{
2003-12-04 22:07:33 +00:00
time_t tt;
struct tm *ptm;
static char buf[3];
tt = time(NULL);
ptm = localtime(&tt);
sprintf(buf, "%s", dow[ptm->tm_wday]);
return buf;
2001-08-17 05:46:24 +00:00
}
char *arcname(faddr *addr, unsigned short Zone, int ARCmailCompat)
{
2003-12-04 22:07:33 +00:00
static char *buf;
2001-08-17 05:46:24 +00:00
char *p;
char *ext;
time_t tt;
struct tm *ptm;
faddr *bestaka;
2001-12-23 16:44:18 +00:00
tt = time(NULL);
2001-08-17 05:46:24 +00:00
ptm = localtime(&tt);
ext = dow[ptm->tm_wday];
bestaka = bestaka_s(addr);
2003-12-04 22:07:33 +00:00
buf = prepbuf(addr);
2001-08-17 05:46:24 +00:00
p = strrchr(buf, '/');
if (!ARCmailCompat && (Zone != addr->zone)) {
/*
* Generate ARCfile name from the CRC of the ASCII string
* of the node address.
*/
sprintf(p, "/%08lx.%s0", StringCRC32(ascfnode(addr, 0x1f)), ext);
} else {
if (addr->point) {
sprintf(p, "/%04x%04x.%s0",
((bestaka->net) - (addr->net)) & 0xffff,
((bestaka->node) - (addr->node) + (addr->point)) & 0xffff,
ext);
} else if (bestaka->point) {
/*
* Inserted the next code for if we are a point,
* I hope this is ARCmail 0.60 compliant. 21-May-1999
*/
sprintf(p, "/%04x%04x.%s0", ((bestaka->net) - (addr->net)) & 0xffff,
((bestaka->node) - (addr->node) - (bestaka->point)) & 0xffff, ext);
} else {
sprintf(p, "/%04x%04x.%s0", ((bestaka->net) - (addr->net)) & 0xffff,
((bestaka->node) - (addr->node)) &0xffff, ext);
}
}
2003-12-08 18:01:25 +00:00
tidy_faddr(bestaka);
2001-08-17 05:46:24 +00:00
Syslog('O', "Arc file name is \"%s\"", buf);
return buf;
}