-
Notifications
You must be signed in to change notification settings - Fork 1
/
linklist.c
305 lines (259 loc) · 8.45 KB
/
linklist.c
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
webalizer - a web server log analysis program
Copyright (C) 1997-2013 Bradford L. Barrett
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, and provided that the above
copyright and permission notice is included with all distributed
copies of this or derived software.
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.
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
*/
/*********************************************/
/* STANDARD INCLUDES */
/*********************************************/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> /* normal stuff */
#include <ctype.h>
#include <sys/utsname.h>
/* ensure sys/types */
#ifndef _SYS_TYPES_H
#include <sys/types.h>
#endif
/* need socket header? */
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
/* some systems need this */
#ifdef HAVE_MATH_H
#include <math.h>
#endif
#include "webalizer.h" /* main header */
#include "lang.h"
#include "linklist.h"
/* internal function prototypes */
NLISTPTR new_nlist(char *); /* new list node */
void del_nlist(NLISTPTR *); /* del list */
GLISTPTR new_glist(char *, char *); /* new group list node */
void del_glist(GLISTPTR *); /* del group list */
int isinstr(char *, char *);
/* Linkded list pointers */
GLISTPTR group_sites = NULL; /* "group" lists */
GLISTPTR group_urls = NULL;
GLISTPTR group_refs = NULL;
GLISTPTR group_agents = NULL;
GLISTPTR group_users = NULL;
NLISTPTR hidden_sites = NULL; /* "hidden" lists */
NLISTPTR hidden_urls = NULL;
NLISTPTR hidden_refs = NULL;
NLISTPTR hidden_agents = NULL;
NLISTPTR hidden_users = NULL;
NLISTPTR ignored_sites = NULL; /* "Ignored" lists */
NLISTPTR ignored_urls = NULL;
NLISTPTR ignored_refs = NULL;
NLISTPTR ignored_agents= NULL;
NLISTPTR ignored_users = NULL;
NLISTPTR include_sites = NULL; /* "Include" lists */
NLISTPTR include_urls = NULL;
NLISTPTR include_refs = NULL;
NLISTPTR include_agents= NULL;
NLISTPTR include_users = NULL;
NLISTPTR index_alias = NULL; /* index. aliases */
NLISTPTR html_pre = NULL; /* before anything else :) */
NLISTPTR html_head = NULL; /* top HTML code */
NLISTPTR html_body = NULL; /* body HTML code */
NLISTPTR html_post = NULL; /* middle HTML code */
NLISTPTR html_tail = NULL; /* tail HTML code */
NLISTPTR html_end = NULL; /* after everything else */
NLISTPTR page_type = NULL; /* page view types */
NLISTPTR omit_page = NULL; /* pages not counted */
NLISTPTR page_prefix = NULL; /* page view prefixes */
GLISTPTR search_list = NULL; /* Search engine list */
/*********************************************/
/* NEW_NLIST - create new linked list node */
/*********************************************/
NLISTPTR new_nlist(char *str)
{
NLISTPTR newptr;
if (sizeof(newptr->string) < strlen(str))
{
if (verbose)
fprintf(stderr,"[new_nlist] %s\n",msg_big_one);
}
if (( newptr = calloc(1, sizeof(struct nlist))) != NULL)
{strncpy(newptr->string, str, sizeof(newptr->string) - 1);newptr->next=NULL;}
return newptr;
}
/*********************************************/
/* ADD_NLIST - add item to FIFO linked list */
/*********************************************/
int add_nlist(char *str, NLISTPTR *list)
{
NLISTPTR newptr,cptr,pptr;
if ( (newptr = new_nlist(str)) != NULL)
{
if (*list==NULL) *list=newptr;
else
{
cptr=pptr=*list;
while(cptr!=NULL) { pptr=cptr; cptr=cptr->next; };
pptr->next = newptr;
}
}
return newptr==NULL;
}
/*********************************************/
/* DEL_NLIST - delete FIFO linked list */
/*********************************************/
void del_nlist(NLISTPTR *list)
{
NLISTPTR cptr,nptr;
cptr=*list;
while (cptr!=NULL)
{
nptr=cptr->next;
free(cptr);
cptr=nptr;
}
}
/*********************************************/
/* NEW_GLIST - create new linked list node */
/*********************************************/
GLISTPTR new_glist(char *str, char *name)
{
GLISTPTR newptr;
if (sizeof(newptr->string) < strlen(str) ||
sizeof(newptr->name) < strlen(name))
{
if (verbose)
fprintf(stderr,"[new_glist] %s\n",msg_big_one);
}
if (( newptr = calloc(1, sizeof(struct glist))) != NULL)
{
strncpy(newptr->string, str, sizeof(newptr->string) - 1);
strncpy(newptr->name, name, sizeof(newptr->name) - 1);
newptr->next=NULL;
}
return newptr;
}
/*********************************************/
/* ADD_GLIST - add item to FIFO linked list */
/*********************************************/
int add_glist(char *str, GLISTPTR *list)
{
GLISTPTR newptr,cptr,pptr;
char temp_buf[MAXKVAL];
char *name=temp_buf;
char sep=0;
/* make local copy of string */
if (*str=='"' || *str=='\'') sep=*str++; /* Quote character? */
strncpy(temp_buf,str,MAXKVAL-1);
temp_buf[MAXKVAL-1]=0;
if (!sep) /* Space separated */
while (!isspace((unsigned char)*name) && *name!=0) name++;
else
while (*name!=sep && *name!=0) name++; /* Quote separated */
if (*name==0) name=temp_buf;
else
{
*name++=0;
while (isspace((unsigned char)*name)&&*name!=0) name++;
if (*name==0) name=temp_buf;
}
if ( (newptr = new_glist(temp_buf, name)) != NULL)
{
if (*list==NULL) *list=newptr;
else
{
cptr=pptr=*list;
while(cptr!=NULL) { pptr=cptr; cptr=cptr->next; };
pptr->next = newptr;
}
}
return newptr==NULL;
}
/*********************************************/
/* DEL_GLIST - delete FIFO linked list */
/*********************************************/
void del_glist(GLISTPTR *list)
{
GLISTPTR cptr,nptr;
cptr=*list;
while (cptr!=NULL)
{
nptr=cptr->next;
free(cptr);
cptr=nptr;
}
}
/*********************************************/
/* ISINLIST - Test if string is in list */
/*********************************************/
char *isinlist(NLISTPTR list, char *str)
{
NLISTPTR lptr;
lptr=list;
while (lptr!=NULL)
{
if (isinstr(str,lptr->string)) return lptr->string;
lptr=lptr->next;
}
return NULL;
}
/*********************************************/
/* ISINGLIST - Test if string is in list */
/*********************************************/
char *isinglist(GLISTPTR list, char *str)
{
GLISTPTR lptr;
lptr=list;
while (lptr!=NULL)
{
if (isinstr(str,lptr->string)) return lptr->name;
lptr=lptr->next;
}
return NULL;
}
/*********************************************/
/* ISINSTR - Scan for string in string */
/*********************************************/
int isinstr(char *str, char *cp)
{
char *cp1,*cp2;
cp1=(cp+strlen(cp))-1;
if (*cp=='*')
{
/* if leading wildcard, start from end */
cp2=str+strlen(str)-1;
while ( (cp1!=cp) && (cp2!=str))
{
if (*cp1=='*') return 1;
if (*cp1--!=*cp2--) return 0;
}
if (cp1==cp) return 1;
else return 0;
}
else
{
/* if no leading/trailing wildcard, just strstr */
if (*cp1!='*') return(strstr(str,cp)!=NULL);
/* otherwise do normal forward scan */
cp1=cp; cp2=str;
while (*cp2!='\0')
{
if (*cp1=='*') return 1;
if (*cp1++!=*cp2++) return 0;
}
if (*cp1=='*') return 1;
else return 0;
}
}