1 /*
2     AWFFull - A Webalizer Fork, Full o' features
3 
4     hashtab.h
5         Hashing Tables definitions/includes
6 
7     Copyright (C) 1997-2001  Bradford L. Barrett (brad@mrunix.net)
8     Copyright (C) 2004-2008 by Stephen McInerney (spm@stedee.id.au)
9     Copyright (C) 2006 by John Heaton (john@manchester.ac.uk)
10 
11     This file is part of AWFFull.
12 
13     AWFFull is free software: you can redistribute it and/or modify
14     it under the terms of the GNU General Public License as published by
15     the Free Software Foundation, either version 3 of the License, or
16     (at your option) any later version.
17 
18     AWFFull is distributed in the hope that it will be useful,
19     but WITHOUT ANY WARRANTY; without even the implied warranty of
20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21     GNU General Public License for more details.
22 
23     You should have received a copy of the GNU General Public License
24     along with AWFFull.  If not, see <http://www.gnu.org/licenses/>.
25 
26 */
27 
28 #ifndef AWFFULL_HASHTAB_H
29 #define AWFFULL_HASHTAB_H
30 
31 typedef struct hnode *HNODEPTR;                 /* site node (host) pointer     */
32 typedef struct unode *UNODEPTR;                 /* url node pointer             */
33 typedef struct rnode *RNODEPTR;                 /* referrer node                */
34 typedef struct anode *ANODEPTR;                 /* user agent node pointer      */
35 typedef struct snode *SNODEPTR;                 /* Search string node pointer   */
36 typedef struct inode *INODEPTR;                 /* user (ident) node pointer    */
37 typedef struct enode *ENODEPTR;                 /* error page pointer           */
38 typedef struct seg_node *SEGNODEPTR;            /* Segmenting Node pointer      */
39 
40 /* Object flags */
41 #define OBJ_REG  0                              /* Regular object               */
42 #define OBJ_HIDE 1                              /* Hidden object                */
43 #define OBJ_GRP  2                              /* Grouped object               */
44 
45 #define NODE_H  0
46 #define NODE_U  1
47 #define NODE_R  2
48 #define NODE_A  3
49 #define NODE_S  4
50 #define NODE_I  5
51 #define NODE_E  6
52 #define NODE_SEG  7
53 
54 /* Generic node pointer/structure for generic delete function.
55  * Base template for all other hash node structures */
56 struct node {
57     struct node *next;
58 };
59 typedef struct node *NODEPTR;
60 
61 /* host hash table structure    */
62 struct hnode {
63     struct hnode *next;
64     unsigned long long xfer;
65     char *lasturl;
66     unsigned long count;
67     unsigned long files;
68     unsigned long visit;                        /* visit information            */
69     unsigned long pages;
70     unsigned long tstamp;
71     int flag;
72     bool lasturl_is_entry;                      /* If the last url was the entry page => true */
73     char string[];
74 };
75 
76 /* url hash table structure     */
77 struct unode {
78     struct unode *next;
79     unsigned long long xfer;                    /* xfer size in bytes           */
80     unsigned long long pxfer;                   /* 206 xfer size in bytes       */
81     unsigned long count;                        /* requests counter             */
82     unsigned long pcount;                       /* 206 requests counter         */
83     unsigned long files;                        /* files counter                */
84     unsigned long entry;                        /* entry page counter           */
85     unsigned long exit;                         /* exit page counter            */
86     unsigned long single_access;                /* Single Access Counter        */
87     int flag;                                   /* Object type (REG, HIDE, GRP) */
88     char string[];
89 };                                              /* pointer to next node         */
90 
91 /* referrer hash table struct   */
92 struct rnode {
93     struct rnode *next;
94     unsigned long count;
95     int flag;
96     char string[];
97 };
98 
99 /* user agent hash table struct */
100 struct anode {
101     struct anode *next;
102     unsigned long count;
103     int flag;
104     char string[];
105 };
106 
107 /* search string struct      */
108 struct snode {
109     struct snode *next;
110     unsigned long count;
111     char string[];
112 };
113 
114 /* user (ident) hash table struct    */
115 struct inode {
116     struct inode *next;
117     unsigned long long xfer;
118     unsigned long count;
119     unsigned long files;
120     unsigned long visit;
121     unsigned long tstamp;
122     int flag;
123     char string[];
124 };
125 
126 /* error page hash table struct   */
127 struct enode {
128     struct enode *next;
129     char *error_request;
130     char *url;                                  /* The errored request */
131     char *referer;                              /* who have called this error page */
132     unsigned long count;
133 };
134 
135 /* Segmenting hash table struct    */
136 struct seg_node {
137     struct seg_node *next;
138     unsigned long tstamp;
139     char string[];
140 };
141 
142 extern HNODEPTR sm_htab[MAXHASH];               /* hash tables               */
143 extern HNODEPTR sd_htab[MAXHASH];
144 extern UNODEPTR um_htab[MAXHASH];               /* for hits, sites,          */
145 extern RNODEPTR rm_htab[MAXHASH];               /* referrers and agents...   */
146 extern ANODEPTR am_htab[MAXHASH];
147 extern SNODEPTR sr_htab[MAXHASH];               /* search string table       */
148 extern INODEPTR im_htab[MAXHASH];               /* ident table (username)    */
149 extern ENODEPTR ep_htab[MAXHASH];               /* error page                */
150 
151 extern SEGNODEPTR seg_ref_htab[MAXHASH];
152 
153 extern int put_hnode(char *, int, unsigned long, unsigned long, unsigned long long, unsigned long *, unsigned long, unsigned long, unsigned long, char *, char *, HNODEPTR *, bool,
154                      bool, bool *);
155 extern int put_unode(char *, int, unsigned long, unsigned long long, unsigned long *, unsigned long, unsigned long, unsigned long, int, UNODEPTR *);
156 extern int put_inode(char *, int, unsigned long, unsigned long, unsigned long long, unsigned long *, unsigned long, unsigned long, INODEPTR *, bool);
157 extern int put_rnode(char *, int, unsigned long, unsigned long *, RNODEPTR *);
158 extern int put_anode(char *, int, unsigned long, unsigned long *, ANODEPTR *);
159 extern int put_snode(char *, unsigned long, SNODEPTR *);
160 extern int put_enode(char *, char *, int, unsigned long, unsigned long *, ENODEPTR *);
161 
162 extern unsigned long put_segnode(char *, unsigned long, SEGNODEPTR *);
163 extern unsigned long get_segnode(char *str, SEGNODEPTR * htab);
164 extern int remove_segnode(char *, SEGNODEPTR *);
165 void segment_htab_cleanup(SEGNODEPTR *);
166 
167 extern void del_htabs(void);                    /* delete hash tables        */
168 extern void del_hlist(HNODEPTR *);              /* delete host htab          */
169 extern void del_ulist(UNODEPTR *);              /* delete url htab           */
170 extern void del_rlist(RNODEPTR *);              /* delete referrer htab      */
171 extern void del_alist(ANODEPTR *);              /* delete host htab          */
172 extern void del_slist(SNODEPTR *);              /* delete host htab          */
173 extern void del_ilist(INODEPTR *);              /* delete host htab          */
174 extern void del_elist(ENODEPTR *);              /* delete errorpage htab     */
175 
176 extern void month_update_exit(unsigned long);
177 extern unsigned long tot_visit(HNODEPTR *);
178 extern char *find_url(char *);
179 
180 #endif          /* AWFFULL_HASHTAB_H */
181