httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Graham Leggett <minf...@sharp.fm>
Subject Re: svn commit: r1642154 - in /httpd/httpd/trunk: docs/manual/expr.xml include/ap_expr.h server/util_expr_eval.c server/util_expr_parse.y
Date Sun, 21 Dec 2014 11:37:31 GMT
On 27 Nov 2014, at 3:46 PM, jkaluza@apache.org wrote:

> Author: jkaluza
> Date: Thu Nov 27 13:46:11 2014
> New Revision: 1642154
> 
> URL: http://svn.apache.org/r1642154
> Log:
> * ap_exr: Add replace(string, from, to) function.
> 
> Modified:
>    httpd/httpd/trunk/docs/manual/expr.xml
>    httpd/httpd/trunk/include/ap_expr.h
>    httpd/httpd/trunk/server/util_expr_eval.c
>    httpd/httpd/trunk/server/util_expr_parse.y
> 
> Modified: httpd/httpd/trunk/docs/manual/expr.xml
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/expr.xml?rev=1642154&r1=1642153&r2=1642154&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/docs/manual/expr.xml (original)
> +++ httpd/httpd/trunk/docs/manual/expr.xml Thu Nov 27 13:46:11 2014
> @@ -136,7 +136,7 @@ variable    ::= "<strong>%{</strong>" va
> 
> rebackref   ::= "<strong>$</strong>" [0-9]
> 
> -function     ::= funcname "<strong>(</strong>" word "<strong>)</strong>"
> +function     ::= funcname "<strong>(</strong>" wordlist "<strong>)</strong>"
> 
> listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
> </pre>
> @@ -526,6 +526,9 @@ listfunction ::= listfuncname "<strong>(
>     <tr><td><code>ldap</code></td>
>         <td>Escape characters as required by LDAP distinguished name escaping
>             (RFC4514) and LDAP filter escaping (RFC4515).</td><td></td></tr>
> +    <tr><td><code>replace</code></td>
> +        <td>replace(string, "from", "to") replaces all occurences of "from"
> +            in the string with "to".</td><td></td></tr>
> 
>     </table>
> 
> 
> Modified: httpd/httpd/trunk/include/ap_expr.h
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_expr.h?rev=1642154&r1=1642153&r2=1642154&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/include/ap_expr.h (original)
> +++ httpd/httpd/trunk/include/ap_expr.h Thu Nov 27 13:46:11 2014
> @@ -232,6 +232,16 @@ typedef const char *(ap_expr_string_func
>                                             const void *data,
>                                             const char *arg);
> 
> +/** String valued function, takes a list argument and returns a string
> + * @param ctx The evaluation context
> + * @param data An opaque context provided by the lookup hook function
> + * @param args The list of string arguments
> + * @return The functions result string, may be NULL for 'empty string'
> + */
> +typedef const char *(ap_expr_string_list_func_t)(ap_expr_eval_ctx_t *ctx,
> +                                            const void *data,
> +                                            const apr_array_header_t *args);
> +
> /** List valued function, takes a string argument and returns a list of strings
>  * Can currently only be called following the builtin '-in' operator.
>  * @param ctx The evaluation context
> @@ -276,7 +286,9 @@ typedef struct {
>     const char **err;
> 
>     /** arg for pre-parsing (only if a simple string).
> -     *  For binary ops, this is the right argument. */
> +     *  For binary ops, this is the right argument.
> +     *  For functions with more arguments, this is the first string
> +     *  argument. */
>     const char *arg;
> } ap_expr_lookup_parms;
> 
> 
> Modified: httpd/httpd/trunk/server/util_expr_eval.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_expr_eval.c?rev=1642154&r1=1642153&r2=1642154&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/server/util_expr_eval.c (original)
> +++ httpd/httpd/trunk/server/util_expr_eval.c Thu Nov 27 13:46:11 2014
> @@ -24,6 +24,7 @@
> #include "http_protocol.h"
> #include "http_request.h"
> #include "ap_provider.h"
> +#include "util_varbuf.h"
> #include "util_expr_private.h"
> #include "util_md5.h"
> 
> @@ -32,6 +33,8 @@
> #include "apr_base64.h"
> #include "apr_sha1.h"
> #include "apr_version.h"
> +#include "apr_strings.h"
> +#include "apr_strmatch.h"
> #if APR_VERSION_AT_LEAST(1,5,0)
> #include "apr_escape.h"
> #endif
> @@ -183,13 +186,29 @@ static const char *ap_expr_eval_string_f
>                                             const ap_expr_t *info,
>                                             const ap_expr_t *arg)
> {
> -    ap_expr_string_func_t *func = (ap_expr_string_func_t *)info->node_arg1;
>     const void *data = info->node_arg2;
> 
>     AP_DEBUG_ASSERT(info->node_op == op_StringFuncInfo);
> -    AP_DEBUG_ASSERT(func != NULL);
> +    AP_DEBUG_ASSERT(info->node_arg1 != NULL);
>     AP_DEBUG_ASSERT(data != NULL);
> -    return (*func)(ctx, data, ap_expr_eval_word(ctx, arg));
> +    if (arg->node_op == op_ListElement) {
> +        /* Evaluate the list elements and store them in apr_array_header. */
> +        ap_expr_string_list_func_t *func = (ap_expr_string_list_func_t *)info->node_arg1;
> +        apr_array_header_t *args = apr_array_make(ctx->p, 1, sizeof(char *));
> +        do {
> +            const ap_expr_t *val = arg->node_arg1;
> +            const char **new = apr_array_push(args);
> +            *new = ap_expr_eval_word(ctx, val);
> +
> +            arg = arg->node_arg2;
> +        } while (arg != NULL);
> +
> +        return (*func)(ctx, data, args);
> +    }
> +    else {
> +        ap_expr_string_func_t *func = (ap_expr_string_func_t *)info->node_arg1;
> +        return (*func)(ctx, data, ap_expr_eval_word(ctx, arg));
> +    }
> }
> 
> static int intstrcmp(const char *s1, const char *s2)
> @@ -443,7 +462,27 @@ static ap_expr_t *ap_expr_info_make(int 
>     parms.func  = &info->node_arg1;
>     parms.data  = &info->node_arg2;
>     parms.err   = &ctx->error2;
> -    parms.arg   = (arg && arg->node_op == op_String) ? arg->node_arg1
: NULL;
> +    parms.arg   = NULL;
> +    if (arg) {
> +        switch(arg->node_op) {
> +            case op_String:
> +                parms.arg = arg->node_arg1;
> +                break;
> +            case op_ListElement:
> +                do {
> +                    const ap_expr_t *val = arg->node_arg1;
> +                    if (val->node_op == op_String) {
> +                        parms.arg = val->node_arg1;
> +                    }
> +                    arg = arg->node_arg2;
> +                } while (arg != NULL);
> +                break;
> +            default:
> +                break;
> +        }
> +    }
> +                        ap_log_error(APLOG_MARK, APLOG_ERR, 0, 0,
> +                                    "sss %s", parms.arg);

I am currently getting the error “sss” (not sure what that means?) when attempting to
use named regex variables in LocationMatch - can you confirm this works as expected?

[Sun Dec 21 11:16:49.894286 2014] [core:error] [pid 42903:tid 140735132574464] sss MATCH_NUMBER
[Sun Dec 21 11:16:49.894359 2014] [core:error] [pid 42903:tid 140735132574464] sss MATCH_SUFFIX
[Sun Dec 21 11:16:49.894386 2014] [core:error] [pid 42903:tid 140735132574464] sss MATCH_NUMBER
[Sun Dec 21 11:16:49.894408 2014] [core:error] [pid 42903:tid 140735132574464] sss MATCH_NUMBER
[Sun Dec 21 11:16:49.894480 2014] [core:error] [pid 42903:tid 140735132574464] sss MATCH_NUMBER

Config looks like this:

    <LocationMatch /expr/ali(?<number>[0-9])>
        [DirectiveSupportingExpressions] /%{env:MATCH_NUMBER}.html
    </LocationMatch>

From the subsequent discussion, it looks like this patch breaks ap_expr_str_exec().

(Or perhaps this is noise and I am chasing something else - any idea what the error “sss”
means?)

Regards,
Graham
—


Mime
View raw message