1
/*
2
 * Copyright (c) 2002-2007  Dustin Sallings
3
 */
4
5
#ifndef LOGFILES_H
6
#define LOGFILES_H 1
7
8
#include <iostream>
9
#include <queue>
10
#include <vector>
11
12
#include <sys/time.h>
13
#include <sys/types.h>
14
#include <zlib.h>
15
16
#ifdef USE_ASSERT
17
#define TESTED_STATIC
18
#else
19
#define TESTED_STATIC static
20
#endif
21
22
#define OK 1
23
#define ERROR -1
24
25
/* The size of a line buffer */
26
#define LINE_BUFFER 16384
27
/* Read buffer for gzipped data.  Fairly arbitrary, but just about anything
28
 * helps. */
29
#define GZBUFFER 1024*1024
30
31
extern "C" {
32
33
enum logType {
34
	COMMON, AMAZON_S3, UNKNOWN
35
};
36
37
/* The logfile itself */
38
struct logfile {
39
	/* The filename of this log entry */
40
	char *filename;
41
	/* The current record */
42
	char *line;
43
	/* Look!  I know pascal! */
44
	int lineLength;
45
	/* Function to output the current line */
46
	void (*outputLine)(struct logfile *);
47
	/* The timestamp of the current record */
48
	time_t timestamp;
49
	/* Indicate whether this logfile is open */
50
	bool isOpen;
51
	/* Buffering for speeding up gzipped file access */
52
	char *gzBufCur;
53
	char *gzBufEnd;
54
	char *gzBuf;
55
	/* The actual input stream being read */
56
	gzFile input;
57
};
58
59
class TimeCmp {
60
public:
61
	bool operator() (const struct logfile* a, const struct logfile* b) const {
62
		return a->timestamp > b->timestamp;
63
	}
64
};
65
66
typedef std::priority_queue<struct logfile *,
67
	std::vector<struct logfile *>, TimeCmp>
68
	log_queue;
69
70
/* Get a new logfile */
71
struct logfile *createLogfile(const char *filename);
72
/* Skip to the next record in the list */
73
void skipRecord(log_queue&);
74
/* Open a logfile */
75
int openLogfile(struct logfile *lf);
76
77
/* Parse a month.  This is generally static, but exposed when assertions are
78
 enabled. */
79
#ifdef USE_ASSERT
80
TESTED_STATIC int parseMonth(const char*);
81
#endif
82
83
} // extern C
84
85
#endif /* LOGFILES_H */