You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ch...@locus.apache.org on 2000/06/06 02:12:05 UTC

cvs commit: apache-apr/apr/lib apr_tables.c

chuck       00/06/05 17:12:05

  Modified:    apr/include apr_lib.h
               apr/lib  apr_tables.c
  Log:
  added ap_replace_tables() (orig. Graham Leggett) for mod_proxy
  
  Revision  Changes    Path
  1.13      +2 -0      apache-apr/apr/include/apr_lib.h
  
  Index: apr_lib.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/include/apr_lib.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- apr_lib.h	1999/08/04 17:51:56	1.12
  +++ apr_lib.h	2000/06/06 00:12:04	1.13
  @@ -305,6 +305,8 @@
   API_EXPORT(ap_table_t *) ap_overlay_tables(struct context_t *p,
   					     const ap_table_t *overlay,
   					     const ap_table_t *base);
  +API_EXPORT(int) ap_replace_tables(const ap_table_t *base,
  +				   const ap_table_t *overlay);        
   API_EXPORT(void)
   	ap_table_do(int (*comp) (void *, const char *, const char *),
   		     void *rec, const ap_table_t *t, ...);
  
  
  
  1.2       +19 -0     apache-apr/apr/lib/apr_tables.c
  
  Index: apr_tables.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/lib/apr_tables.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_tables.c	1999/07/27 18:27:59	1.1
  +++ apr_tables.c	2000/06/06 00:12:04	1.2
  @@ -564,6 +564,25 @@
       return res;
   }
   
  +/* overlay one table on another - keys in base
  + * will be replaced by keys in overlay
  + */
  +API_EXPORT(int) ap_replace_tables(const ap_table_t *base,
  +                                  const ap_table_t *overlay)
  +{
  +    ap_table_entry_t *elts = (ap_table_entry_t *) overlay->a.elts;
  +    int i, q = 0;
  +    const char *val;
  + 
  +    for (i = 0; i < overlay->a.nelts; ++i) {
  +      val = ap_table_get(base, elts[i].key);
  +      if (!val || strcmp(val, elts[i].val))
  +          q = 1;
  +      ap_table_set(base, elts[i].key, elts[i].val);
  +    }
  + 
  +    return q;
  +}                                                                               
   /* And now for something completely abstract ...
   
    * For each key value given as a vararg:
  
  
  

Re: cvs commit: apache-apr/apr/lib apr_tables.c

Posted by Chuck Murcko <ch...@topsail.org>.
Greg Stein wrote:
> 
> On Tue, Jun 06, 2000 at 07:00:49PM +0200, Graham Leggett wrote:
> > Greg Stein wrote:
> >
> > > Euh... how is this different from ap_overlap_tables() ??
> >
> > Overlap tables combines the values of common headers, no information is
> > lost, two headers become one with comma separated data. Replace tables
> > does exactly that - old header values are lost and are replaced with new
> > header values.
> 
> ap_overlap_tables(base, overrides, AP_OVERLAP_TABLES_SET) does what you are
> looking for.
> 
The real difference is that ap_replace_tables() returns an int used to
signify the status of comparing the values in the two headers, to
determine whether the request gets fulfilled immediately or not. The
replace gets done in either case.
-- 
Chuck
Chuck Murcko
Topsail Group
chuck@topsail.org

Re: cvs commit: apache-apr/apr/lib apr_tables.c

Posted by Greg Stein <gs...@lyra.org>.
On Tue, Jun 06, 2000 at 07:00:49PM +0200, Graham Leggett wrote:
> Greg Stein wrote:
> 
> > Euh... how is this different from ap_overlap_tables() ??
> 
> Overlap tables combines the values of common headers, no information is
> lost, two headers become one with comma separated data. Replace tables
> does exactly that - old header values are lost and are replaced with new
> header values.

ap_overlap_tables(base, overrides, AP_OVERLAP_TABLES_SET) does what you are
looking for.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: cvs commit: apache-apr/apr/lib apr_tables.c

Posted by Graham Leggett <mi...@sharp.fm>.
Greg Stein wrote:

> Euh... how is this different from ap_overlap_tables() ??

Overlap tables combines the values of common headers, no information is
lost, two headers become one with comma separated data. Replace tables
does exactly that - old header values are lost and are replaced with new
header values.

It is required when replacement header data arrives from a source
webserver during a revalidation (like If-Modified-Since). The proxy is
required to replace any stored header values with new values from the
source server, discarding the old values. None of the existing table
functions can do this.

> The time-complexity of the algorithm below is also pretty expensive.
> ap_overlap_tables() takes incredible pains to bring the operation down to
> O(n log n).

To be honest I didn't pay much attention to making it fast - though it
is based on the fact that the overlayed array will almost always be very
much smaller than the original table. As a result, iterations should be
small anyway.

Is there a better way of doing this?

Regards,
Graham
-- 
-----------------------------------------
minfrin@sharp.fm		"There's a moon
					over Bourbon Street
						tonight..."



Re: cvs commit: apache-apr/apr/lib apr_tables.c

Posted by Chuck Murcko <ch...@topsail.org>.
Yeah, never mind, this is slower and wrong, 

Greg Stein wrote:
> 
> Euh... how is this different from ap_overlap_tables() ??
> 
> The time-complexity of the algorithm below is also pretty expensive.
> ap_overlap_tables() takes incredible pains to bring the operation down to
> O(n log n).
> 
> -1 on this change, unless somebody can explain "why"
> 
OK, I'm not going ahead until I check further into this and
ap_overlap_tables(). This is only used on a 304 Not Modified from the
origin server where the headers have changed (yes, that's possible).
I'll test it in 1.3 with ap_overlap_tables() using
AP_OVERLAP_TABLES_SET, which is what I assume you're suggesting.
-- 
Chuck
Chuck Murcko
Topsail Group
chuck@topsail.org

Re: cvs commit: apache-apr/apr/lib apr_tables.c

Posted by Greg Stein <gs...@lyra.org>.
Euh... how is this different from ap_overlap_tables() ??

The time-complexity of the algorithm below is also pretty expensive.
ap_overlap_tables() takes incredible pains to bring the operation down to
O(n log n).

-1 on this change, unless somebody can explain "why"

thx,
-g

On 6 Jun 2000 chuck@locus.apache.org wrote:
> chuck       00/06/05 17:12:05
> 
>   Modified:    apr/include apr_lib.h
>                apr/lib  apr_tables.c
>   Log:
>   added ap_replace_tables() (orig. Graham Leggett) for mod_proxy
>...
>   --- apr_tables.c	1999/07/27 18:27:59	1.1
>   +++ apr_tables.c	2000/06/06 00:12:04	1.2
>   @@ -564,6 +564,25 @@
>        return res;
>    }
>    
>   +/* overlay one table on another - keys in base
>   + * will be replaced by keys in overlay
>   + */
>   +API_EXPORT(int) ap_replace_tables(const ap_table_t *base,
>   +                                  const ap_table_t *overlay)
>   +{
>   +    ap_table_entry_t *elts = (ap_table_entry_t *) overlay->a.elts;
>   +    int i, q = 0;
>   +    const char *val;
>   + 
>   +    for (i = 0; i < overlay->a.nelts; ++i) {
>   +      val = ap_table_get(base, elts[i].key);
>   +      if (!val || strcmp(val, elts[i].val))
>   +          q = 1;
>   +      ap_table_set(base, elts[i].key, elts[i].val);
>   +    }
>   + 
>   +    return q;
>   +}                                                                               

-- 
Greg Stein, http://www.lyra.org/