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/mbcico/call.c

281 lines
7.0 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2002-01-07 19:16:03 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Fidonet mailer
*
*****************************************************************************
2003-01-02 16:44:28 +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 "../lib/libs.h"
#include "../lib/structs.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2001-08-17 05:46:24 +00:00
#include "../lib/records.h"
#include "../lib/common.h"
#include "../lib/nodelist.h"
2001-08-17 05:46:24 +00:00
#include "../lib/clcomm.h"
#include "../lib/dbnode.h"
2002-10-20 20:58:55 +00:00
#include "../lib/mberrors.h"
2001-08-17 05:46:24 +00:00
#include "session.h"
#include "callstat.h"
#include "call.h"
#include "config.h"
#include "dial.h"
#include "lutil.h"
#include "portsel.h"
#include "openport.h"
#include "opentcp.h"
#include "rdoptions.h"
2003-08-23 14:57:51 +00:00
#include "inbound.h"
2001-08-17 05:46:24 +00:00
extern int tcp_mode;
2003-11-24 22:19:50 +00:00
extern int telnet;
2001-08-17 05:46:24 +00:00
extern int immediatecall;
extern char *forcedphone;
extern char *forcedline;
extern char *inetaddr;
2003-01-02 16:44:28 +00:00
extern char *protocol;
2001-08-17 05:46:24 +00:00
int portopen(faddr *addr)
{
char *p;
int rc;
if (inetaddr) {
Syslog('d', "portopen inetaddr %s", inetaddr);
if ((rc = opentcp(inetaddr))) {
Syslog('+', "Cannot connect %s", inetaddr);
nodeulock(addr);
2002-10-20 20:58:55 +00:00
return MBERR_NO_CONNECTION;
2001-08-17 05:46:24 +00:00
}
2002-10-20 20:58:55 +00:00
return MBERR_OK;
}
2001-08-17 05:46:24 +00:00
if (forcedline) {
Syslog('d', "portopen forcedline %s", forcedline);
p = forcedline;
strncpy(history.tty, p, 6);
if (load_port(p)) {
if ((rc = openport(p, ttyinfo.portspeed))) {
Syslog('+', "Cannot open port %s",p);
nodeulock(addr);
2002-10-20 20:58:55 +00:00
putstatus(addr, 10, MBERR_PORTERROR);
return MBERR_PORTERROR;
}
2002-10-20 20:58:55 +00:00
return MBERR_OK;
} else {
nodeulock(addr);
2002-10-20 20:58:55 +00:00
putstatus(addr, 0, MBERR_PORTERROR);
return MBERR_PORTERROR;
2001-08-17 05:46:24 +00:00
}
}
2001-08-17 05:46:24 +00:00
WriteError("No call method available, maybe missing parameters");
2002-10-20 20:58:55 +00:00
return MBERR_NO_CONNECTION;
2001-08-17 05:46:24 +00:00
}
int call(faddr *addr)
{
2003-01-02 16:44:28 +00:00
int rc = 1;
char *p, temp[81];
unsigned long cmmask;
/*
* Don't call points, call their boss instead.
*/
addr->point = 0;
/*
* First check if node is locked, if not lock it immediatly
* or stop further waste of time and logfile space.
*/
if (nodelock(addr)) {
Syslog('+', "System %s is locked", ascfnode(addr, 0x1f));
2002-10-20 20:58:55 +00:00
putstatus(addr, 0, MBERR_NODE_LOCKED);
return MBERR_NODE_LOCKED;
}
if ((nlent = getnlent(addr)) == NULL) {
WriteError("Cannot call %s: fatal in nodelist lookup", ascfnode(addr, 0x1f));
2002-10-20 20:58:55 +00:00
putstatus(addr,0,MBERR_NODE_NOT_IN_LIST);
nodeulock(addr);
2002-10-20 20:58:55 +00:00
return MBERR_NODE_NOT_IN_LIST;
}
/*
* Load the noderecord if the node is in the setup.
*/
noderecord(addr);
rdoptions(TRUE);
cmmask = getCMmask();
/*
* Fill default history info in case we get a FTS0001 session
*/
strncpy(history.system_name, nlent->name, 35);
strncpy(history.location, nlent->location, 35);
strncpy(history.sysop, nlent->sysop, 35);
history.aka.zone = addr->zone;
history.aka.net = addr->net;
history.aka.node = addr->node;
history.aka.point = addr->point;
if (addr->domain && strlen(addr->domain))
sprintf(history.aka.domain, "%s", addr->domain);
/*
2003-01-02 16:44:28 +00:00
* Extract the protocol from the URL.
*/
2003-01-02 16:44:28 +00:00
strncpy(temp, nlent->url, 80);
p = strchr(temp, ':');
*p = '\0';
protocol = xstrcpy(temp);
if (strcasecmp(protocol, "pots") && strcasecmp(protocol, "isdn")) {
if (!inetaddr) {
/*
2003-01-02 16:44:28 +00:00
* Get the internet address from the URL.
*/
2003-01-02 16:44:28 +00:00
p = strchr(nlent->url, '/');
p++;
p++;
inetaddr = xstrcpy(p);
2001-08-17 05:46:24 +00:00
}
2003-01-02 16:44:28 +00:00
RegTCP();
2001-08-17 05:46:24 +00:00
2003-01-02 16:44:28 +00:00
if (tcp_mode == TCPMODE_NONE) {
if (strcmp(protocol, "binkp") == 0) {
tcp_mode = TCPMODE_IBN;
} else if (strcmp(protocol, "fido") == 0) {
tcp_mode = TCPMODE_IFC;
2003-11-22 21:42:44 +00:00
} else if (strcmp(protocol, "telnet") == 0) {
tcp_mode = TCPMODE_ITN;
2003-11-24 22:19:50 +00:00
telnet = TRUE;
2003-01-02 16:44:28 +00:00
} else {
Syslog('+', "No common TCP/IP protocols for node %s", nlent->name);
free(inetaddr);
inetaddr = NULL;
}
2003-01-02 16:44:28 +00:00
}
if (inetaddr == NULL) {
WriteError("No IP address, abort call");
2002-10-20 20:58:55 +00:00
rc = MBERR_NO_IP_ADDRESS;
putstatus(addr, 10, rc);
nodeulock(addr);
return rc;
2001-08-17 05:46:24 +00:00
}
2003-01-02 16:44:28 +00:00
} else {
if (!forcedphone) {
/*
* Get the phone number from the URL.
*/
p = strchr(nlent->url, '/');
p++;
p++;
forcedphone = xstrcpy(p);
}
}
if (((nlent->oflags & cmmask) == 0) && (!IsZMH())) {
Syslog('?', "Warning: calling non-CM system outside ZMH");
}
2003-08-23 14:57:51 +00:00
inbound_open(addr, TRUE); /* master sessions are secure */
/*
* Call when:
2003-01-09 21:02:59 +00:00
* there is a phone number and node is not down, hold or pvt
* or
* there is a fqdn/ip-address and node is not down or hold
* and
* nocall is false
*/
2003-01-09 21:02:59 +00:00
if (((forcedphone && ((nlent->pflag & (NL_DUMMY | NL_DOWN | NL_HOLD | NL_PVT)) == 0)) ||
(inetaddr && ((nlent->pflag & (NL_DUMMY | NL_DOWN | NL_HOLD)) == 0))) && ((localoptions & NOCALL) == 0)) {
2003-01-02 16:44:28 +00:00
Syslog('+', "Calling %s (%s, phone %s)", ascfnode(addr,0x1f), nlent->name, forcedphone);
IsDoing("Call %s", ascfnode(addr, 0x0f));
rc = portopen(addr);
2003-01-02 16:44:28 +00:00
if ((rc == MBERR_OK) && (forcedphone)) {
if ((rc = dialphone(forcedphone))) {
Syslog('+', "Dial failed");
nodeulock(addr);
}
2001-08-17 05:46:24 +00:00
}
2002-10-20 20:58:55 +00:00
if (rc == MBERR_OK) {
if (!inetaddr)
nolocalport();
2001-08-17 05:46:24 +00:00
if (tcp_mode == TCPMODE_IBN)
rc = session(addr,nlent,SESSION_MASTER,SESSION_BINKP,NULL);
else
rc = session(addr,nlent,SESSION_MASTER,SESSION_UNKNOWN,NULL);
}
2001-08-17 05:46:24 +00:00
IsDoing("Disconnect");
if (inetaddr) {
closetcp();
2001-08-17 05:46:24 +00:00
} else {
hangup();
localport();
closeport();
if (strlen(modem.info)) {
/*
* If mode info string defined, open port again to get
* the aftercall information. Mostly used with ISDN.
*/
portopen(addr);
aftercall();
closeport();
}
2001-08-17 05:46:24 +00:00
}
} else {
IsDoing("NoCall");
2003-01-02 16:44:28 +00:00
Syslog('+', "Cannot call %s (%s)", ascfnode(addr,0x1f), MBSE_SS(nlent->name));
2002-10-20 20:58:55 +00:00
rc = MBERR_NO_CONNECTION;
putstatus(addr, 10, rc);
nodeulock(addr);
2001-08-17 05:46:24 +00:00
return rc;
}
2002-10-21 18:29:29 +00:00
if ((rc == MBERR_NOT_ZMH) || (rc == MBERR_SESSION_ERROR)) /* Session error */
putstatus(addr, 5, rc);
else if ((rc == MBERR_NO_CONNECTION) || (rc == MBERR_UNKNOWN_SESSION) || (rc == MBERR_FTRANSFER))
putstatus(addr,1,rc);
else
putstatus(addr,0,rc);
return rc;
2001-08-17 05:46:24 +00:00
}