Re: domainrc to manage cross-domain requests (was Re: RequestPolicy-like patch)
"corvid" <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <20121003172921.GB26483@local> |
I should mention that I was playing around with printing a summary at freeall time in order to see which sites are the worst offenders. Diff attached. _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
domain_data.diff
(text/plain, 2 KB)
diff -r 9e68d01e7822 src/domain.c
--- a/src/domain.c Wed Oct 03 05:51:03 2012 +0000
+++ b/src/domain.c Wed Oct 03 17:20:05 2012 +0000
@@ -25,6 +25,21 @@
static bool_t default_deny = FALSE;
+typedef struct Counter Counter;
+
+struct Counter {
+ char *dest_host;
+ uint_t count;
+};
+
+struct List_data {
+ Counter *counter;
+ int size;
+ int max;
+};
+
+static struct List_data accept = {NULL, 0, 1}, deny = {NULL, 0, 1};
+
/*
* Parse domainrc.
*/
@@ -85,6 +100,20 @@
dFree(exceptions[i].destination);
}
dFree(exceptions);
+
+ MSG("ACCEPT:\n");
+ for (i = 0; i < accept.size; i++) {
+ MSG("%4u %s\n", accept.counter[i].count, accept.counter[i].dest_host);
+ dFree(accept.counter[i].dest_host);
+ }
+ dFree(accept.counter);
+
+ MSG("DENY:\n");
+ for (i = 0; i < deny.size; i++) {
+ MSG("%4u %s\n", deny.counter[i].count, deny.counter[i].dest_host);
+ dFree(deny.counter[i].dest_host);
+ }
+ dFree(deny.counter);
}
/*
@@ -117,6 +146,7 @@
{
int i;
bool_t ret;
+ struct List_data *l;
const char *source_host, *dest_host;
if (default_deny == FALSE && num_exceptions == 0)
@@ -144,8 +174,28 @@
if (i == num_exceptions)
ret = default_deny ? FALSE : TRUE;
- MSG("Domain: %s from %s to %s.\n",
- (ret == TRUE ? "permitted" : "DENIED"), source_host, dest_host);
+ if (ret == FALSE)
+ MSG("Domain: Request from %s to %s denied.\n", source_host, dest_host);
+ l = ret ? &accept : &deny;
+
+ for (i = 0; i < l->size; i++) {
+ if (dStrAsciiCasecmp(dest_host, l->counter[i].dest_host) == 0) {
+ l->counter[i].count++;
+ while (i && l->counter[i].count > l->counter[i-1].count) {
+ Counter tmp = l->counter[i-1];
+
+ l->counter[i-1] = l->counter[i];
+ l->counter[i] = tmp;
+ }
+ break;
+ }
+ }
+ if (i == l->size) {
+ a_List_add(l->counter, l->size, l->max);
+ l->counter[l->size].dest_host = dStrdup(dest_host);
+ l->counter[l->size].count = 1;
+ l->size++;
+ }
return ret;
}