httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: svn commit: r454683 - in /httpd/httpd/trunk: CHANGES docs/manual/mod/mod_rewrite.xml modules/mappers/mod_rewrite.c
Date Tue, 10 Oct 2006 12:00:18 GMT


On 10/10/2006 12:33 PM,  wrote:
> Author: niq
> Date: Tue Oct 10 03:33:06 2006
> New Revision: 454683
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=454683
> Log:
> Add SQL Query capability to RewriteMap
> 

> Modified: httpd/httpd/trunk/modules/mappers/mod_rewrite.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_rewrite.c?view=diff&rev=454683&r1=454682&r2=454683
> ==============================================================================
> --- httpd/httpd/trunk/modules/mappers/mod_rewrite.c (original)
> +++ httpd/httpd/trunk/modules/mappers/mod_rewrite.c Tue Oct 10 03:33:06 2006

> +static char *lookup_map_dbd(request_rec *r, char *key, const char *label)
> +{
> +    apr_status_t rv;
> +    apr_dbd_prepared_t *stmt;
> +    apr_dbd_results_t *res = NULL;
> +    apr_dbd_row_t *row = NULL;
> +    const char *ret = NULL;
> +    int n = 0;
> +    ap_dbd_t *db = dbd_acquire(r);
> +
> +    stmt = apr_hash_get(db->prepared, label, APR_HASH_KEY_STRING);
> +
> +    rv = apr_dbd_pvselect(db->driver, r->pool, db->handle, &res,
> +                          stmt, 0, key, NULL);
> +    if (rv != 0) {
> +        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
> +                      "rewritemap: error querying for %s", key);
> +    }
> +    while (rv = apr_dbd_get_row(db->driver, r->pool, res, &row, -1), rv ==
0) {

Guess that brings us back to the code style discussion :-)

> +        ++n;
> +        if (ret == NULL) {
> +            ret = apr_dbd_get_entry(db->driver, row, 0);
> +        }
> +        else {
> +            /* randomise crudely amongst multiple results */
> +            if ((double)rand() < (double)RAND_MAX/(double)n) {

Is rand portable? Are there APR alternatives that could be used?

> +     */
> +    case MAPTYPE_DBD_CACHE:
> +        value = get_cache_value(s->cachename, st.mtime, key, r->pool);

I think that st is not initialized here. Other maps do an apr_stat before using it.
So it is possible that its value is different each time you call lookup_map.

> +        if (!value) {
> +            rewritelog((r, 6, NULL,
> +                        "cache lookup FAILED, forcing new map lookup"));
> +
> +            value = lookup_map_dbd(r, key, s->dbdq);
> +            if (!value) {
> +                rewritelog((r, 5, NULL, "SQL map lookup FAILED: map %s key=%s",
> +                            name, key));

I noticed that the other rewritemaps also cache negative results by setting the cache to "".
Any specfic reason why this is not done here?

> +                return NULL;
> +            }
> +
> +            rewritelog((r, 5, NULL, "SQL map lookup OK: map %s key=%s, val=%s",
> +                        name, key, value));
> +
> +            set_cache_value(s->cachename, st.mtime, key, value);

Same as above with st.

> +            return value;
> +        }
> +
> +        rewritelog((r, 5, NULL, "cache lookup OK: map=%s[SQL] key=%s, val=%s",
> +                    name, key, value));
> +        return *value ? value : NULL;
> +        
> +    /*

Regards

RĂ¼diger

Mime
View raw message