File: hashtab.c

package info (click to toggle)
webdruid 0.5.4-8
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,236 kB
  • ctags: 806
  • sloc: ansic: 10,823; sh: 2,763; makefile: 162
file content (1605 lines) | stat: -rw-r--r-- 42,346 bytes parent folder | download | duplicates (8)
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
/*
    The WebDruid - a web server log analysis program

    Copyright (C) 2003-2004  Fabien Chevalier (fabien@juliana-multimedia.com)

    Original webalizer copyright:
    Copyright (C) 1997-2001  Bradford L. Barrett (brad@mrunix.net)

    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

    This software uses the gd graphics library, which is copyright by
    Quest Protein Database Center, Cold Spring Harbor Labs.  Please
    see the documentation supplied with the library for additional
    information and license terms, or visit www.boutell.com/gd/ for the
    most recent version of the library and supporting documentation.
*/

/*********************************************/
/* 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>
#include <sys/times.h>

/* ensure getopt */
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

/* ensure sys/types */
#ifndef _SYS_TYPES_H
#include <sys/types.h>
#endif

/* some systems need this */
#ifdef HAVE_MATH_H
#include <math.h>
#endif

/* SunOS 4.x Fix */
#ifndef CLK_TCK
#define CLK_TCK _SC_CLK_TCK
#endif

#include "webdruid.h"                        /* main header              */
#include "lang.h"
#include "linklist.h"
#include "hashtab.h"
#include "utils.h"
#include "sengine.h"

/* internal function prototypes */

HNODEPTR  new_hnode(char *);                  /* new host node            */
UNODEPTR  new_unode(char *);                  /* new url node             */
RNODEPTR  new_rnode(char *);                  /* new referrer node        */
ANODEPTR  new_anode(char *);                  /* new user agent node      */
INODEPTR  new_inode(char *);                  /* new ident node           */
#ifdef USE_DNS
DNODEPTR  new_dnode(char *);                  /* new DNS node             */
#endif  /* USE_DNS */
OPNODEPTR new_opnode(char *, char *, char     /* new open path node       */
            *, char *, char *);
PNODEPTR  new_pnode(LISTPTR, char *, int);    /* new path node            */

void      update_entry(char *);               /* update entry/exit        */
void      update_exit(char *);                /* page totals              */

/* local data */
                                              /* hash tables for:         */
HNODEPTR  sm_htab[MAXHASH];                   /* sites (monthly)          */
HNODEPTR  sd_htab[MAXHASH];                   /* sites (daily)            */
UNODEPTR  um_htab[MAXHASH];                   /* urls                     */
RNODEPTR  rm_htab[MAXHASH];                   /* referrers and agents...  */
ANODEPTR  am_htab[MAXHASH];                   /* user agents              */
INODEPTR  im_htab[MAXHASH];                   /* ident table (username)   */
#ifdef USE_DNS
DNODEPTR  host_table[MAXHASH];                /* DNS hash table           */
#endif  /* USE_DNS */
OPNODEPTR op_htab[MAXHASH];                   /* currently opened path    */
PNODEPTR  gp_htab[MAXHASH];                   /* all path (not sorted)    */
PNODEPTR  fm_htab[MAXHASH];                   /* users flow (monthly)     */

/*********************************************/
/* NEW_HNODE - create host node              */
/*********************************************/

HNODEPTR new_hnode(char *str)
{
   HNODEPTR newptr;
   char     *sptr;

   if (strlen(str) >= MAXHOST)
   {
      if (verbose)
      {
         fprintf(stderr,"[new_hnode] %s (%d)",_("Warning: String exceeds storage size"),(int)strlen(str));
         if (debug_mode)
            fprintf(stderr,":\n--> %s",str);
         fprintf(stderr,"\n");
      }
      str[MAXHOST-1]=0;
   }

   if ( (sptr=malloc(strlen(str)+1))==NULL ) return (HNODEPTR)NULL;
   strcpy(sptr,str);

   if (( newptr = malloc(sizeof(struct hnode))) != NULL)
   {
      newptr->string    =sptr;
      newptr->visit     =0;
      newptr->tstamp    =0;
      newptr->lasturl   =blank_str;
   }
   else free(sptr);
   return newptr;
}

/*********************************************/
/* PUT_HNODE - insert/update host node       */
/*********************************************/

