Re: privoxy "redirect" with {n} and {n, m} style matching

Fabian Keil <[email protected]>
Newsgroups gmane.comp.web.privoxy.devel
Message-ID <[email protected]>
Ramkumar Chinchani <[email protected]> wrote:

> This is again with reference to the freedombox-privoxy project and
> in particular conversion of https_everywhere rulesets into "redirect" actions.
> 
> Starting from https_everywhere rulesets version 3.x, noticed that
> rules use regular expressions with {n} and {n,m} style matching
> which privoxy doesn't appear to like.
> 
> http://www.privoxy.org/user-manual/actions-file.html#REDIRECT
> "An absolute URL or a single pcrs command."
> 
> Does the pcrs engine not handle these?

This is a known but probably undocumented issue.
Unfortunately we have many of those.

The problem here isn't pcrs, but the action file parser which
currently doesn't support closing curly braces inside the action
parameter.

The attached poorly-tested patch allows to escape them like this:

{+redirect{s@a{2,3\}b{10\}@z@}}
# Redirected URL = http://example.org/blafasel-aaabbbbbbbbbbbb
# Redirect Destination = http://example.org/blafasel-zbb
# Redirected URL = http://example.org/blafasel-aabbbbbbbbbb
# Redirect Destination = http://example.org/blafasel-z
example.org/blafasel

It's not exactly pretty, but maybe it's better than nothing.

As mentioned before, I think for the Freedombox use case
it would be best to introduce a redirect-filter{} action:
https://sourceforge.net/mailarchive/forum.php?thread_name=20120121190442.4d16e017.fk%40fabiankeil.de&forum_name=ijbswa-developers

Fabian

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_nov

_______________________________________________
Ijbswa-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ijbswa-developers
accept-escaped-curly-braces-in-action-values.diff (text/x-patch, 4 KB)
From c758f8669e1ed964258a973e6b44eb526cb48d14 Mon Sep 17 00:00:00 2001
From: Fabian Keil <[email protected]>
Date: Fri, 9 Nov 2012 14:23:06 +0100
Subject: [PATCH 1/2] Move string_move() into miscutil.c and make it extern

It's not really a parser.
---
 miscutil.c | 25 +++++++++++++++++++++++++
 miscutil.h |  3 ++-
 parsers.c  | 25 -------------------------
 3 files changed, 27 insertions(+), 26 deletions(-)

diff --git a/miscutil.c b/miscutil.c
index 561e3d6..f04344c 100644
--- a/miscutil.c
+++ b/miscutil.c
@@ -526,6 +526,31 @@ char *string_toupper(const char *string)
 
 /*********************************************************************
  *
+ * Function    :  string_move
+ *
+ * Description :  memmove wrapper to move the last part of a string
+ *                towards the beginning, overwriting the part in
+ *                the middle. strlcpy() can't be used here as the
+ *                strings overlap.
+ *
+ * Parameters  :
+ *          1  :  dst = Destination to overwrite
+ *          2  :  src = Source to move.
+ *
+ * Returns     :  N/A
+ *
+ *********************************************************************/
+void string_move(char *dst, char *src)
+{
+   assert(dst < src);
+
+   /* +1 to copy the terminating nul as well. */
+   memmove(dst, src, strlen(src)+1);
+}
+
+
+/*********************************************************************
+ *
  * Function    :  bindup
  *
  * Description :  Duplicate the first n characters of a string that may
diff --git a/miscutil.h b/miscutil.h
index 5654f92..6c51ee9 100644
--- a/miscutil.h
+++ b/miscutil.h
@@ -60,8 +60,9 @@ extern int strncmpic(const char *s1, const char *s2, size_t n);
 
 extern jb_err string_append(char **target_string, const char *text_to_append);
 extern jb_err string_join  (char **target_string,       char *text_to_append);
-
 extern char *string_toupper(const char *string);
+extern void string_move(char *dst, char *src);
+
 extern char *chomp(char *string);
 extern char *bindup(const char *string, size_t len);
 
diff --git a/parsers.c b/parsers.c
index d3dceea..9376a97 100644
--- a/parsers.c
+++ b/parsers.c
@@ -740,31 +740,6 @@ jb_err decompress_iob(struct client_state *csp)
 
 /*********************************************************************
  *
- * Function    :  string_move
- *
- * Description :  memmove wrapper to move the last part of a string
- *                towards the beginning, overwriting the part in
- *                the middle. strlcpy() can't be used here as the
- *                strings overlap.
- *
- * Parameters  :
- *          1  :  dst = Destination to overwrite
- *          2  :  src = Source to move.
- *
- * Returns     :  N/A
- *
- *********************************************************************/
-static void string_move(char *dst, char *src)
-{
-   assert(dst < src);
-
-   /* +1 to copy the terminating nul as well. */
-   memmove(dst, src, strlen(src)+1);
-}
-
-
-/*********************************************************************
- *
  * Function    :  normalize_lws
  *
  * Description :  Reduces unquoted linear white space in headers
-- 
1.8.0


From 4ff5fb2196677f9bbbd90f5633725184cd057d36 Mon Sep 17 00:00:00 2001
From: Fabian Keil <[email protected]>
Date: Fri, 9 Nov 2012 14:33:23 +0100
Subject: [PATCH 2/2] Allow closing curly braces as part of action values as
 long as they are escaped

---
 actions.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/actions.c b/actions.c
index 9532c51..42219db 100644
--- a/actions.c
+++ b/actions.c
@@ -403,7 +403,17 @@ jb_err get_action_token(char **line, char **name, char **value)
    str++;
    *value = str;
 
-   str = strchr(str, '}');
+   /* The value ends with the first non-escaped closing curly brace */
+   while ((str = strchr(str, '}')) != NULL)
+   {
+      if (str[-1] == '\\')
+      {
+         /* Overwrite the '\' so the action doesn't see it. */
+         string_move(str-1, str);
+         continue;
+      }
+      break;
+   }
    if (str == NULL)
    {
       /* error */
-- 
1.8.0
signature.asc (application/pgp-signature, 196 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (FreeBSD)

iEYEARECAAYFAlCdDfwACgkQSMVSH78upWOWUQCfRVmimWTBsUyU+Uy2OrN2W9hb
oH8An0GGhGOmJ1XRByi+puxvSWQ3tW6C
=OPrM
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.