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
|
Author: Alexander Zangerl <az@debian.org>
Subject: properly integrate ancient patches that lingered in the debian diff
--- a/Makefile
+++ b/Makefile
@@ -2,21 +2,25 @@
# HINT: If you want to run the program on an UltraSPARC driven machine,
# I recommend to use Sun C-Compiler >= 4.0 or gcc >= 2.8.0 with
# optimization level >= 4 for best performance.
-CC=cc
+CC=gcc
INCLUDE = -I.
LDFLAGS =
+#LDFLAGS = -pg -lc_p
# Compiler Options
-AC_CFLAGS = -xO5 -mr -s -xcrossfile #-g -xsb # SUN cc >= 4.0
+#AC_CFLAGS = -xO5 -mr -s -xcrossfile #-g -xsb # SUN cc >= 4.0
#AC_CFLAGS = -O3 -s # SGI cc, AIX cc
#AC_CFLAGS = -O5 -s # GNU cc
+AC_CFLAGS = -O3 -g -DLINUX -Wall
+#AC_CFLAGS = -O3 -g -pg -DLINUX -Wall
# extra Libraries ( we need this for inet_addr(char *) only )
-XTRA_LIBS = -lnsl # Solaris 2.x
+#XTRA_LIBS = -lnsl # Solaris 2.x
#XTRA_LIBS = # AIX 4.2, Linux 2.x.x, IRIX 5.x, 6.x
+XTRA_LIBS =
# if you want to have the option, to enable debug message logging,
# uncomment the following line, but beware: This DECREASES THE PERFORMANCE
@@ -49,7 +53,7 @@ XTRA_LIBS = -lnsl # Solaris 2.x
# If jesred is compiled without -DUSE_ACCEL the ACCEL strings in the
# redirect rules are ignored, if there are some.
#
-# DEFS = -DUSE_ACCEL
+#DEFS = -DUSE_ACCEL
# That's it - no further changes should be necessary ;-)
# ===========================================================================
--- a/config.c
+++ b/config.c
@@ -22,6 +22,7 @@
*/
#include<stdio.h>
+#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<ctype.h>
@@ -52,7 +53,7 @@ read_allow(char **file, ip_acl **list) {
FILE *fd;
char *token = NULL;
char buff[BUFSIZE];
- struct in_addr addr;
+/* struct in_addr addr; */
fd = fopen(*file, "r");
if(fd == NULL) {
--- a/etc/jesred.conf
+++ b/etc/jesred.conf
@@ -1,17 +1,18 @@
# file with IP addresses, for which URL rewriting is [not] allowed
-allow = /local/squid/etc/redirect.acl
+allow = /etc/jesred.acl
# file with rules for URL rewriting
-rules = /local/squid/etc/redirect.rules
+rules = /etc/jesred.rules
+#rules = /usr/share/doc/jesred/jesred.bofh.rules
# log file for general, error and debug messages (empty value or commenting
# this out disables logging)
-redirect_log = /local/squid/logs/redirect.log
+redirect_log = /var/log/squid/jesred-redirect.log
# log file for URL rewrites (empty value or commenting this out disables
# logging of URL rewrites)
# Log file format: Timestamp Client/Ident URL RURL NO
-rewrite_log = /local/squid/logs/rewrite.log
+# rewrite_log = /var/log/squid/jesred-rewrite.log
# Debug mode: if set to yes and DEBUG option was compiled in, this enables
# debug logging to redirect_log
--- a/etc/redirect.acl
+++ b/etc/redirect.acl
@@ -19,12 +19,14 @@
# If the client IP address matches an entry below, rewrite rules
# are applied immediately (i.e. no further checks for other IP access
# pattern matches will be done).
-#
-# These are my children caches which have their own redirectors running
-!141.44.251.15/32
-!149.203.102.1/32
+# These are example children caches which have their own redirectors running
+# !141.44.251.15/32
+# !149.203.102.1/32
# rewrite all URLs from
-141.44.0.0/16
-149.203.0.0/16
-193.175.28.0/24
+# 141.44.0.0/16
+# 149.203.0.0/16
+# 193.175.28.0/24
+
+# Uncomment the following to rewrite all URLs from all sources:
+# 0.0.0.0/0
--- a/etc/redirect.rules
+++ b/etc/redirect.rules
@@ -1,60 +1,44 @@
-# Example: redirector rules
+# jesred example redirector rules
+# this rules file does NOT redirect any URLs.
+# after uncommenting/adding rules you need to either reload squid or send jesred a HUP signal.
-# since jesred uses exactly the same pattern functions as squirm 1.0 betaB,
-# you can also find detailed information about this file on:
-# http://www.senet.com.au/squirm/#squirm_patterns
-
-#############################################################################
-# Since jesred uses a linear list of redirect rules, the order of the rules #
-# in this file is important!!! #
-#############################################################################
+# Syntax:
+#
+# regex|regexi pattern replacement
+#
+# or
+#
+# abort .filename_extension
-# TAG: abort string
+# jesred uses a linear list of redirect rules and terminates on first match,
+# so the order of rules is important!
+
+# abort string:
#
# If jesred enconters the specified string at the end
# of the passed URL, it immediately returns and echo's back a newline (i.e.
-# no rewrite) - so this speeds up the lookup process a lot!
-# such rules are referred as ABORT rules
+# no rewrite) - so this speeds up the lookup process a lot for commonly
+# accepted URLs.
-# rule 1 - 7
-abort .html
-abort .jpg
-abort .html
-abort .shtml
-abort .java
-abort .jar
-abort .htm
+# examples:
+# abort .html
+# abort .jpg
+# abort .html
+# abort .shtml
+# abort .java
+# abort .jar
+# abort .htm
-# TAG: regex RE [RURL [ACCEL]]
-# TAG: regexi RE [RURL [ACCEL]]
-#
-# ACCEL is honored only, if you compiled jesred with the switch -DUSE_ACCEL
+# regex RE [RURL]
+# regexi RE [RURL]
#
# regex ... indicates, that the following RE is case-sensitive
# regexi ... indicates, that the following RE is case-insensitive
# RE ... is the regular expression, which has to match the passed URL to get
-# rewritten with the following RURL (it is only limited by the
-# implementation of the used regex functions - so see the man page
-# for the regex functions you compiled jesred with, to get detailed
-# information on supported RE's)
+# rewritten with the following RURL (see regex(7)).
# RURL ... if RE matches the passed URL, jesred returns RURL
-# ACCEL ... a string, which
-# starts with a '^' if the string after the '^' is NOT completely
-# the same as the passed URL starts with
-# OR (except when case-insensitive) no egexc with
-# RE and the passed URL (relative expensive) will
-# be called, since the RE wouldn't match the
-# pased URL - i.e. no match
-# ends with a '$' if the passed URL does NOT end exactly with the
-# string before the '$' (expcept case-insensitive)
-# OR , no egexc with with RE and the passed URL
-# will be called - i.e. no match
-# is plain text if accelerator string does not occur in the URL,
-# no regexc with RE and the passed URL will be
-# called - i.e. no match
-#
-#------------------------------------------------------------------------------
-# If RURL and ACCEL are omitted, all URLs which match RE, are NOT rewritten.
+
+# If RURL is omitted, all URLs which match RE are NOT rewritten.
# So the following two rules prevent jesred from rewriting matched URLs, but
# with the 2nd rule jesred does NOT need to store the RURL (thus consuming
# less memory) and does NOT need to do all the pattern replacements (faster)...
@@ -63,31 +47,19 @@ abort .htm
#
# NO_REDIRECT rule
# regex ^http://(.*)/ads/minizoff(.*)
-#------------------------------------------------------------------------------
-#
-# I recommend to use the "accelerators" '^' and '$' in REs whereever it is
-# possible, since this speeds up the pattern matching a lot!
-#------------------------------------------------------------------------------
-
-# rule 8 - 9
-regex ^http://199.78.52.10/~web_ani/.*\.gif http://141.44.30.2/images/dot.gif ^http://199.78.52.10/~web_ani/
-abort .gif
-
-# rule 10 - 17
-regexi ^http://ad.doubleclick.net/ad/.* http://141.44.30.2/images/dot.gif ^http://ad.doubleclick.net/ad/
-regex ^http://ad.preferences.com/image.* http://141.44.30.2/images/dot.gif ^http://ad.preferences.com/image
-regex ^http://ads[0-9][0-9].focalink.com/SmartBanner/nph-graphic.* http://141.44.30.2/images/dot.gif
-regex ^http://adserver.developer.com/cgi-bin/accipiter/adserver.exe.* http://141.44.30.2/images/dot.gif http://adserver.developer.com/cgi-bin/accipiter/adserver.exe
-regex ^http://tracker.clicktrade.com/Tracker.* http://141.44.30.2/images/dot.gif http://tracker.clicktrade.com/Tracker
-regex ^http://adforce.imgis.com/?adserv.* http://141.44.30.2/images/dot.gif ^http://adforce.imgis.com/?adserv
-regex ^http://195.90.252.40/banner.* http://141.44.30.2/images/dot.gif ^http://195.90.252.40/banner
-regex ^http://www.artuframe.com/partners/affiliates/banners.* http://141.44.30.2/images/dot.gif ^http://www.artuframe.com/partners/affiliates/banners
-
-
-# NOTE: actually '.' in RE is any character, so if you want to be sure,
-# escape the special meaning with a prefixed '\' ;-)
-
-# We use the IP address in the rewritten URL to get the local image cached ;-)
-# BTW: You might have a look at our latest redirect.rules file for our
-# parent proxy cache via
-# http://www.cs.uni-magdeburg.de/proxy/filter.shtml
+
+# NOTE: '.' in RE stands for "a single character", so if you want to be sure to match only dots
+# escape the special meaning with a prefixed '\'
+
+# regex ^http://199.78.52.10/~web_ani/.*\.gif http://141.44.30.2/images/dot.gif
+# abort .gif
+
+# regexi ^http://ad.doubleclick.net/ad/.* http://141.44.30.2/images/dot.gif
+# regex ^http://ad.preferences.com/image.* http://141.44.30.2/images/dot.gif
+# regex ^http://ads[0-9][0-9].focalink.com/SmartBanner/nph-graphic.* http://141.44.30.2/images/dot.gif
+# regex ^http://adserver.developer.com/cgi-bin/accipiter/adserver.exe.* http://141.44.30.2/images/dot.gif
+# regex ^http://tracker.clicktrade.com/Tracker.* http://141.44.30.2/images/dot.gif
+# regex ^http://adforce.imgis.com/?adserv.* http://141.44.30.2/images/dot.gif
+# regex ^http://195.90.252.40/banner.* http://141.44.30.2/images/dot.gif
+# regex ^http://www.artuframe.com/partners/affiliates/banners.* http://141.44.30.2/images/dot.gif
+
--- a/ip_list.c
+++ b/ip_list.c
@@ -101,6 +101,11 @@
# include <sys/types.h>
#endif /* __FreeBSD__ */
+#ifdef LINUX
+# include <stdio.h>
+# include <stdlib.h>
+#endif
+
#include<netinet/in.h>
#include<arpa/inet.h>
--- a/main.c
+++ b/main.c
@@ -29,6 +29,10 @@
#include<netinet/in.h>
#include<arpa/inet.h>
+#ifdef LINUX
+#include <unistd.h>
+#endif
+
#ifdef LOCAL_REGEX
#include "regex.h"
#else
@@ -44,6 +48,8 @@
#include "version.h"
#include "rewrite.h"
+extern int pattern_compare(); /* from rewrite.c */
+
static void Usage (void);
static void GetOptions(int argc, char *argv[]);
@@ -66,7 +72,7 @@ int main(int argc, char **argv)
char *f_redirect = NULL;
- int first_run = 1;
+/* int first_run = 1; */
char buff[BUFSIZE];
char redirect_url[BUFSIZE];
char *url, *src_addr, *ident, *method;
--- a/path.h
+++ b/path.h
@@ -7,6 +7,6 @@
/* change this to the path, which contains your jesred.conf */
-#define DEFAULT_PATH "/local/squid/etc"
+#define DEFAULT_PATH "/etc"
#endif
--- a/pattern_list.c
+++ b/pattern_list.c
@@ -24,8 +24,14 @@
*/
#include<stdio.h>
+#include<stdlib.h>
+#include<string.h>
#include<sys/types.h>
+#ifdef LINUX
+#include <ctype.h> /* for tolower() */
+#endif
+
#ifdef LOCAL_REGEX
#include "regex.h"
#else
@@ -37,6 +43,8 @@
#include "util.h"
#include "pattern_list.h"
+int count_parenthesis (char *pattern);
+
void add_to_plist(pattern_item, pattern_item **);
#ifdef USE_ACCEL
char * get_accel(char *, int *, int);
--- a/rewrite.c
+++ b/rewrite.c
@@ -26,7 +26,11 @@
*/
#include<stdio.h>
+#ifdef LINUX
+#include<string.h>
+#else
#include<strings.h>
+#endif
#include<ctype.h>
#include<sys/types.h>
#include<sys/socket.h>
@@ -45,6 +49,8 @@
#include "rewrite.h"
#include "main.h"
+extern int count_parenthesis(); /* from pattern_list.c */
+
/* load the stdin for the redirector into an IN_BUFF structure
Sets in_buff.url to "" if the fields can't be converted */
@@ -82,11 +88,20 @@ parse_buff(char *buff, char **url, char
end[2] = token;
*ident = new_token;
new_token = strchr(++token,'\n');
- if (new_token) {
+ if (new_token) { /* Method */
c++;
*new_token = '\0';
end[3] = new_token;
*method = token;
+ /* Squid 2.6 adds Url-group,
+ this should make jesred backwards-compatible */
+ new_token = strchr(token,' ');
+ if (new_token)
+ {
+ *new_token = '\0';
+ end[3] = new_token;
+ }
+
}
}
}
@@ -242,7 +257,7 @@ pattern_compare(char *url,char *newurl,
int
replace_string (pattern_item *curr, char *url, char *buffer)
{
- char *replacement_string = NULL;
+/* char *replacement_string = NULL; */
regmatch_t match_data[10];
int parenthesis;
char *in_ptr;
|