int put_hnode( char     *str,   /* Hostname  */
               int       type,  /* obj type  */
               u_long    count, /* hit count */
               u_long    file,  /* File flag */
               double    xfer,  /* xfer size */
               u_long   *ctr,   /* counter   */
               u_long    visit, /* visits    */
               u_long    tstamp,/* timestamp */
               char     *lasturl, /* lasturl */
               HNODEPTR *htab)  /* ptr>next  */
{
   HNODEPTR cptr,nptr;
   u_long hvalue = hash(str) & (MAXHASH - 1);

   /* check if hashed */
   if ( (cptr = htab[hvalue]) == NULL)
   {
      /* not hashed */
      if ( (nptr=new_hnode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->files = file;
         nptr->xfer  = xfer;
         nptr->next  = NULL;
         htab[hvalue] = nptr;
         if (type!=OBJ_GRP) (*ctr)++;

         if (visit)
         {
            nptr->visit=(visit-1);
            nptr->lasturl=find_url(lasturl);
            nptr->tstamp=tstamp;
            return 0;
         }
         else
         {
            if (ispage(log_rec.url))
            {
               if (htab==sm_htab) update_entry(log_rec.url);
               nptr->lasturl=find_url(log_rec.url);
               nptr->tstamp=tstamp;
               nptr->visit=1;
            }
         }
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
         {
            if ((type==cptr->flag)||((type!=OBJ_GRP)&&(cptr->flag!=OBJ_GRP)))
            {
               /* found... bump counter */
               cptr->count+=count;
               cptr->files+=file;
               cptr->xfer +=xfer;

               if (ispage(log_rec.url))
               {
                  if ((tstamp-cptr->tstamp)>=visit_timeout)
                  {
                     cptr->visit++;
                     if (htab==sm_htab)
                     {
                        update_exit(cptr->lasturl);
                        update_entry(log_rec.url);
                     }
                  }
                  cptr->lasturl=find_url(log_rec.url);
                  cptr->tstamp=tstamp;
               }
               return 0;
            }
         }
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_hnode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->files = file;
         nptr->xfer  = xfer;
         nptr->next  = htab[hvalue];
         htab[hvalue]=nptr;
         if (type!=OBJ_GRP) (*ctr)++;

         if (visit)
         {
            nptr->visit = (visit-1);
            nptr->lasturl=find_url(lasturl);
            nptr->tstamp= tstamp;
            return 0;
         }
         else
         {
            if (ispage(log_rec.url))
            {
               if (htab==sm_htab) update_entry(log_rec.url);
               nptr->lasturl=find_url(log_rec.url);
               nptr->tstamp= tstamp;
               nptr->visit=1;
            }
         }
      }
   }

   if (nptr!=NULL)
   {
      /* set object type */
      if (type==OBJ_GRP) nptr->flag=OBJ_GRP;            /* is it a grouping? */
      else
      {
         /* check if it's a hidden object */
         if ((hide_sites)||(isinlist(hidden_sites,nptr->string)!=NULL))
           nptr->flag=OBJ_HIDE;
      }
   }
   return nptr==NULL;
}

/*********************************************/
/* DEL_HLIST - delete host hash table        */
/*********************************************/

void	del_hlist(HNODEPTR *htab)
{
   /* free memory used by hash table */
   HNODEPTR aptr,temp;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      if (htab[i] != NULL)
      {
         aptr = htab[i];
         while (aptr != NULL)
         {
            temp = aptr->next;
            free (aptr->string);    /* free hostname string space */
            free (aptr);            /* free hostname structure    */
            aptr = temp;
         }
         htab[i]=NULL;
      }
   }
}

/*********************************************/
/* NEW_UNODE - URL node creation             */
/*********************************************/

UNODEPTR new_unode(char *str)
{
   UNODEPTR newptr;
   char     *sptr;

   if (strlen(str) >= MAXURLH)
   {
      if (verbose)
      {
         fprintf(stderr,"[new_unode] %s (%d)",_("Warning: String exceeds storage size"),(int)strlen(str));
         if (debug_mode)
            fprintf(stderr,":\n--> %s",str);
         fprintf(stderr,"\n");
      }
      str[MAXURLH-1]=0;
   }

   if ( (sptr=malloc(strlen(str)+1))==NULL) return (UNODEPTR)NULL;
   strcpy(sptr,str);

   if (( newptr = malloc(sizeof(struct unode))) != NULL)
   {
      newptr->string=sptr;
      newptr->count = 0;
      newptr->flag  = OBJ_REG;
      /* This one is unused for now.
         TODO : check why there is a 'files' member in the unode structure,
         and maybe delete it. We have to think twice, as that will break
         incremental file compatibility */
      newptr->files = 0;
   }
   else free(sptr);
   return newptr;
}

/*********************************************/
/* PUT_UNODE - insert/update URL node        */
/*********************************************/

