forked from vexeq/goaccess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommons.h
238 lines (204 loc) · 5.06 KB
/
commons.h
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
/**
* Copyright (C) 2009-2014 by Gerardo Orellana <[email protected]>
* GoAccess - An Ncurses apache weblog analyzer & interactive viewer
*
* 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.
*
* 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
* GNU General Public License for more details.
*
* A copy of the GNU General Public License is attached to this
* source distribution for its full text.
*
* Visit http://goaccess.prosoftcorp.com for new releases.
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef COMMONS_H_INCLUDED
#define COMMONS_H_INCLUDED
#ifdef HAVE_LIBGEOIP
#include <GeoIP.h>
#endif
#include <time.h>
#include <stdint.h>
/* Remove the __attribute__ stuff when the compiler is not GCC. */
#if !__GNUC__
#define __attribute__(x) /**/
#endif
#define GO_UNUSED __attribute__((unused))
#define GO_VERSION "0.9.4"
#define GO_WEBSITE "http://goaccess.io/"
struct tm *now_tm;
/* Processing time */
extern time_t end_proc;
extern time_t timestamp;
extern time_t start_proc;
/* resizing */
extern size_t real_size_y;
extern size_t term_h;
extern size_t term_w;
#define LOG_DEBUG(x, ...) do { dbg_fprintf x; } while (0)
/* invalid requests log */
#define LOG_INVALID(x, ...) do { invalid_fprintf x; } while (0)
#define MAX_CHOICES 366
#ifdef HAVE_LIBGEOIP
#define TOTAL_MODULES 13
#else
#define TOTAL_MODULES 12
#endif
#define DATE_TIME 20
#define DATE_LEN 12 /* date length */
#define HOUR_LEN 3 /* hour length */
#define REQ_PROTO_LEN 9
/* Type of IP */
typedef enum
{
TYPE_IPINV,
TYPE_IPV4,
TYPE_IPV6
} GTypeIP;
/* Type of Modules */
typedef enum MODULES
{
VISITORS,
REQUESTS,
REQUESTS_STATIC,
NOT_FOUND,
HOSTS,
OS,
BROWSERS,
VISIT_TIMES,
REFERRERS,
REFERRING_SITES,
KEYPHRASES,
#ifdef HAVE_LIBGEOIP
GEO_LOCATION,
#endif
STATUS_CODES,
} GModule;
/* Metrics within GHolder or GDashData */
typedef struct GMetrics
{
/* metric id can be used to identify
* a specific data field */
uint8_t id;
char *data;
char *method;
char *protocol;
float percent;
int hits;
int visitors;
/* holder has a numeric value, while
* dashboard has a displayable string value */
union
{
char *sbw;
uint64_t nbw;
} bw;
/* holder has a numeric value, while
* dashboard has a displayable string value */
union
{
char *sts;
uint64_t nts;
} avgts;
/* holder has a numeric value, while
* dashboard has a displayable string value */
union
{
char *sts;
uint64_t nts;
} cumts;
/* holder has a numeric value, while
* dashboard has a displayable string value */
union
{
char *sts;
uint64_t nts;
} maxts;
} GMetrics;
/* Holder sub item */
typedef struct GSubItem_
{
GModule module;
GMetrics *metrics;
struct GSubItem_ *prev;
struct GSubItem_ *next;
} GSubItem;
/* Double linked-list of sub items */
typedef struct GSubList_
{
int size;
struct GSubItem_ *head;
struct GSubItem_ *tail;
} GSubList;
/* Holder item */
typedef struct GHolderItem_
{
GSubList *sub_list;
GMetrics *metrics;
} GHolderItem;
/* Holder of GRawData */
typedef struct GHolder_
{
GHolderItem *items; /* items */
GModule module; /* current module */
int idx; /* index */
int holder_size; /* total number of allocated items */
int ht_size; /* total number of data items */
int sub_items_size; /* total number of sub items */
} GHolder;
/* Enum-to-string */
typedef struct GEnum_
{
const char *str;
int idx;
} GEnum;
/* A metric can contain a root/data/uniq node id */
typedef struct GDataMap_
{
int data;
int uniq;
int root;
} GDataMap;
typedef struct GAgentItem_
{
char *agent;
} GAgentItem;
typedef struct GAgents_
{
int size;
struct GAgentItem_ *items;
} GAgents;
/* Generic Single linked-list */
typedef struct GSLList_
{
void *data;
struct GSLList_ *next;
} GSLList;
/* *INDENT-OFF* */
GAgents *new_gagents (void);
GAgentItem *new_gagent_item (uint32_t size);
float get_percentage (unsigned long long total, unsigned long long hit);
int get_module_enum (const char *str);
int has_timestamp (const char *fmt);
int str2enum (const GEnum map[], int len, const char *str);
void display_storage (void);
void display_version (void);
/* single linked-list */
GSLList *list_create (void *data);
GSLList *list_find (GSLList * node, int (*func) (void *, void *), void *data);
GSLList *list_insert_append (GSLList * node, void *data);
GSLList *list_insert_prepend (GSLList * list, void *data);
int list_count (GSLList * list);
int list_foreach (GSLList * node, int (*func) (void *, void *), void *user_data);
int list_remove_nodes (GSLList * list);
void format_date_visitors (GMetrics * metrics);
/* *INDENT-ON* */
#endif