2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2002-04-25 21:03:54 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Fidonet Address conversions.
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-28 09:42:08 +00:00
|
|
|
* Copyright (C) 1993-2005
|
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 MB 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.
|
|
|
|
*
|
|
|
|
* MB 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 MB 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"
|
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
*
|
|
|
|
* String functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fidonet aka to string, returns Z:N/N@domain or Z:N/N.P@domain
|
|
|
|
*/
|
|
|
|
char *aka2str(fidoaddr aka)
|
|
|
|
{
|
2002-04-25 21:03:54 +00:00
|
|
|
static char result[43];
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-04-25 21:03:54 +00:00
|
|
|
result[0] = '\0';
|
|
|
|
if (strlen(aka.domain)) {
|
2001-08-17 05:46:24 +00:00
|
|
|
if (aka.point == 0)
|
2005-08-28 09:42:08 +00:00
|
|
|
snprintf(result, 42, "%d:%d/%d@%s", aka.zone, aka.net, aka.node, aka.domain);
|
2001-08-17 05:46:24 +00:00
|
|
|
else
|
2005-08-28 09:42:08 +00:00
|
|
|
snprintf(result, 42, "%d:%d/%d.%d@%s", aka.zone, aka.net, aka.node, aka.point, aka.domain);
|
2002-04-25 21:03:54 +00:00
|
|
|
} else {
|
|
|
|
if (aka.point == 0)
|
2005-08-28 09:42:08 +00:00
|
|
|
snprintf(result, 42, "%d:%d/%d", aka.zone, aka.net, aka.node);
|
2002-04-25 21:03:54 +00:00
|
|
|
else
|
2005-08-28 09:42:08 +00:00
|
|
|
snprintf(result, 42, "%d:%d/%d.%d", aka.zone, aka.net, aka.node, aka.point);
|
2002-04-25 21:03:54 +00:00
|
|
|
}
|
|
|
|
return result;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-05-05 17:34:07 +00:00
|
|
|
/*
|
|
|
|
* Try to create a aka structure of a string.
|
|
|
|
*/
|
2001-08-17 05:46:24 +00:00
|
|
|
fidoaddr str2aka(char *addr)
|
|
|
|
{
|
|
|
|
char a[256];
|
|
|
|
static char b[43];
|
2002-05-05 17:34:07 +00:00
|
|
|
char *p, *temp = NULL;
|
|
|
|
static fidoaddr n;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
n.zone = 0;
|
|
|
|
n.net = 0;
|
|
|
|
n.node = 0;
|
|
|
|
n.point = 0;
|
|
|
|
n.domain[0] = '\0';
|
|
|
|
|
2002-05-05 17:34:07 +00:00
|
|
|
/*
|
|
|
|
* Safety check
|
|
|
|
*/
|
|
|
|
if (strlen(addr) > 42)
|
|
|
|
return n;
|
|
|
|
|
2005-08-28 09:42:08 +00:00
|
|
|
snprintf(b, 42, "%s~", addr);
|
2002-05-05 17:34:07 +00:00
|
|
|
if ((strchr(b, ':') == NULL) || (strchr(b, '/') == NULL))
|
2001-08-17 05:46:24 +00:00
|
|
|
return n;
|
|
|
|
|
2002-05-05 17:34:07 +00:00
|
|
|
/*
|
|
|
|
* First split the f:n/n.p and domain part
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2002-05-05 17:34:07 +00:00
|
|
|
if ((strchr(b, '@'))) {
|
|
|
|
temp = strtok(b, "@");
|
|
|
|
p = strtok(NULL, "~");
|
|
|
|
if (p)
|
|
|
|
strcpy(n.domain, p);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-05-05 17:34:07 +00:00
|
|
|
/*
|
|
|
|
* Handle f:n/n.p part
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2002-05-05 17:34:07 +00:00
|
|
|
if (temp)
|
|
|
|
strcpy(a, strcat(temp, "~"));
|
|
|
|
else
|
|
|
|
strcpy(a, b);
|
2001-08-17 05:46:24 +00:00
|
|
|
if (strchr(a, '.') == NULL) {
|
|
|
|
n.zone = atoi(strtok(a, ":"));
|
|
|
|
n.net = atoi(strtok(NULL, "/"));
|
|
|
|
n.node = atoi(strtok(NULL, "~"));
|
|
|
|
} else {
|
|
|
|
n.zone = atoi(strtok(a, ":"));
|
|
|
|
n.net = atoi(strtok(NULL, "/"));
|
|
|
|
n.node = atoi(strtok(NULL, "."));
|
|
|
|
n.point = atoi(strtok(NULL, "~"));
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|