2019-11-23 03:40:23 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2019 by John D. Robertson *
|
|
|
|
* john@rrci.com *
|
|
|
|
* *
|
|
|
|
* 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 3 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
#ifndef LOGFILE_H
|
|
|
|
#define LOGFILE_H
|
|
|
|
|
2019-12-03 02:56:55 +00:00
|
|
|
#define _GNU_SOURCE
|
2019-11-23 03:40:23 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "logType.h"
|
|
|
|
#include "map.h"
|
|
|
|
|
|
|
|
/* One of these for each log file which is scanned. */
|
|
|
|
typedef struct _LOGFILE {
|
|
|
|
int flags;
|
2019-12-03 02:56:55 +00:00
|
|
|
char *logFname;
|
|
|
|
struct {
|
|
|
|
MAP offEntry_map,
|
|
|
|
obsvTpl_map;
|
|
|
|
} addr; /* addr denotes the map keys */
|
2019-11-23 03:40:23 +00:00
|
|
|
unsigned nOffenses;
|
|
|
|
} LOGFILE;
|
|
|
|
|
2019-12-03 02:56:55 +00:00
|
|
|
#define LOGFILE_logFname(self) \
|
|
|
|
(const char*)(self)->logFname
|
2019-12-02 03:29:32 +00:00
|
|
|
|
2019-11-23 03:40:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-12-03 02:56:55 +00:00
|
|
|
#define LOGFILE_cache_create(s, cacheFname, logFname) \
|
|
|
|
((s)=(LOGFILE_cache_constructor((s)=malloc(sizeof(LOGFILE)), cacheFname, logFname) ? (s) : ( s ? realloc(LOGFILE_destructor(s),0) : 0 )))
|
2019-11-23 03:40:23 +00:00
|
|
|
LOGFILE*
|
2019-12-03 02:56:55 +00:00
|
|
|
LOGFILE_cache_constructor(
|
|
|
|
LOGFILE *self,
|
|
|
|
const char *cacheFname,
|
|
|
|
const char *logFname
|
|
|
|
);
|
2019-11-23 03:40:23 +00:00
|
|
|
/******************************************************************
|
|
|
|
* Initialize an instance of a LOGFILE class.
|
|
|
|
*/
|
|
|
|
|
2019-12-03 02:56:55 +00:00
|
|
|
#define LOGFILE_log_create(s, h_protoType, logFname) \
|
|
|
|
((s)=(LOGFILE_log_constructor((s)=malloc(sizeof(LOGFILE)), h_protoType, logFname) ? (s) : ( s ? realloc(LOGFILE_destructor(s),0) : 0 )))
|
2019-11-23 03:40:23 +00:00
|
|
|
LOGFILE*
|
2019-12-03 02:56:55 +00:00
|
|
|
LOGFILE_log_constructor(
|
|
|
|
LOGFILE *self,
|
|
|
|
const struct logProtoType *h_protoType,
|
|
|
|
const char *logFname
|
|
|
|
);
|
2019-11-23 03:40:23 +00:00
|
|
|
/******************************************************************
|
|
|
|
* Initialize an instance of a LOGFILE class.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOGFILE_destroy(s) \
|
|
|
|
{if(LOGFILE_destructor(s)) {free(s);(s)=0;}}
|
|
|
|
LOGFILE*
|
|
|
|
LOGFILE_destructor(LOGFILE *self);
|
|
|
|
/******************************************************************
|
|
|
|
* Free resources associated with a LOGFILE object.
|
|
|
|
*/
|
|
|
|
|
2019-12-03 02:56:55 +00:00
|
|
|
#if 0
|
2019-11-23 03:40:23 +00:00
|
|
|
void
|
2019-12-03 02:56:55 +00:00
|
|
|
LOGFILE_set_logFname(LOGFILE *self, const char *path);
|
2019-11-23 03:40:23 +00:00
|
|
|
/******************************************************************
|
|
|
|
* Set the log file name by making a copy of the path.
|
|
|
|
*/
|
2019-12-03 02:56:55 +00:00
|
|
|
#endif
|
2019-11-23 03:40:23 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
LOGFILE_writeCache(LOGFILE *self, const char *fname);
|
|
|
|
/******************************************************************
|
|
|
|
* Create a cache file and dump contents of this object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
LOGFILE_print(LOGFILE *self, FILE *fh);
|
|
|
|
/********************************************************
|
|
|
|
* Print a human readable representation of *self.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
LOGFILE_map_addr(LOGFILE *self, MAP *h_rtnMap);
|
|
|
|
/********************************************************
|
2019-12-02 03:29:32 +00:00
|
|
|
* Create a map of OFFENTRY objects with composite
|
2019-11-23 03:40:23 +00:00
|
|
|
* counts by address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
LOGFILE_offenseCount(LOGFILE *self, unsigned *h_sum);
|
|
|
|
/********************************************************
|
|
|
|
* Get a count of all offenses for this file.
|
|
|
|
*/
|
|
|
|
|
2019-11-27 19:17:34 +00:00
|
|
|
int
|
|
|
|
LOGFILE_addressCount(LOGFILE *self, unsigned *h_sum);
|
|
|
|
/********************************************************
|
|
|
|
* Get a count of all unique addresses for this file.
|
|
|
|
*/
|
|
|
|
|
2019-11-23 03:40:23 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* LOGFILE_H */
|