int put_unode(char *str, int type, u_long count, double xfer,
              u_long *ctr, u_long entry, u_long exit, UNODEPTR *htab)
{
   UNODEPTR cptr,nptr;
   u_long hvalue = hash(str) & (MAXHASH - 1);

   if (str[0]=='-') return 0;

   /* check if hashed */
   if ( (cptr = htab[hvalue]) == NULL)
   {
      /* not hashed */
      if ( (nptr=new_unode(str)) != NULL)
      {
         nptr->flag = type;
         nptr->count= count;
         nptr->xfer = xfer;
         nptr->next = NULL;
         nptr->entry= entry;
         nptr->exit = exit;
         htab[hvalue] = nptr;
         if (type!=OBJ_GRP) (*ctr)++;
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
         {
            if ((type==cptr->flag)||((type!=OBJ_GRP)&&(cptr->flag!=OBJ_GRP)))
            {
               /* found... bump counter */
               cptr->count+=count;
               cptr->xfer += xfer;
               return 0;
            }
         }
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_unode(str)) != NULL)
      {
         nptr->flag = type;
         nptr->count= count;
         nptr->xfer = xfer;
         nptr->next = htab[hvalue];
         nptr->entry= entry;
         nptr->exit = exit;
         htab[hvalue]=nptr;
         if (type!=OBJ_GRP) (*ctr)++;
      }
   }
   if (nptr!=NULL)
   {
      if (type==OBJ_GRP) nptr->flag=OBJ_GRP;
      else if (isinlist(hidden_urls,nptr->string)!=NULL)
                         nptr->flag=OBJ_HIDE;
   }
   return nptr==NULL;
}

/*********************************************/
/* DEL_ULIST - delete URL hash table         */
/*********************************************/

void	del_ulist(UNODEPTR *htab)
{
   /* free memory used by hash table */
   UNODEPTR aptr,temp;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      if (htab[i] != NULL)
      {
         aptr = htab[i];
         while (aptr != NULL)
         {
            temp = aptr->next;
            free (aptr->string);  /* free up URL string memory */
            free (aptr);          /* free up URL struct node   */
            aptr = temp;
         }
         htab[i]=NULL;
      }
   }
}

/*********************************************/
/* NEW_RNODE - Referrer node creation        */
/*********************************************/

RNODEPTR new_rnode(char *str)
{
   RNODEPTR newptr;
   char     *sptr;

   if (strlen(str) >= MAXREFH)
   {
      if (verbose)
      {
         fprintf(stderr,"[new_rnode] %s (%d)",_("Warning: String exceeds storage size"),(int)strlen(str));
         if (debug_mode)
            fprintf(stderr,":\n--> %s",str);
         fprintf(stderr,"\n");
      }
      str[MAXREFH-1]=0;
   }

   if ( (sptr=malloc(strlen(str)+1))==NULL ) return (RNODEPTR)NULL;
   strcpy(sptr,str);

   if (( newptr = malloc(sizeof(struct rnode))) != NULL)
   {
      newptr->string= sptr;
      newptr->count = 1;
      newptr->flag  = OBJ_REG;
   }
   else free(sptr);
   return newptr;
}

/*********************************************/
/* PUT_RNODE - insert/update referrer node   */
/*********************************************/

int put_rnode(char *str, int type, u_long count, u_long *ctr, RNODEPTR *htab)
{
   RNODEPTR cptr,nptr;
   u_long hvalue = hash(str) & (MAXHASH - 1);

   if (str[0]=='-') strcpy(str,"- (Direct Request)");

   /* check if hashed */
   if ( (cptr = htab[hvalue]) == NULL)
   {
      /* not hashed */
      if ( (nptr=new_rnode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->next  = NULL;
         htab[hvalue] = nptr;
         if (type!=OBJ_GRP) (*ctr)++;
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
         {
            if ((type==cptr->flag)||((type!=OBJ_GRP)&&(cptr->flag!=OBJ_GRP)))
            {
               /* found... bump counter */
               cptr->count+=count;
               return 0;
            }
         }
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_rnode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->next  = htab[hvalue];
         htab[hvalue]=nptr;
         if (type!=OBJ_GRP) (*ctr)++;
      }
   }
   if (nptr!=NULL)
   {
      if (type==OBJ_GRP) nptr->flag=OBJ_GRP;
      else if (isinlist(hidden_refs,nptr->string)!=NULL)
                         nptr->flag=OBJ_HIDE;
   }
   return nptr==NULL;
}

/*********************************************/
/* DEL_RLIST - delete referrer hash table    */
/*********************************************/

void	del_rlist(RNODEPTR *htab)
{
   /* free memory used by hash table */
   RNODEPTR aptr,temp;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      if (htab[i] != NULL)
      {
         aptr = htab[i];
         while (aptr != NULL)
         {
            temp = aptr->next;
            free (aptr->string);
            free (aptr);
            aptr = temp;
         }
         htab[i]=NULL;
      }
   }
}

/*********************************************/
/* NEW_ANODE - User Agent node creation      */
/*********************************************/

ANODEPTR new_anode(char *str)
{
   ANODEPTR newptr;
   char     *sptr;

   if (strlen(str) >= MAXAGENT)
   {
      if (verbose)
      {
         fprintf(stderr,"[new_anode] %s (%d)",_("Warning: String exceeds storage size"),(int)strlen(str));
         if (debug_mode)
            fprintf(stderr,":\n--> %s",str);
         fprintf(stderr,"\n");
      }
      str[MAXAGENT-1]=0;
   }

   if ( (sptr=malloc(strlen(str)+1))==NULL ) return (ANODEPTR)NULL;
   strcpy(sptr,str);

   if (( newptr = malloc(sizeof(struct anode))) != NULL)
   {
      newptr->string= sptr;
      newptr->count = 1;
      newptr->flag  = OBJ_REG;
   }
   else free(sptr);
   return newptr;
}

