On Mon, 23 Aug 2004 07:45:17 -0700
"Guy Ferraiolo" <[EMAIL PROTECTED]> wrote:

> That's great.  I have a need for non-numeric random substitution and I
> don't want to do something contradictory.

I was hoping for a few days dedicated to flood development, but I had to
settle for a few hours. Somehow I managed to prepare a patch which brings this
functionality (see attachment). You can use fixed size random numbers like
this:

<url requesttemplate="http://www.x.com/test?id=${(-6:27)=id}" />

If you omit colon like this:

<url requesttemplate="http://www.x.com/test?id=${(128)=id}" />

It will result in a range from 0 to 128.

This patch is very simple, and nearly offers no protection against wrong
ranges (like 543:-256), so use with care. If there are no objections it will
be commited, as soon, as I prepare paragraph describing this feature.

regards,
Jacek Prucia

--- flood_round_robin.c.orig    2004-09-03 17:51:27.000000000 +0200
+++ flood_round_robin.c 2004-09-03 17:51:06.000000000 +0200
@@ -158,6 +158,58 @@
             else
                 data = NULL;
         }
+        else if (*(cur+match[1].rm_so) == '(')
+        {
+            if (set)
+            {
+                /* fixed range random value. */
+                char *colon, *ptr;
+                int offs = 0;
+                int range_beg = 0;
+                int range_end = 0;
+                int range_size = 0;
+
+                while(*(cur + match[1].rm_so + offs) != ')') {
+                    if (match[1].rm_so + offs > match[1].rm_eo) {
+                        offs  = 0;
+                        data = NULL;
+                        break;
+                    }
+                    offs++;
+                }
+
+                if(offs)
+                {
+                    ptr = cur + match[1].rm_so + offs;
+                    colon = strchr(cur + match[1].rm_so, ':');
+                    if(colon && colon < ptr) {
+                        range_beg = strtol(cur + match[1].rm_so + 1, &colon, 
10);
+                        range_end = strtol(colon + 1, &ptr, 10);
+                    } else {
+                        range_end = strtol(cur + match[1].rm_so + 1, &ptr, 10);
+                        if(range_end < 1) {
+                            range_end = 1;
+                        }
+                    }
+                    range_size = abs(range_beg) + abs(range_end) + 1;
+#if FLOOD_USE_RAND
+                    data = apr_psprintf(rp->pool, "%d", (rand() % range_size) 
+ range_beg);
+#elif FLOOD_USE_RAND48
+                    data = apr_psprintf(rp->pool, "%ld", (lrand48() % 
range_size) + range_beg);
+#elif FLOOD_USE_RANDOM
+                    data = apr_psprintf(rp->pool, "%ld", ((long)random() % 
range_size) + range_beg);
+#endif
+                }
+                else
+                    data = NULL;
+
+                matchsize = match[1].rm_eo - match[1].rm_so - offs - 2;
+                apr_hash_set(rp->state, cur + match[1].rm_so + offs + 2, 
matchsize, data);
+
+            }
+            else
+                data = NULL;
+        }
         else
         {
             matchsize = match[1].rm_eo - match[1].rm_so;

Reply via email to