1
/* class to encapsulate set of functions to manage a circular array;
2
* recent hit information is stored in the looping array; each hit
3
* has information written into the next slot of structs. If
4
* we reach the end, start over. Then the top-URL/IP is summed up from
5
* this information. The bigger the table, the more hits you'll have
11
extern map *hm, *um, *rm;
13
int Hits_Circle::create(unsigned int passed_size)
19
tab = (circle_struct *)
20
calloc(size, sizeof( circle_struct));
26
reqcount = bytecount = 0;
27
memset(rc_summary, (char) NULL, sizeof(rc_summary));
32
int Hits_Circle::insert(struct logbits lb)
34
circle_struct *posptr;
35
short rc_tmp_old, rc_tmp_new;
37
/* insert the given data into the current position,
38
* and update pos to point at next position */
41
if (posptr->time == 0)
42
/* if this is a new insert, increment our count */
46
/* if this is re-using an old slot, remove refcount for the
47
* previous data before we vape it */
48
hm->sub_ref(posptr->host_pos);
49
um->sub_ref(posptr->url_pos);
50
rm->sub_ref(posptr->ref_pos);
54
/* maintain some stats */
55
/* bytecount; remove the previous one and add the new one */
56
bytecount -= posptr->bytes;
57
bytecount += lb.bytes;
58
/* retcodes, remember how many we have of each */
59
rc_tmp_old = (int)posptr->retcode/100;
60
rc_tmp_new = (int)lb.retcode/100;
61
if (rc_tmp_old != rc_tmp_new)
63
--rc_summary[rc_tmp_old];
64
++rc_summary[rc_tmp_new];
68
memcpy(posptr, &lb, sizeof(lb));
72
/* see if we're running out of space. We'd like to keep however many
73
* hits of data the user has asked for; if we're not managing
84
//int Hits_Circle::walk(unsigned int *url_pos, unsigned int *ip_pos,
85
// int *bytes, time_t *time, unsigned int *ipl, unsigned int *retcode)
86
int Hits_Circle::walk(struct logbits **lb)
88
/* return each value in the circle one by one, starting at 0 and
89
* working up; return 0 when there are more to go, or -1 when we're
94
if (walkpos == size || tab[walkpos].time == 0)
106
time_t Hits_Circle::oldest(void)
110
/* return the first entry we have. normally this will be pos+1, but
111
* cater for circumstances where it is isn't; ie we're initially
112
* filling up the array (use 0), or we're at position size (use 0) */
114
tmp = 0; /* earliest will be 0 */
116
tmp = pos + 1; /* earliest is next element */
118
if (tab[tmp].time > 0)
119
return tab[tmp].time;