/*****************************************************************************
 *
 * File ..................: mbcico/callstat.c
 * Purpose ...............: Fidonet mailer
 * Last modification date : 07-Nov-1999
 *
 *****************************************************************************
 * Copyright (C) 1997-1999
 *   
 * Michiel Broek		FIDO:		2:2801/16
 * Beekmansbos 10		Internet:	mbroek@ux123.pttnwb.nl
 * 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
 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *****************************************************************************/

#include "../include/libs.h"
#include "../include/structs.h"
#include "../include/records.h"
#include "../common/common.h"
#include "callstat.h"




static callstat st;

callstat *getstatus(faddr *addr)
{
	FILE *fp;

	st.trytime=0L;
	st.tryno=0;
	st.trystat=0;

	if ((fp=fopen(stsname(addr),"r"))) {
		fscanf(fp,"%lu %u %u",&st.trytime,&st.tryno,&st.trystat);
		fclose(fp);
	}

	return &st;
}



void putstatus(faddr *addr, int incr, int sts)
{
	FILE *fp;

	(void)getstatus(addr);
	if ((fp=fopen(stsname(addr),"w"))) {
		if (sts == 0) 
			st.tryno=0;
		else 
			st.tryno+=incr;
		st.trystat=sts;
		(void)time(&st.trytime);
		fprintf(fp,"%lu %u %u\n",
			st.trytime,st.tryno,(unsigned)st.trystat);
		fclose(fp);
		if (st.tryno >= 30)
			WriteError("Node %s is marked undialble.", ascfnode(addr, 0x1f));
	} else {
		WriteError("$Cannot create status file for node %s",
			ascfnode(addr,0x1f));
	}
}