/*********************************************/
/* PUT_ANODE - insert/update user agent node */
/*********************************************/

int put_anode(char *str, int type, u_long count, u_long *ctr, ANODEPTR *htab)
{
   ANODEPTR cptr,nptr;
   u_long hvalue = hash(str) & (MAXHASH - 1);

   if (str[0]=='-') return 0;     /* skip bad user agents */

   /* check if hashed */
   if ( (cptr = htab[hvalue]) == NULL)
   {
      /* not hashed */
      if ( (nptr=new_anode(str)) != NULL)
      {
         nptr->flag = type;
         nptr->count= count;
         nptr->next = NULL;
         htab[hvalue] = nptr;
         if (type!=OBJ_GRP) (*ctr)++;
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
         {
            if ((type==cptr->flag)||((type!=OBJ_GRP)&&(cptr->flag!=OBJ_GRP)))
            {
               /* found... bump counter */
               cptr->count+=count;
               return 0;
            }
         }
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_anode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->next  = htab[hvalue];
         htab[hvalue]=nptr;
         if (type!=OBJ_GRP) (*ctr)++;
      }
   }
   if (type==OBJ_GRP) nptr->flag=OBJ_GRP;
   else if (isinlist(hidden_agents,nptr->string)!=NULL)
                      nptr->flag=OBJ_HIDE;
   return nptr==NULL;
}

/*********************************************/
/* DEL_ALIST - delete user agent hash table  */
/*********************************************/

void	del_alist(ANODEPTR *htab)
{
   /* free memory used by hash table */
   ANODEPTR aptr,temp;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      if (htab[i] != NULL)
      {
         aptr = htab[i];
         while (aptr != NULL)
         {
            temp = aptr->next;
            free (aptr->string);
            free (aptr);
            aptr = temp;
         }
         htab[i]=NULL;
      }
   }
}

/*********************************************/
/* NEW_INODE - create ident (username) node  */
/*********************************************/

INODEPTR new_inode(char *str)
{
   INODEPTR newptr;
   char     *sptr;

   if (strlen(str) >= MAXIDENT)
   {
      if (verbose)
      {
         fprintf(stderr,"[new_inode] %s (%d)",_("Warning: String exceeds storage size"),(int)strlen(str));
         if (debug_mode)
            fprintf(stderr,":\n--> %s",str);
         fprintf(stderr,"\n");
      }
      str[MAXIDENT-1]=0;
   }

   if ( (sptr=malloc(strlen(str)+1))==NULL ) return (INODEPTR)NULL;
   strcpy(sptr,str);

   if (( newptr = malloc(sizeof(struct inode))) != NULL)
   {
      newptr->string    =sptr;
      newptr->visit     =1;
      newptr->tstamp    =0;
   }
   else free(sptr);
   return newptr;
}

/*********************************************/
/* PUT_INODE - insert/update ident node      */
/*********************************************/

int put_inode( char     *str,   /* ident str */
               int       type,  /* obj type  */
               u_long    count, /* hit count */
               u_long    file,  /* File flag */
               double    xfer,  /* xfer size */
               u_long   *ctr,   /* counter   */
               u_long    visit, /* visits    */
               u_long    tstamp,/* timestamp */
               INODEPTR *htab)  /* hashtable */
{
   INODEPTR cptr,nptr;
   u_long hvalue = hash(str) & (MAXHASH - 1);

   if ((str[0]=='-') || (str[0]==0)) return 0;  /* skip if no username */

   /* check if hashed */
   if ( (cptr = htab[hvalue]) == NULL)
   {
      /* not hashed */
      if ( (nptr=new_inode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->files = file;
         nptr->xfer  = xfer;
         nptr->next  = NULL;
         htab[hvalue] = nptr;
         if (type!=OBJ_GRP) (*ctr)++;

         if (visit)
         {
            nptr->visit=(visit-1);
            nptr->tstamp=tstamp;
            return 0;
         }
         else
         {
            if (ispage(log_rec.url)) nptr->tstamp=tstamp;
         }
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
         {
            if ((type==cptr->flag)||((type!=OBJ_GRP)&&(cptr->flag!=OBJ_GRP)))
            {
               /* found... bump counter */
               cptr->count+=count;
               cptr->files+=file;
               cptr->xfer +=xfer;

               if (ispage(log_rec.url))
               {
                  if ((tstamp-cptr->tstamp)>=visit_timeout)
                     cptr->visit++;
                  cptr->tstamp=tstamp;
               }
               return 0;
            }
         }
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_inode(str)) != NULL)
      {
         nptr->flag  = type;
         nptr->count = count;
         nptr->files = file;
         nptr->xfer  = xfer;
         nptr->next  = htab[hvalue];
         htab[hvalue]=nptr;
         if (type!=OBJ_GRP) (*ctr)++;

         if (visit)
         {
            nptr->visit = (visit-1);
            nptr->tstamp= tstamp;
            return 0;
         }
         else
         {
            if (ispage(log_rec.url)) nptr->tstamp= tstamp;
         }
      }
   }

   if (nptr!=NULL)
   {
      /* set object type */
      if (type==OBJ_GRP) nptr->flag=OBJ_GRP;            /* is it a grouping? */
      else
      {
         /* check if it's a hidden object */
         if (isinlist(hidden_users,nptr->string)!=NULL)
           nptr->flag=OBJ_HIDE;
      }
   }
   return nptr==NULL;
}

