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

292 lines
6.1 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
*
*****************************************************************************
2007-02-03 12:18:41 +00:00
* Copyright (C) 1997-2007
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"
2004-02-21 14:24:03 +00:00
#include "mbselib.h"
#include "users.h"
#include "mbsedb.h"
2001-08-17 05:46:24 +00:00
#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
2005-08-27 18:53:32 +00:00
snprintf(buf, PATH_MAX -1, "%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
2005-08-28 13:34:43 +00:00
snprintf(zpref, 8, ".%03x", addr->zone);
2003-12-04 22:07:33 +00:00
} 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 {
domain = xstrcpy(GetFidoDomain(addr->zone));
}
2003-12-04 22:07:33 +00:00
2007-02-03 12:18:41 +00:00
/*
* If we got a 2d address, add the default zone.
*/
if (addr->zone == 0 ) {
addr->zone = CFG.aka[0].zone;
}
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
2005-08-28 13:34:43 +00:00
snprintf(zpref, 8, ".%03x", addr->zone);
2003-12-04 22:07:33 +00:00
} else {
/*
* this is our primary domain
*/
if ((addr->zone == 0) || (addr->zone == CFG.aka[0].zone))
zpref[0]='\0';
else
2005-08-28 13:34:43 +00:00
snprintf(zpref, 8, ".%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)
2005-08-27 18:53:32 +00:00
snprintf(p, PATH_MAX -1, "%s/%04x%04x.pnt/%08x.", zpref,addr->net,addr->node,addr->point);
2003-12-04 22:07:33 +00:00
else
2005-08-27 18:53:32 +00:00
snprintf(p, PATH_MAX -1, "%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';
if (flavor == 'i')
flavor = 'd';
2001-08-17 05:46:24 +00:00
2003-12-04 22:07:33 +00:00
q = p + strlen(p);
2005-08-27 18:53:32 +00:00
snprintf(q, PATH_MAX -1, "%c%s", flavor, ptyp);
2003-12-04 22:07:33 +00:00
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';
if (flavor == 'i')
flavor = 'd';
2003-12-04 22:07:33 +00:00
q = p + strlen(p);
2005-08-27 18:53:32 +00:00
snprintf(q, PATH_MAX -1, "%c%s", flavor, ftyp);
2003-12-04 22:07:33 +00:00
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);
2005-08-27 18:53:32 +00:00
snprintf(q, PATH_MAX -1, "%s", rtyp);
2003-12-04 22:07:33 +00:00
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);
2005-08-27 18:53:32 +00:00
snprintf(q, PATH_MAX -1, "%s", styp);
2003-12-04 22:07:33 +00:00
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);
2005-08-27 18:53:32 +00:00
snprintf(q, PATH_MAX -1, "%s", btyp);
2003-12-04 22:07:33 +00:00
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);
2005-08-27 18:53:32 +00:00
snprintf(q, PATH_MAX -1, "%s", qtyp);
2003-12-04 22:07:33 +00:00
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);
2005-08-27 18:53:32 +00:00
snprintf(q, PATH_MAX -1, "%s", ltyp);
2003-12-04 22:07:33 +00:00
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);
2005-08-28 13:34:43 +00:00
snprintf(buf, 3, "%s", dow[ptm->tm_wday]);
2003-12-04 22:07:33 +00:00
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.
*/
2005-10-11 20:49:41 +00:00
snprintf(p, PATH_MAX -1, "/%08x.%s0", StringCRC32(ascfnode(addr, 0x1f)), ext);
2001-08-17 05:46:24 +00:00
} else {
if (addr->point) {
2005-08-27 18:53:32 +00:00
snprintf(p, PATH_MAX -1, "/%04x%04x.%s0",
2001-08-17 05:46:24 +00:00
((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
*/
2005-08-27 18:53:32 +00:00
snprintf(p, PATH_MAX -1, "/%04x%04x.%s0", ((bestaka->net) - (addr->net)) & 0xffff,
2001-08-17 05:46:24 +00:00
((bestaka->node) - (addr->node) - (bestaka->point)) & 0xffff, ext);
} else {
2005-08-27 18:53:32 +00:00
snprintf(p, PATH_MAX -1, "/%04x%04x.%s0", ((bestaka->net) - (addr->net)) & 0xffff,
2001-08-17 05:46:24 +00:00
((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
return buf;
}