[PATCH] Allow acl_time to specify more than one time interval in-line

From: Paul P Komkoff Jr <i@dont-contact.us>
Date: Sat, 16 Nov 2002 15:26:06 +0300

-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160

This allows specifying multiple time ranges for acl time in-line, like
that:

acl foobar time M 10:00-12:00 T 12:00-14:00

etc

applies with offsets to 2.5STABLE1

diff -Nru a/src/acl.c b/src/acl.c
- --- a/src/acl.c Sat Nov 16 14:31:31 2002
+++ b/src/acl.c Sat Nov 16 14:31:31 2002
@@ -546,8 +546,9 @@
     int h1, m1, h2, m2;
     char *t = NULL;
     for (Tail = curlist; *Tail; Tail = &((*Tail)->next));
- - q = memAllocate(MEM_ACL_TIME_DATA);
     while ((t = strtokFile())) {
+ if (!q)
+ q = memAllocate(MEM_ACL_TIME_DATA);
         if (*t < '0' || *t > '9') {
             /* assume its day-of-week spec */
             while (*t) {
@@ -593,7 +594,8 @@
                     cfg_filename, config_lineno, config_input_line);
                 debug(28, 0) ("aclParseTimeSpec: IGNORING Bad time range\n");
                 memFree(q, MEM_ACL_TIME_DATA);
- - return;
+ q = NULL;
+ continue;
             }
             q->start = h1 * 60 + m1;
             q->stop = h2 * 60 + m2;
@@ -602,16 +604,26 @@
                     cfg_filename, config_lineno, config_input_line);
                 debug(28, 0) ("aclParseTimeSpec: IGNORING Reversed time range\n");
                 memFree(q, MEM_ACL_TIME_DATA);
- - return;
+ q = NULL;
+ continue;
             }
+
+ if (q->weekbits == 0)
+ q->weekbits = ACL_ALLWEEK;
+ *(Tail) = q;
+ Tail = &q->next;
+ q = NULL;
         }
     }
- - if (q->start == 0 && q->stop == 0)
- - q->stop = 23 * 60 + 59;
- - if (q->weekbits == 0)
- - q->weekbits = ACL_ALLWEEK;
- - *(Tail) = q;
- - Tail = &q->next;
+
+ if (q) {
+ if (q->start == 0 && q->stop == 0)
+ q->stop = 23 * 60 + 59;
+ if (q->weekbits == 0)
+ q->weekbits = ACL_ALLWEEK;
+ *(Tail) = q;
+ Tail = &q->next;
+ }
 }
 
 void
@@ -1385,18 +1397,26 @@
     static time_t last_when = 0;
     static struct tm tm;
     time_t t;
- - assert(data != NULL);
+/* assert(data != NULL); */
     if (when != last_when) {
         last_when = when;
         xmemcpy(&tm, localtime(&when), sizeof(struct tm));
     }
+
     t = (time_t) (tm.tm_hour * 60 + tm.tm_min);
- - debug(28, 3) ("aclMatchTime: checking %d in %d-%d, weekbits=%x\n",
- - (int) t, (int) data->start, (int) data->stop, data->weekbits);
 
- - if (t < data->start || t > data->stop)
- - return 0;
- - return data->weekbits & (1 << tm.tm_wday) ? 1 : 0;
+ while (data) {
+ debug(28, 3) ("aclMatchTime: checking %d in %d-%d, weekbits=%x\n",
+ (int) t, (int) data->start, (int) data->stop, data->weekbits);
+
+ if ((t >= data->start && t <= data->stop) &&
+ (data->weekbits & (1 << tm.tm_wday)))
+ return 1;
+
+ data = data->next;
+ }
+
+ return 0;
 }
 
 #if SQUID_SNMP

- --
Paul P 'Stingray' Komkoff 'Greatest' Jr /// (icq)23200764 /// (http)stingr.net
  When you're invisible, the only one really watching you is you (my keychain)
-----BEGIN PGP SIGNATURE-----

iD8DBQE91jlKyMW8naS07KQRA1gGAJ40xpTwmHEiTtws/DhY3sHuyfm4igCdFifc
jh/2oOExOHt7o3Jb0IePsXE=
=t49h
-----END PGP SIGNATURE-----
Received on Thu Nov 21 2002 - 10:52:38 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:18:47 MST