Hi

Some time ago Henrik asked for volunteer to some beginner squid developer task.
Due some time constraint problems (working on my final project), I
couldn't work on
it as I desired. But now I have more time (I hope :) ).

Well, here comes a initial patch against squid-2 HEAD which implements a new acl
type, called 'file_suffix'.
It's quite simple:

acl file_suffix exts .cgi .dll .tar.gz .;exe

Please comment it. It works for me, but real world is wider than my tests :)
I've also made some memory leaks tests with valgrind.

regards
Lucas Brasilino
Index: src/acl.c
===================================================================
RCS file: /cvsroot/squid/squid/src/acl.c,v
retrieving revision 1.91
diff -u -r1.91 acl.c
--- src/acl.c	14 Jan 2008 13:52:37 -0000	1.91
+++ src/acl.c	1 Mar 2008 17:15:07 -0000
@@ -39,6 +39,7 @@
 static void aclParseDomainList(void *curlist);
 static void aclParseUserList(void **current);
 static void aclParseIpList(void *curlist);
+static void aclParseFileSuffix(void *curlist);
 static void aclParseIntlist(void *curlist);
 static void aclParseWordList(void *curlist);
 static void aclParseProtoList(void *curlist);
@@ -54,6 +55,7 @@
 static int aclMatchTime(acl_time_data * data, time_t when);
 static int aclMatchUser(void *proxyauth_acl, char *user);
 static int aclMatchIp(void *dataptr, struct in_addr c);
+static int aclMatchFileSuffix(void *dataptr, const char *url);
 static int aclMatchDomainList(void *dataptr, const char *);
 static int aclMatchIntegerRange(intrange * data, int i);
 static int aclMatchWordList(wordlist *, const char *);
@@ -118,6 +120,8 @@
 	return ACL_DST_IP;
     if (!strcmp(s, "myip"))
 	return ACL_MY_IP;
+    if (!strcmp(s, "file_suffix"))
+        return ACL_FILE_SUFFIX;
     if (!strcmp(s, "domain"))
 	return ACL_DST_DOMAIN;
     if (!strcmp(s, "dstdomain"))
@@ -576,6 +580,29 @@
     }
 }
 
+/**********************/
+/* aclParseFileSuffix */
+/**********************/
+
+void
+aclParseFileSuffix(void *curlist)
+{ 
+  char *t = NULL;
+
+  while ((t = strtokFile())) {
+    if (*t != '.') {
+      debug (28,0) ("aclParseFileSuffix: Invalid filename extension '%s'\n",t);
+      continue;
+    }
+    if (strlen (t) > ACL_FILE_SUFFIX_SZ) {	
+      debug (28,0) ("aclParseFileSuffix: Filename extension too long '%s'\n",t);
+      continue;
+    }
+    wordlistAdd (curlist,t);
+    debug (28,3) ("aclParseFileSuffix: added '%s' extension\n", t);
+  }
+}
+
 static void
 aclParseTimeSpec(void *curlist)
 {
@@ -999,6 +1026,9 @@
     case ACL_MY_IP:
 	aclParseIpList(&A->data);
 	break;
+    case ACL_FILE_SUFFIX:
+        aclParseFileSuffix(&A->data);
+        break;
     case ACL_SRC_DOMAIN:
     case ACL_DST_DOMAIN:
 	aclParseDomainList(&A->data);
@@ -1326,6 +1356,32 @@
 }
 
 /**********************/
+/* aclMatchFileSuffix */
+/**********************/
+
+int
+aclMatchFileSuffix(void *dataptr, const char *url)
+{
+  char *e = NULL, *s = NULL;
+  wordlist *l = NULL;
+
+  debug (28,3) ("aclMatchFileSuffix: checking urlpath '%s'\n", url);
+  s = strchr (url,'.');
+  if (s == NULL)
+    return 0;
+  l = dataptr;
+  while (l) {
+    debug (28,3) ("aclMatchFileSuffix: checking against '%s'\n", l->key);
+    if (!strncmp (l->key, s, strlen (l->key))) {
+      debug (28, 2) ("aclMatchFileSuffix: '%s' match found\n", l->key);
+      return 1;
+    } 
+    l = l->next;
+  }
+  return 0;
+}
+
+/**********************/
 /* aclMatchDomainList */
 /**********************/
 
@@ -1796,6 +1852,9 @@
 	/* NOTREACHED */
     case ACL_MY_IP:
 	return aclMatchIp(&ae->data, checklist->my_addr);
+        /* NOTREACHED */
+    case ACL_FILE_SUFFIX:
+        return aclMatchFileSuffix(ae->data, strBuf (r->urlpath));
 	/* NOTREACHED */
     case ACL_DST_IP:
 	ia = ipcache_gethostbyname(r->host, IP_LOOKUP_IF_MISS);
@@ -2517,6 +2576,9 @@
 	case ACL_MY_IP:
 	    splay_destroy(a->data, aclFreeIpData);
 	    break;
+        case ACL_FILE_SUFFIX:
+	    wordlistDestroy ((wordlist **) &a->data);
+            break;
 #if USE_ARP_ACL
 	case ACL_SRC_ARP:
 #endif
@@ -2976,6 +3038,8 @@
     case ACL_DST_IP:
     case ACL_MY_IP:
 	return aclDumpIpList(a->data);
+    case ACL_FILE_SUFFIX:
+        return wordlistDup(a->data);
     case ACL_SRC_DOMAIN:
     case ACL_DST_DOMAIN:
 	return aclDumpDomainList(a->data);
Index: src/defines.h
===================================================================
RCS file: /cvsroot/squid/squid/src/defines.h,v
retrieving revision 1.43
diff -u -r1.43 defines.h
--- src/defines.h	24 Sep 2007 13:52:08 -0000	1.43
+++ src/defines.h	1 Mar 2008 17:15:08 -0000
@@ -61,6 +61,7 @@
 #define DISKD_LOAD_QUEUE_WEIGHT (MAX_LOAD_VALUE - DISKD_LOAD_BASE)
 
 #define ACL_NAME_SZ 32
+#define ACL_FILE_SUFFIX_SZ 10
 #define BROWSERNAMELEN 128
 
 #define ACL_SUNDAY	0x01
Index: src/enums.h
===================================================================
RCS file: /cvsroot/squid/squid/src/enums.h,v
retrieving revision 1.68
diff -u -r1.68 enums.h
--- src/enums.h	26 Feb 2008 04:51:48 -0000	1.68
+++ src/enums.h	1 Mar 2008 17:15:09 -0000
@@ -105,6 +105,7 @@
     ACL_SRC_IP,
     ACL_DST_IP,
     ACL_MY_IP,
+    ACL_FILE_SUFFIX,
     ACL_SRC_DOMAIN,
     ACL_DST_DOMAIN,
     ACL_SRC_DOM_REGEX,

Reply via email to