/*********************************************/
/* DEL_ILIST - delete ident hash table       */
/*********************************************/

void	del_ilist(INODEPTR *htab)
{
   /* free memory used by hash table */
   INODEPTR aptr,temp;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      if (htab[i] != NULL)
      {
         aptr = htab[i];
         while (aptr != NULL)
         {
            temp = aptr->next;
            free (aptr->string);    /* free ident string space */
            free (aptr);            /* free ident structure    */
            aptr = temp;
         }
         htab[i]=NULL;
      }
   }
}

#ifdef USE_DNS   /* only add these for DNS   */

/*********************************************/
/* NEW_DNODE - DNS resolver node creation    */
/*********************************************/

DNODEPTR new_dnode(char *str)
{
   DNODEPTR newptr;
   char     *sptr;

   if (strlen(str) >= MAXHOST)
   {
      if (verbose)
      {
         fprintf(stderr,"[new_dnode] %s (%d)",_("Warning: String exceeds storage size"),(int)strlen(str));
         if (debug_mode)
            fprintf(stderr,":\n--> %s",str);
         fprintf(stderr,"\n");
      }
      str[MAXHOST-1]=0;
   }

   if ( (sptr=malloc(strlen(str)+1))==NULL ) return (DNODEPTR)NULL;
   strcpy(sptr,str);

   if (( newptr = malloc(sizeof(struct dnode))) != NULL)
   {
      newptr->string= sptr;
   }
   else free(sptr);
   return newptr;
}

/*********************************************/
/* PUT_DNODE - insert/update dns host node   */
/*********************************************/

#ifdef USE_IPV6
int put_dnode(char *str, struct sockaddr_storage *addr, DNODEPTR *htab)
#else
int put_dnode(char *str, struct in_addr *addr, DNODEPTR *htab)
#endif
{
   DNODEPTR cptr,nptr;
   u_long hvalue = hash(str) & (MAXHASH - 1);

   if (str[0]==0 || str[0]==' ') return 0;     /* skip bad hostnames */

   /* check if hashed */
   if ( (cptr = htab[hvalue]) == NULL)
   {
      /* not hashed */
      if ( (nptr=new_dnode(str)) != NULL)
      {
         #ifdef USE_IPV6
         if (addr) memcpy(&nptr->addr, addr, sizeof(struct sockaddr_storage));
            else   memset(&nptr->addr, 0, sizeof(struct sockaddr_storage));
         #else
         if (addr) memcpy(&nptr->addr, addr, sizeof(struct in_addr));
            else   memset(&nptr->addr, 0, sizeof(struct in_addr));
         #endif
         nptr->next = NULL;
         htab[hvalue] = nptr;
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0) return 0;
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_dnode(str)) != NULL)
      {
         #ifdef USE_IPV6
         if (addr) memcpy(&nptr->addr, addr, sizeof(struct sockaddr_storage));
            else   memset(&nptr->addr, 0, sizeof(struct sockaddr_storage));
         #else
         if (addr) memcpy(&nptr->addr, addr, sizeof(struct in_addr));
            else   memset(&nptr->addr, 0, sizeof(struct in_addr));
         #endif
         nptr->next  = htab[hvalue];
         htab[hvalue]=nptr;
      }
   }
   return nptr==NULL;
}

/*********************************************/
/* DEL_DLIST - delete dns hash table         */
/*********************************************/

void	del_dlist(DNODEPTR *htab)
{
   /* free memory used by hash table */
   DNODEPTR dptr,temp;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      if (htab[i] != NULL)
      {
         dptr = htab[i];
         while (dptr != NULL)
         {
            temp = dptr->next;
            free (dptr->string);
            free (dptr);
            dptr = temp;
         }
         htab[i]=NULL;
      }
   }
}

#endif /* USE_DNS */

/*********************************************/
/* NEW_OPNODE - create open path node        */
/*********************************************/

/* No deep copies. Fields are pointers to
   respective node items
*/

