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

158 lines
3.9 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2002-01-07 19:16:03 +00:00
* $Id$
* Purpose ...............: Fidonet mailer - awnser a call
2001-08-17 05:46:24 +00:00
*
*****************************************************************************
2005-08-28 11:34:24 +00:00
* Copyright (C) 1997-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 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 17:22:00 +00:00
#include "../lib/mbselib.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
#include "../lib/nodelist.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbsedb.h"
2001-08-17 05:46:24 +00:00
#include "lutil.h"
#include "session.h"
#include "config.h"
#include "answer.h"
#include "openport.h"
#include "portsel.h"
#include "dial.h"
#include "rdoptions.h"
#include "mbcico.h"
extern int carrier, online;
extern time_t c_start, c_end;
2005-10-11 20:49:41 +00:00
extern unsigned int sentbytes;
extern unsigned int rcvdbytes;
2001-08-17 05:46:24 +00:00
extern int Loaded;
int answer(char *stype)
{
2002-10-20 20:58:55 +00:00
int st, rc;
char *p, *q;
FILE *fp;
/*
* mgetty set's the environment variable CONNECT and CALLER_ID,
* so if they are present, we might as well make log entries.
*/
if ((q = getenv("CONNECT")) != NULL)
Syslog('+', "CONNECT %s", q);
if ((q = getenv("CALLER_ID")) != NULL)
if (strncmp(q, "none", 4))
Syslog('+', "CALLER %s", q);
/*
* Incoming calls from modem/ISDN lines do have a tty.
* Network calls don't have a tty attached.
*/
carrier = TRUE;
p = ttyname(0);
if (p) {
q = strrchr(ttyname(0), '/');
if (q)
p = q + 1;
strncpy(history.tty, p, 6);
if (load_port(p))
Syslog('d', "Port %s, modem %s", ttyinfo.tty, modem.modem);
else
Syslog('d', "Port and modem not loaded!");
}
if ((nlent = getnlent(NULL)) == NULL) {
WriteError("could not get dummy nodelist entry");
return MBERR_NODE_NOT_IN_LIST;
}
c_start = time(NULL);
rdoptions(FALSE);
if (stype == NULL) {
st=SESSION_UNKNOWN;
} else if (strcmp(stype,"tsync") == 0) {
st=SESSION_FTSC;
IsDoing("Answer ftsc");
} else if (strcmp(stype,"yoohoo") == 0) {
st=SESSION_YOOHOO;
IsDoing("Answer yoohoo");
} else if (strncmp(stype,"**EMSI_",7) == 0) {
st=SESSION_EMSI;
IsDoing("Answer EMSI");
} else if (strncmp(stype,"ibn",3) == 0) {
st=SESSION_BINKP;
IsDoing("Answer binkp");
} else {
st=SESSION_UNKNOWN;
IsDoing("Answer unknown");
}
if ((rc = rawport()) != 0)
WriteError("Unable to set raw mode");
else {
nolocalport();
rc = session(NULL,NULL,SESSION_SLAVE,st,stype);
}
cookedport();
if (p) {
2001-08-17 05:46:24 +00:00
/*
2002-10-20 20:58:55 +00:00
* Hangup will write the history record.
2001-08-17 05:46:24 +00:00
*/
2002-10-20 20:58:55 +00:00
hangup();
} else {
2001-08-17 05:46:24 +00:00
/*
2002-10-20 20:58:55 +00:00
* Network call, write history record.
2001-08-17 05:46:24 +00:00
*/
2002-10-20 20:58:55 +00:00
c_end = time(NULL);
online += (c_end - c_start);
2005-10-16 11:37:54 +00:00
history.online = (int)c_start;
history.offline = (int)c_end;
2002-10-20 20:58:55 +00:00
history.sent_bytes = sentbytes;
history.rcvd_bytes = rcvdbytes;
history.inbound = TRUE;
p = calloc(PATH_MAX, sizeof(char));
2005-08-28 11:34:24 +00:00
snprintf(p, PATH_MAX -1, "%s/var/mailer.hist", getenv("MBSE_ROOT"));
2002-10-20 20:58:55 +00:00
if ((fp = fopen(p, "a")) == NULL)
WriteError("$Can't open %s", p);
2001-08-17 05:46:24 +00:00
else {
2002-10-20 20:58:55 +00:00
fwrite(&history, sizeof(history), 1, fp);
fclose(fp);
2001-08-17 05:46:24 +00:00
}
2002-10-20 20:58:55 +00:00
free(p);
if (Loaded) {
2005-10-16 11:37:54 +00:00
nodes.LastDate = (int32_t)time(NULL);
2002-10-20 20:58:55 +00:00
UpdateNode();
2001-08-17 05:46:24 +00:00
}
2002-10-20 20:58:55 +00:00
}
return rc;
2001-08-17 05:46:24 +00:00
}