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/dial.c

165 lines
3.9 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 ...............: Fidonet mailer
*
*****************************************************************************
2002-01-07 19:16:03 +00:00
* Copyright (C) 1997-2002
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 "config.h"
#include "chat.h"
#include "ttyio.h"
#include "session.h"
#include "dial.h"
extern time_t c_start;
extern time_t c_end;
extern int online;
extern int master;
int carrier;
extern long sentbytes;
extern long rcvdbytes;
extern int Loaded;
2001-08-17 05:46:24 +00:00
int initmodem(void)
{
int i;
for (i = 0; i < 3; i++)
if (strlen(modem.init[i]))
if (chat(modem.init[i], CFG.timeoutreset, FALSE, NULL)) {
WriteError("dial: could not reset the modem");
2002-10-20 20:58:55 +00:00
return MBERR_MODEM_ERROR;
}
2002-10-20 20:58:55 +00:00
return MBERR_OK;
2001-08-17 05:46:24 +00:00
}
int dialphone(char *Phone)
{
int rc;
Syslog('+', "dial: %s (%s)",MBSE_SS(Phone), MBSE_SS(tranphone(Phone)));
carrier = FALSE;
if (initmodem())
2002-10-20 20:58:55 +00:00
return MBERR_MODEM_ERROR;
rc = 0;
if (strlen(nodes.phone[0])) {
if (strlen(nodes.dial))
rc = chat(nodes.dial, CFG.timeoutconnect, FALSE, nodes.phone[0]);
else
rc = chat(modem.dial, CFG.timeoutconnect, FALSE, nodes.phone[0]);
if ((rc == 0) && strlen(nodes.phone[1])) {
if (strlen(nodes.dial))
rc = chat(nodes.dial, CFG.timeoutconnect, FALSE, nodes.phone[1]);
else
rc = chat(modem.dial, CFG.timeoutconnect, FALSE, nodes.phone[1]);
2001-08-17 05:46:24 +00:00
}
} else {
if (strlen(nodes.dial))
rc = chat(nodes.dial, CFG.timeoutconnect, FALSE, Phone);
else
rc = chat(modem.dial, CFG.timeoutconnect, FALSE, Phone);
}
if (rc) {
Syslog('+', "Could not connect to the remote");
2002-10-20 20:58:55 +00:00
return MBERR_NO_CONNECTION;
} else {
c_start = time(NULL);
carrier = TRUE;
2002-10-20 20:58:55 +00:00
return MBERR_OK;
}
2001-08-17 05:46:24 +00:00
}
int hangup()
{
char *tmp;
FILE *fp;
FLUSHIN();
FLUSHOUT();
if (strlen(modem.hangup))
chat(modem.hangup, CFG.timeoutreset, FALSE, NULL);
if (carrier) {
c_end = time(NULL);
online += (c_end - c_start);
Syslog('+', "Connection time %s", t_elapsed(c_start, c_end));
carrier = FALSE;
history.offline = c_end;
history.online = c_start;
history.sent_bytes = sentbytes;
history.rcvd_bytes = rcvdbytes;
history.inbound = ~master;
tmp = calloc(128, sizeof(char));
sprintf(tmp, "%s/var/mailer.hist", getenv("MBSE_ROOT"));
if ((fp = fopen(tmp, "a")) == NULL)
WriteError("$Can't open %s", tmp);
else {
fwrite(&history, sizeof(history), 1, fp);
fclose(fp);
2001-08-17 05:46:24 +00:00
}
free(tmp);
memset(&history, 0, sizeof(history));
if (Loaded) {
nodes.LastDate = time(NULL);
UpdateNode();
}
}
FLUSHIN();
FLUSHOUT();
2002-10-20 20:58:55 +00:00
return MBERR_OK;
2001-08-17 05:46:24 +00:00
}
void aftercall()
2001-08-17 05:46:24 +00:00
{
Syslog('d', "Reading link stat (aftercall)");
FLUSHIN();
FLUSHOUT();
chat(modem.info, CFG.timeoutreset, TRUE, NULL);
2001-08-17 05:46:24 +00:00
}