OPNODEPTR new_opnode(char *hostname,
                     char *search_string,
                     char *user,
                     char *referrer,
                     char *url
                     )
{
   OPNODEPTR newptr;

   if (( newptr = malloc(sizeof(struct opnode))) != NULL)
   {
      LISTPTR path;

      newptr->hostname       = find_hostname(hostname);
      newptr->search_string  = ""; /* unused for now */
      newptr->user           = find_user(user);
      newptr->referrer       = find_referrer(referrer);
      newptr->tstamp         = 0;
      newptr->hash           = progressive_hash(url, 0);

      path = new_list(find_url(url), 0); /* no deep copy */

      if(path == NULL)
      {
         free(newptr);
         newptr = 0;
      }
      else
        newptr->path         = path;
   }
   return newptr;
}

/*********************************************/
/* ADD_OPITEM - add url to open path         */
/*********************************************/

/*
   returns:
      0 on success
      1 on failure
*/

int    add_opitem(char *hostname,
                  char *search_string,
                  char *user,
                  char *referrer,
                  char *url,
                  u_long tstamp,
                  OPNODEPTR * htab)
{
   OPNODEPTR cptr, nptr;
   u_long hvalue = hash(hostname) & (MAXHASH - 1);

   if( (cptr = htab[hvalue]) == NULL )
   {
      /* path not opened, open it now! */
      if( (nptr = new_opnode(hostname, search_string,
                            user, referrer, url)) != NULL )
      {
         nptr->next     = NULL;
         nptr->tstamp   = tstamp;
         htab[hvalue]  = nptr;
      }
      else
      {
         if(verbose)
            fprintf(stderr,"[add_opitem] %s \n",
               _("Warning: out of memory - could not create open path"));
         return 1;
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         if(strcmp(hostname, cptr->hostname) == 0)
         {
            /* We found our opened path! */
            if((tstamp - cptr->tstamp) >= visit_timeout)
            {
               /* we consider the visit is too old, let's begin a new path */
               if (flush_opnode(hvalue, hostname))
               {
                  if (verbose)
                     /* Error flushing node, skipping .... */
                     fprintf(stderr,"%s %s %s...\n",
                           _("Error flushing path, skipping"), cptr->hostname, (char*)cptr->path->item);
                  return 1;
               }
               if( (nptr = new_opnode(hostname, search_string,
                                    user, referrer, url)) != NULL )
               {
                  nptr->next     = htab[hvalue];
                  nptr->tstamp   = tstamp;
                  htab[hvalue]  = nptr;
               }
               else
               {
                  if(verbose)
                     fprintf(stderr,"[add_opitem] %s \n",
                        _("Warning: out of memory - could not create open path"));
                  return 1;
               }
            }
            else
            {
               /*
                  We add the url to the path, the path is growing!
               */

               /* get the last url of the list */
               LISTPTR plptr = 0, lptr = cptr->path;
               while(lptr != NULL)
               {
                  plptr = lptr;
                  lptr = lptr->next;
               }

               /* only add our url if it differs from the last url from the list */
               if(strcmp((char*)plptr->item, url) != 0) {
                  if(add_list(&plptr, find_url(url), 0) != 0)  /* no deep copy */
                  {
                     if(verbose)
                        fprintf(stderr,"[add_opitem] %s \n",
                           _("Warning: out of memory - could not add url to open path"));
                     return 1;
                  }
                  else
                     cptr->hash = progressive_hash(url, cptr->hash);
               }
               else {
                  static OPNODEPTR temp;
                  temp = cptr;
               }
            }
            return 0;
         }
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_opnode(hostname, search_string,
                            user, referrer, url)) != NULL )
      {
         nptr->tstamp    = tstamp;
         nptr->next      = htab[hvalue];
         htab[hvalue] = nptr;
      }
   }
   return nptr==NULL;
}

/*********************************************/
/* FLUSH_OPNODE                              */
/*********************************************/

/* Takes path out of the open path htab,
   and puts it into the global path htab,
   and cuts it into small pieces to put in
   the flow htab
   Does nothing if index'ed value is null
   If hostname null, flushes the first path
   found at position 'index' */

int flush_opnode(u_long index, char *hostname)
{
   /* find path to remove */
   OPNODEPTR ptr = op_htab[index], pptr = 0;

   if(hostname) /* find in list */
   {
      while(ptr != NULL)
      {
         if(strcmp(ptr->hostname, hostname) == 0)
            break;
         else
         {
            pptr = ptr;
            ptr = ptr->next;
         }
      }
   }

   if(ptr != NULL)
   {
      /* we don't keep path of length < 1 */
      if(ptr->path->next != NULL)
      {
         LISTPTR plptr, lptr;
         LISTPTR flow;
         u_long flowhash;

         /* truncate hash */
         u_long hash = ptr->hash % MAXHASH;

         /* cuts path down into small pieces and inserts it in fm_htab */
         plptr = ptr->path;
         lptr = plptr->next;
         while(lptr != NULL)
         {
            /* compute hash - it is based only on the source*/
            flowhash = progressive_hash((char *) plptr->item, 0);

            /* create flow item */
            flow = new_list(plptr->item, 0);
            add_list(&flow, lptr->item, 0);

            put_pnode(flow, NULL, 1, flowhash % MAXHASH, fm_htab);

            plptr = lptr;
            lptr = lptr->next;
         }

         /* put path in global hash table -- this will free the path
            if it is duplicated */
         put_pnode(ptr->path, NULL, 1, hash, gp_htab);
      }
      else
        del_list(&ptr->path, 0); /* no deep destroy */

      /* remove node from open path htab*/
      if(pptr != NULL)
         pptr->next = ptr->next;
      else
         op_htab[index] = ptr->next;

      /* free node */
      free(ptr);
      return 0;
   }
   else
      return 1;
}

