home *** CD-ROM | disk | FTP | other *** search
- /* Original by Andrew Kopp, modified by John Bickers */
- /* small mods for logging device, unit, and failed messages by Steve Drew */
-
- #include "includes.h"
-
- Prototype void xferinit (char *);
- Prototype void xferstat (char *phonenum, char *comment);
- Prototype void xferlog (char *, ...);
-
- Prototype XferStat xfer;
-
- XferStat xfer;
-
- static const char
- statname [] = "UUSpool:XferStat";
-
- void
- xferinit (char *host)
- {
- time_t
- t;
- char
- proto [sizeof (xfer.proto)];
-
- memcpy (proto, xfer.proto, sizeof (proto));
- memset (&xfer, 0, sizeof (xfer));
- memcpy (xfer.proto, proto, sizeof (xfer.proto));
- strncpy (xfer.host, host, sizeof (xfer.host) - 1);
- t = time (NULL);
- xfer.time_start = t;
- xfer.time_stop = t;
-
- return;
- }
-
- void
- xferstat (char *phonenum, char *comment)
- {
- FILE
- *fo;
- struct tm
- st,
- et;
- long
- hh,
- mm,
- ss,
- calc,
- fcalc,
- perc;
-
- if (xfer.flags & XFERF_WRITTEN)
- return;
-
- fo = fopen (statname, "a");
- if (!fo)
- return;
-
- xfer.flags |= XFERF_WRITTEN; /* indicate output done */
-
- /* Indicator for type of link */
- fprintf (fo, "%c %-8s ", (xfer.flags & XFERF_OUTGOING) ? '<' : '>', xfer.host);
-
- st = *localtime (&xfer.time_start);
- et = *localtime (&xfer.time_stop);
-
- fprintf (fo, "%02d-%02d-%02d %02d:%02d:%02d > ",
- st.tm_mday, st.tm_mon + 1, st.tm_year,
- st.tm_hour, st.tm_min, st.tm_sec);
- fprintf (fo, "%02d-%02d-%02d %02d:%02d:%02d ",
- et.tm_mday, et.tm_mon + 1, et.tm_year,
- et.tm_hour, et.tm_min, et.tm_sec);
-
- hh = et.tm_hour - st.tm_hour;
- if (hh < 0)
- hh += 24;
- mm = et.tm_min - st.tm_min;
- ss = et.tm_sec - st.tm_sec;
- if (ss < 0) {
- ss += 60;
- mm--;
- }
- if (mm < 0) {
- mm += 60;
- hh--;
- }
- if (hh < 0)
- hh += 24;
-
- fprintf (fo, "(%02d:%02d:%02d)", hh, mm, ss);
-
- ss += (hh * 3600L) + (mm * 60L);
-
- calc = xfer.bytes_recv + xfer.bytes_send;
- calc = ss ? (calc / ss) : 0L;
- fprintf (fo, "%6ld", calc);
-
- fcalc = xfer.fbytes_recv + xfer.fbytes_send;
- fcalc = ss ? (fcalc / ss) : 0L;
- fprintf (fo," %6ld", fcalc);
-
- perc = calc ? ((100 * fcalc) / calc) : 0L;
- fprintf (fo, " %3ld%%\n", perc);
-
- switch (xfer.proto [0]) {
- case ('g'):
- case ('G'):
- {
- int
- psize;
-
- psize = (1 << (xfer.proto [2] + 4));
- fprintf (fo, "| %c %1d %4d", xfer.proto [0], xfer.proto [1], psize);
- }
- break;
- default:
- fprintf (fo, "| %c ", xfer.proto [0]);
- }
-
- fprintf (fo, " %8ld %8ld # %8ld %8ld # %4ld %4ld\n",
- xfer.bytes_recv, xfer.bytes_send,
- xfer.fbytes_recv, xfer.fbytes_send,
- xfer.files_recv, xfer.files_send
- );
-
- /*
- * serial port, and comment passed from uucico mods by Steve Drew
- */
-
- fprintf (fo, "| VIA device %s unit %d", DeviceName, DeviceUnit);
- if (phonenum) {
- fprintf (fo, " number %s\n", phonenum);
- }
- else {
- fprintf (fo, "\n");
- }
-
- if (comment) {
- fprintf (fo, "%s\n", comment);
- }
-
- fclose (fo);
-
- return;
- }
-
- /* Perhaps put file handle into xfer? */
- void
- xferlog (char *cp, ...)
- {
- FILE
- *fo;
- va_list
- args;
-
- if (cp && (fo = fopen (statname, "a"))) {
- va_start (args,cp);
- vfprintf (fo, cp, args)
- va_end (args);
- fclose (fo);
- }
-
- return;
- }
-