2 webalizer - a web server log analysis program
4 Copyright (C) 1997-2011 Bradford L. Barrett
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version, and provided that the above
10 copyright and permission notice is included with all distributed
11 copies of this or derived software.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 /*********************************************/
25 /* STANDARD INCLUDES */
26 /*********************************************/
32 #include <unistd.h> /* normal stuff */
34 #include <sys/utsname.h>
36 /* ensure sys/types */
38 #include <sys/types.h>
41 /* need socket header? */
42 #ifdef HAVE_SYS_SOCKET_H
43 #include <sys/socket.h>
46 /* some systems need this */
51 #include "webalizer.h" /* main header */
55 /* internal function prototypes */
57 NLISTPTR
new_nlist(char *); /* new list node */
58 void del_nlist(NLISTPTR
*); /* del list */
60 GLISTPTR
new_glist(char *, char *); /* new group list node */
61 void del_glist(GLISTPTR
*); /* del group list */
63 int isinstr(char *, char *);
65 /* Linkded list pointers */
66 GLISTPTR group_sites
= NULL
; /* "group" lists */
67 GLISTPTR group_urls
= NULL
;
68 GLISTPTR group_refs
= NULL
;
69 GLISTPTR group_agents
= NULL
;
70 GLISTPTR group_users
= NULL
;
71 NLISTPTR hidden_sites
= NULL
; /* "hidden" lists */
72 NLISTPTR hidden_urls
= NULL
;
73 NLISTPTR hidden_refs
= NULL
;
74 NLISTPTR hidden_agents
= NULL
;
75 NLISTPTR hidden_users
= NULL
;
76 NLISTPTR ignored_sites
= NULL
; /* "Ignored" lists */
77 NLISTPTR ignored_urls
= NULL
;
78 NLISTPTR ignored_refs
= NULL
;
79 NLISTPTR ignored_agents
= NULL
;
80 NLISTPTR ignored_users
= NULL
;
81 NLISTPTR include_sites
= NULL
; /* "Include" lists */
82 NLISTPTR include_urls
= NULL
;
83 NLISTPTR include_refs
= NULL
;
84 NLISTPTR include_agents
= NULL
;
85 NLISTPTR include_users
= NULL
;
86 NLISTPTR index_alias
= NULL
; /* index. aliases */
87 NLISTPTR html_pre
= NULL
; /* before anything else :) */
88 NLISTPTR html_head
= NULL
; /* top HTML code */
89 NLISTPTR html_body
= NULL
; /* body HTML code */
90 NLISTPTR html_post
= NULL
; /* middle HTML code */
91 NLISTPTR html_tail
= NULL
; /* tail HTML code */
92 NLISTPTR html_end
= NULL
; /* after everything else */
93 NLISTPTR page_type
= NULL
; /* page view types */
94 NLISTPTR omit_page
= NULL
; /* pages not counted */
95 NLISTPTR page_prefix
= NULL
; /* page view prefixes */
96 GLISTPTR search_list
= NULL
; /* Search engine list */
98 /*********************************************/
99 /* NEW_NLIST - create new linked list node */
100 /*********************************************/
102 NLISTPTR
new_nlist(char *str
)
106 if (sizeof(newptr
->string
) < strlen(str
))
109 fprintf(stderr
,"[new_nlist] %s\n",msg_big_one
);
111 if (( newptr
= malloc(sizeof(struct nlist
))) != NULL
)
112 {strncpy(newptr
->string
, str
, sizeof(newptr
->string
));newptr
->next
=NULL
;}
116 /*********************************************/
117 /* ADD_NLIST - add item to FIFO linked list */
118 /*********************************************/
120 int add_nlist(char *str
, NLISTPTR
*list
)
122 NLISTPTR newptr
,cptr
,pptr
;
124 if ( (newptr
= new_nlist(str
)) != NULL
)
126 if (*list
==NULL
) *list
=newptr
;
130 while(cptr
!=NULL
) { pptr
=cptr
; cptr
=cptr
->next
; };
137 /*********************************************/
138 /* DEL_NLIST - delete FIFO linked list */
139 /*********************************************/
141 void del_nlist(NLISTPTR
*list
)
154 /*********************************************/
155 /* NEW_GLIST - create new linked list node */
156 /*********************************************/
158 GLISTPTR
new_glist(char *str
, char *name
)
162 if (sizeof(newptr
->string
) < strlen(str
) ||
163 sizeof(newptr
->name
) < strlen(name
))
166 fprintf(stderr
,"[new_glist] %s\n",msg_big_one
);
168 if (( newptr
= malloc(sizeof(struct glist
))) != NULL
)
170 strncpy(newptr
->string
, str
, sizeof(newptr
->string
));
171 strncpy(newptr
->name
, name
, sizeof(newptr
->name
));
177 /*********************************************/
178 /* ADD_GLIST - add item to FIFO linked list */
179 /*********************************************/
181 int add_glist(char *str
, GLISTPTR
*list
)
183 GLISTPTR newptr
,cptr
,pptr
;
184 char temp_buf
[MAXKVAL
];
188 /* make local copy of string */
189 if (*str
=='"' || *str
=='\'') sep
=*str
++; /* Quote character? */
190 strncpy(temp_buf
,str
,MAXKVAL
-1);
191 temp_buf
[MAXKVAL
-1]=0;
193 if (!sep
) /* Space seperated */
194 while (!isspace((unsigned char)*name
) && *name
!=0) name
++;
196 while (*name
!=sep
&& *name
!=0) name
++; /* Quote seperated */
198 if (*name
==0) name
=temp_buf
;
202 while (isspace((unsigned char)*name
)&&*name
!=0) name
++;
203 if (*name
==0) name
=temp_buf
;
206 if ( (newptr
= new_glist(temp_buf
, name
)) != NULL
)
208 if (*list
==NULL
) *list
=newptr
;
212 while(cptr
!=NULL
) { pptr
=cptr
; cptr
=cptr
->next
; };
219 /*********************************************/
220 /* DEL_GLIST - delete FIFO linked list */
221 /*********************************************/
223 void del_glist(GLISTPTR
*list
)
236 /*********************************************/
237 /* ISINLIST - Test if string is in list */
238 /*********************************************/
240 char *isinlist(NLISTPTR list
, char *str
)
247 if (isinstr(str
,lptr
->string
)) return lptr
->string
;
253 /*********************************************/
254 /* ISINGLIST - Test if string is in list */
255 /*********************************************/
257 char *isinglist(GLISTPTR list
, char *str
)
264 if (isinstr(str
,lptr
->string
)) return lptr
->name
;
270 /*********************************************/
271 /* ISINSTR - Scan for string in string */
272 /*********************************************/
274 int isinstr(char *str
, char *cp
)
278 cp1
=(cp
+strlen(cp
))-1;
281 /* if leading wildcard, start from end */
282 cp2
=str
+strlen(str
)-1;
283 while ( (cp1
!=cp
) && (cp2
!=str
))
285 if (*cp1
=='*') return 1;
286 if (*cp1
--!=*cp2
--) return 0;
288 if (cp1
==cp
) return 1;
293 /* if no leading/trailing wildcard, just strstr */
294 if (*cp1
!='*') return(strstr(str
,cp
)!=NULL
);
295 /* otherwise do normal forward scan */
299 if (*cp1
=='*') return 1;
300 if (*cp1
++!=*cp2
++) return 0;
302 if (*cp1
=='*') return 1;