/*********************************************/
/* FLUSH_OPHTAB                              */
/*********************************************/

/* flushes old (i.e. older than visit_timeout)
   nodes from the open path hash table

   rec_tstamp: last record timestamp. With this
               we can day if an opened path is old enough
               to be flushed.
               If = 0, force flush.
 */

void flush_ophtab(u_long rec_tstamp)
{
   /* close paths of open path hash table based on last given timestamp */
   int i;
   for(i=0; i<MAXHASH; i++) {
      OPNODEPTR op = op_htab[i];
      OPNODEPTR nextop;
      while(op != NULL)
      {
         nextop = op->next; /* we need to keep next item here because
                              the op structure is freed in case of
                              a flush_opnode call */
         if((rec_tstamp == 0) || ((rec_tstamp - op->tstamp) >= visit_timeout))
         {
            /* if too old we flush */
            if (flush_opnode(i, op->hostname))
            {
               if (verbose)
                  /* Error flushing open path, skipping .... */
                  fprintf(stderr,"%s %s %s...\n",
                     _("Error flushing path, skipping"), op->hostname, (char*)op->path->item);
            }
         }
         op = nextop;
      }
   }
}

/*********************************************/
/* DEL_OPLIST - delete opened path htabs     */
/*********************************************/

void del_oplist(OPNODEPTR *htab, int delpath)
{
   /* free memory used by hash table */
   OPNODEPTR aptr,temp;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      if (htab[i] != NULL)
      {
         aptr = htab[i];
         while (aptr != NULL)
         {
            temp = aptr->next;

            if(delpath != 0)
               /* we free the list - but not the pointed elements */
               del_list(&aptr->path, 0);

            free (aptr);                /* free path structure    */
            aptr = temp;
         }
         htab[i]=NULL;
      }
   }
}


/*********************************************/
/* NEW_PNODE - creates generic path node     */
/*********************************************/

PNODEPTR new_pnode(LISTPTR path, char *key, int count)
{
   PNODEPTR newptr;

   if ( (newptr = malloc(sizeof(struct pnode))) != NULL)
   {
      newptr->key   = key;
      newptr->path  = path;
      newptr->count = count;
   }
   return newptr;
}

/*********************************************/
/* PUT_PNODE - adds path node into given htab*/
/*********************************************/

/* key will be the (possibly null) string
   value attached to path node

   count is what will be used to initialize the
   path if it is not already in the htab
*/

int put_pnode(LISTPTR path, char *key, int count, u_long hashvalue, PNODEPTR *htab)
{
   PNODEPTR cptr,nptr;

   /* check if hashed */
   if ( (cptr = htab[hashvalue]) == NULL)
   {
      /* not hashed */
      if ( (nptr=new_pnode(path, key, count)) != NULL)
      {
         nptr->next = NULL;
         htab[hashvalue] = nptr;
      }
      else
      {
         if(verbose)
            fprintf(stderr,"[put_pnode] %s \n",
             _("Warning: out of memory - could not put path to path list"));
      }
   }
   else
   {
      /* hashed */
      while (cptr != NULL)
      {
         /* try to find if this path has already been stored */
         if((key == cptr->key) ||
               (strcmp(cptr->key, key) == 0))
         {
            /*key is equal, now check path */
            LISTPTR lptr1 = cptr->path;
            LISTPTR lptr2 = path;

            while( (lptr1 != 0) && (lptr2 != 0))
            {
               if(strcmp((char *)lptr1->item, (char *)lptr2->item) != 0)
                 break;
               else
               {
                  lptr1 = lptr1->next;
                  lptr2 = lptr2->next;
               }
            }
            if(lptr1 == lptr2)
            {
               /* both null... path match!*/
               cptr->count += count;
               /* don't forget to delete path! (thank you Valgrind) */
               del_list(&path, 0);
               return 0;
            }
         }
         cptr = cptr->next;
      }
      /* not found... */
      if ( (nptr = new_pnode(path, key, count)) != NULL)
      {
         nptr->next  = htab[hashvalue];
         htab[hashvalue] = nptr;
      }
      else {
         if(verbose)
            fprintf(stderr,"[put_pnode] %s \n",
             _("Warning: out of memory - could not put path to path list"));
      }

   }
   return nptr==NULL;
}

/*********************************************/
/* DEL_PLIST - delete path hash tables       */
/*********************************************/

