1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/*--------------------------------------------------------------------*/
/* B i n L o g . c */
/* */
/* Part of BinkD project */
/* Binary log implementation */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Copyright (c) 1997 by Fydodor Ustinov */
/* FIDONet 2:5020/79 */
/* FrontDoor stat (c) 1997 A&T Software */
/* 2:5023/8@fidonet */
/* */
/* This program 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 of */
/* the License, or (at your option) any later version. See COPYING. */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* RCS Information */
/*--------------------------------------------------------------------*/
/*
* $Id: binlog.c,v 2.4 2003/04/02 13:12:57 gul Exp $
*
* Revision history:
* $Log: binlog.c,v $
* Revision 2.4 2003/04/02 13:12:57 gul
* Try to use workaround for buggy windows time functions (timezone)
*
* Revision 2.3 2003/03/31 19:35:16 gul
* Clean semaphores usage
*
* Revision 2.2 2003/03/11 09:21:29 gul
* Fixed OS/2 Watcom compilation
*
* Revision 2.1 2003/03/05 13:21:50 gul
* Fix warnings
*
* Revision 2.0 2001/01/10 12:12:37 gul
* Binkd is under CVS again
*
* Revision 0.02 1997/07/11 11:40:19 maxb
* Added FrontDoor aka Bink/+ statistics
*
* Revision 0.01 1997/05/25 18:36:00 ufm
* First revision
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <time.h>
#include <stdio.h>
/*--------------------------------------------------------------------*/
/* Local include files */
/*--------------------------------------------------------------------*/
#include "Config.h"
#include "binlog.h"
#include "sys.h"
#include "readcfg.h"
#include "prothlp.h"
#include "protoco2.h"
#include "assert.h"
#include "sem.h"
/*--------------------------------------------------------------------*/
/* Global definitions */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Global variables */
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* Local variables */
/*--------------------------------------------------------------------*/
#if defined(HAVE_THREADS) || defined(AMIGA)
static MUTEXSEM BLSem; /* =0 removed */
#endif
/*--------------------------------------------------------------------*/
/* void BinLogInit(Void) */
/* */
/* Initialise BinLog semaphore. */
/*--------------------------------------------------------------------*/
void BinLogInit(void) {
InitSem(&BLSem);
}
/*--------------------------------------------------------------------*/
/* void BinLogDeInit(Void) */
/* */
/* Deinitialise BinLog semaphore. */
/*--------------------------------------------------------------------*/
void BinLogDeInit(void) {
CleanSem(&BLSem);
}
/*--------------------------------------------------------------------*/
/* void TLogStat (char*, STATE*) */
/* */
/* Add record to T-Mail style binary log. */
/*--------------------------------------------------------------------*/
void TLogStat (char *status, STATE *state)
{
struct {
u16 fZone;
u16 fNet;
u16 fNode;
u16 fPoint;
u32 fSTime;
u32 fLTime;
u32 fBReceive;
u32 fBSent;
u8 fFReceive;
u8 fFSent;
u16 fStatus;
} TS;
FILE *fl;
if (binlogpath[0]) {
TS.fStatus = 0;
if (state->to) {
TS.fZone = state->to->fa.z;
TS.fNet = state->to->fa.net;
TS.fNode = state->to->fa.node;
TS.fPoint = state->to->fa.p;
TS.fStatus = 1;
} else if (state->fa) {
TS.fZone = state->fa->z;
TS.fNet = state->fa->net;
TS.fNode = state->fa->node;
TS.fPoint = state->fa->p;
TS.fStatus = 2;
} else {
TS.fZone = 0;
TS.fNet = 0;
TS.fNode = 0;
TS.fPoint = 0;
TS.fStatus = 0;
}
TS.fBReceive = state->bytes_rcvd;
TS.fBSent = state->bytes_sent;
TS.fFReceive = state->files_rcvd;
TS.fFSent = state->files_sent;
TS.fSTime = state->start_time + tzoff;
TS.fLTime = safe_time() - state->start_time;
if (STRICMP(status, "OK") != 0) {
TS.fStatus |= 3;
}
if ((fl = fopen(binlogpath,"ab")) != NULL) {
fwrite(&TS,sizeof(TS),1,fl);
fclose(fl);
} else {
Log(1,"unable to open binary log file `%s'",binlogpath);
}
}
}
/*--------------------------------------------------------------------*/
/* void FDLogStat (STATE*) */
/* */
/* Add record to FrontDoor-style binary log. */
/*--------------------------------------------------------------------*/
void FDLogStat (STATE *state)
{
struct
{
u16 Zone;
u16 Net;
u16 Node;
u16 Point;
char Domain[16];
u32 TimeStart;
u32 TimeEnd;
char StationName[32];
char StationLoc[40];
u32 Received;
u32 Sent;
u32 Cost;
} std;
FILE *fp;
time_t t;
if (!state->fa || ((state->to && !fdouthist[0]) || (!state->to && !fdinhist[0])))
return; /* nothing to do */
t = safe_time();
std.TimeStart = (u32)(state->start_time + tzoff);
std.TimeEnd = (u32)(t + tzoff);
std.Zone = state->fa->z;
std.Net = state->fa->net;
std.Node = state->fa->node;
std.Point = state->fa->p;
strnzcpy (std.Domain, state->fa->domain, sizeof (std.Domain));
strnzcpy (std.StationName, state->sysname, sizeof (std.StationName));
strnzcpy (std.StationLoc, state->location, sizeof (std.StationLoc));
std.Received = state->bytes_rcvd;
std.Sent = state->bytes_sent;
std.Cost = 0; /* Let it be free :) */
if (state->to) fp = fopen( fdouthist, "ab+" );
else fp = fopen( fdinhist , "ab+" );
if( fp != NULL )
{
fwrite ( &std, (size_t) sizeof(std), (size_t) 1, fp);
fclose( fp );
}
else Log (1, "failed to write to %s", (state->to ? fdouthist : fdinhist));
}
/*--------------------------------------------------------------------*/
/* void BinLogStat (char*, STATE*) */
/* */
/* Add record to binary logs. */
/*--------------------------------------------------------------------*/
void BinLogStat (char *status, STATE *state)
{
LockSem (&BLSem);
TLogStat (status, state);
FDLogStat (state);
ReleaseSem (&BLSem);
}
|