/* This is a generic function meant to free
   path related hash tables.
   It's ok as long as:
   - items pointed by pnode
     fields are not to be freed by the
     del_plist function (expect path
     if delpath != 0)
   - first item of the xxpnode structs is the
     pointer on the next item
   - second item is a pointer on the path
*/

void	del_plist(PNODEPTR *htab, int delpath)
{
   /* free memory used by hash table */
   PNODEPTR aptr,temp;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      if (htab[i] != NULL)
      {
         aptr = htab[i];
         while (aptr != NULL)
         {
            temp = aptr->next;

            if(delpath != 0)
               /* we free the list - but not the pointed elements */
               del_list(&aptr->path, 0);

            free (aptr);                /* free path structure    */
            aptr = temp;
         }
         htab[i]=NULL;
      }
   }
}

/*********************************************/
/* FIND_URL - Find URL in hash table         */
/*********************************************/

char *find_url(char *str)
{
   UNODEPTR ptr = find_url_node(str);

   if ( ptr != NULL )
      return ptr->string;
   else
      return blank_str;   /* shouldn't get here */
}

/*********************************************/
/* FIND_URL_NODE - Find URL node in htab     */
/*********************************************/

UNODEPTR find_url_node(char *str)
{
   UNODEPTR cptr;

   if ( (cptr=um_htab[hash(str) & (MAXHASH - 1)]) != NULL)
   {
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
            return cptr;
         cptr = cptr->next;
      }
   }
   return NULL;   /* shouldn't get here */
}

/*********************************************/
/* FIND_HOSTNAME - Find hname in hash table  */
/*********************************************/

char *find_hostname(char *str)
{
   HNODEPTR cptr;

   if ( (cptr=sm_htab[hash(str) & (MAXHASH - 1)]) != NULL)
   {
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
            return cptr->string;
         cptr = cptr->next;
      }
   }
   return blank_str;   /* shouldn't get here */
}

/*********************************************/
/* FIND_USER                                 */
/* Find user string in hash table            */
/*********************************************/

char *find_user(char *str)
{
   ANODEPTR cptr;

   if ( (cptr=am_htab[hash(str) & (MAXHASH - 1)]) != NULL)
   {
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
            return cptr->string;
         cptr = cptr->next;
      }
   }
   return blank_str;   /* shouldn't get here */
}

/*********************************************/
/* FIND_REFERRER                             */
/* Find referrer string in hash table        */
/*********************************************/

char *find_referrer(char *str)
{
   RNODEPTR cptr;

   if ( (cptr=rm_htab[hash(str) & (MAXHASH - 1)]) != NULL)
   {
      while (cptr != NULL)
      {
         if (strcmp(cptr->string,str)==0)
            return cptr->string;
         cptr = cptr->next;
      }
   }
   return blank_str;   /* shouldn't get here */
}

/*********************************************/
/* UPDATE_ENTRY - update entry page total    */
/*********************************************/

void update_entry(char *str)
{
   UNODEPTR uptr;

   if (str==NULL) return;
   if ( (uptr = um_htab[hash(str) & (MAXHASH - 1)]) == NULL) return;
   else
   {
      while (uptr != NULL)
      {
         if (strcmp(uptr->string,str)==0)
         {
            if (uptr->flag!=OBJ_GRP)
            {
               uptr->entry++;
               return;
            }
         }
         uptr=uptr->next;
      }
   }
}

/*********************************************/
/* UPDATE_EXIT  - update exit page total     */
/*********************************************/

void update_exit(char *str)
{
   UNODEPTR uptr;

   if (str==NULL) return;
   if ( (uptr = um_htab[hash(str) & (MAXHASH - 1)]) == NULL) return;
   else
   {
      while (uptr != NULL)
      {
         if (strcmp(uptr->string,str)==0)
         {
            if (uptr->flag!=OBJ_GRP)
            {
               uptr->exit++;
               return;
            }
         }
         uptr=uptr->next;
      }
   }
}

/*********************************************/
/* MONTH_UPDATE_EXIT  - eom exit page update */
/*********************************************/

void month_update_exit(u_long tstamp)
{
   HNODEPTR nptr;
   int i;

   for (i=0;i<MAXHASH;i++)
   {
      nptr=sm_htab[i];
      while (nptr!=NULL)
      {
         if (nptr->flag!=OBJ_GRP)
         {
            if ((tstamp-nptr->tstamp)>=visit_timeout)
               update_exit(nptr->lasturl);
         }
         nptr=nptr->next;
      }
   }
}

/*********************************************/
/* TOT_VISIT - calculate total visits        */
/*********************************************/

u_long tot_visit(HNODEPTR *list)
{
   HNODEPTR   hptr;
   u_long     tot=0;
   int        i;

   for (i=0;i<MAXHASH;i++)
   {
      hptr=list[i];
      while (hptr!=NULL)
      {
         if (hptr->flag!=OBJ_GRP) tot+=hptr->visit;
         hptr=hptr->next;
      }
   }
   return tot;
}