Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Dev

Fwd: svn commit: r1367725 - /httpd/httpd/trunk/modules/lua/mod_lua.c

 

 

Apache dev RSS feed   Index | Next | Previous | View Threaded


ruediger.pluem at vodafone

Jul 31, 2012, 11:38 PM

Post #1 of 2 (133 views)
Permalink
Fwd: svn commit: r1367725 - /httpd/httpd/trunk/modules/lua/mod_lua.c

-------- Original Message --------
Subject: svn commit: r1367725 - /httpd/httpd/trunk/modules/lua/mod_lua.c
Date: Tue, 31 Jul 2012 19:43:30 GMT
From: humbedooh [at] apache



Author: humbedooh
Date: Tue Jul 31 19:43:29 2012
New Revision: 1367725

URL: http://svn.apache.org/viewvc?rev=1367725&view=rev
Log:
mod_lua: Add the (missing) LuaMapHandler directive to the fold.
This should work as the existing documentation describes.

Modified:
httpd/httpd/trunk/modules/lua/mod_lua.c

Modified: httpd/httpd/trunk/modules/lua/mod_lua.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/mod_lua.c?rev=1367725&r1=1367724&r2=1367725&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/mod_lua.c (original)
+++ httpd/httpd/trunk/modules/lua/mod_lua.c Tue Jul 31 19:43:29 2012
@@ -170,6 +170,35 @@ static ap_lua_vm_spec *create_vm_spec(ap
return spec;
}

+static const char* ap_lua_interpolate_string(apr_pool_t* pool, const char* string, const
char** values)
+{
+ char *stringBetween;
+ const char* ret;
+ int srclen,x,y;
+ srclen = strlen(string);
+ ret = "";
+ y = 0;
+ for (x=0; x< srclen; x++) {
+ if (string[x] == '
&& x != srclen-1&& string[x+1]>= '0'&&
string[x+1]<= '9') {
+ if (x-y> 0) {
+ stringBetween = apr_pstrndup(pool, string+y, x-y);
+ }
+ else stringBetween = "";

Style. Please review the style guide (code should be on the next line)

+ int v = atoi(apr_pstrndup(pool,string+x+1, 1));

As this is only one digit you can convert directly, e.g. *(string+x+1) - '0' and avoid
copying the string.

+ ret = apr_psprintf(pool, "%s%s%s", ret, stringBetween, values[v]);

As you only concat strings here use apr_pstrcat here.

+ y = ++x;
+ }
+ }
+
+ if (x-y> 0&& y> 0) {
+ stringBetween = apr_pstrndup(pool, string+y+1, x-y);
+ ret = apr_psprintf(pool, "%s%s", ret, stringBetween);


As you only concat strings here use apr_pstrcat here.

+ }
+ else if (y==0) return string; /* If no replacement was made, just return the original
str. */

Style. Please review the style guide (comment should be on a separate line, code on the next line)

+ return ret;
+}
+
+

Regards

Rüdiger


rumble at cord

Aug 1, 2012, 12:33 AM

Post #2 of 2 (124 views)
Permalink
Re: Fwd: svn commit: r1367725 - /httpd/httpd/trunk/modules/lua/mod_lua.c [In reply to]

On 08/01/2012 08:38 AM, Rüdiger Plüm wrote:
>
>
> -------- Original Message --------
> Subject: svn commit: r1367725 -
> /httpd/httpd/trunk/modules/lua/mod_lua.c
> Date: Tue, 31 Jul 2012 19:43:30 GMT
> From: humbedooh [at] apache
>
>
>
> Author: humbedooh
> Date: Tue Jul 31 19:43:29 2012
> New Revision: 1367725
>
> URL: http://svn.apache.org/viewvc?rev=1367725&view=rev
> Log:
> mod_lua: Add the (missing) LuaMapHandler directive to the fold.
> This should work as the existing documentation describes.
>
> Modified:
> httpd/httpd/trunk/modules/lua/mod_lua.c
>
> Modified: httpd/httpd/trunk/modules/lua/mod_lua.c
> URL:
> http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/mod_lua.c?rev=1367725&r1=1367724&r2=1367725&view=diff
>
> ==============================================================================
>
> --- httpd/httpd/trunk/modules/lua/mod_lua.c (original)
> +++ httpd/httpd/trunk/modules/lua/mod_lua.c Tue Jul 31 19:43:29 2012
> @@ -170,6 +170,35 @@ static ap_lua_vm_spec *create_vm_spec(ap
> return spec;
> }
>
> +static const char* ap_lua_interpolate_string(apr_pool_t* pool, const
> char* string, const
> char** values)
> +{
> + char *stringBetween;
> + const char* ret;
> + int srclen,x,y;
> + srclen = strlen(string);
> + ret = "";
> + y = 0;
> + for (x=0; x< srclen; x++) {
> + if (string[x] == '
> && x != srclen-1&& string[x+1]>= '0'&&
> string[x+1]<= '9') {
> + if (x-y> 0) {
> + stringBetween = apr_pstrndup(pool, string+y, x-y);
> + }
> + else stringBetween = "";
>
> Style. Please review the style guide (code should be on the next line)
>
> + int v = atoi(apr_pstrndup(pool,string+x+1, 1));
>
> As this is only one digit you can convert directly, e.g. *(string+x+1) -
> '0' and avoid
> copying the string.
>
> + ret = apr_psprintf(pool, "%s%s%s", ret, stringBetween,
> values[v]);
>
> As you only concat strings here use apr_pstrcat here.
>
> + y = ++x;
> + }
> + }
> +
> + if (x-y> 0&& y> 0) {
> + stringBetween = apr_pstrndup(pool, string+y+1, x-y);
> + ret = apr_psprintf(pool, "%s%s", ret, stringBetween);
>
>
> As you only concat strings here use apr_pstrcat here.
>
> + }
> + else if (y==0) return string; /* If no replacement was made, just
> return the original
> str. */
>
> Style. Please review the style guide (comment should be on a separate
> line, code on the next line)
>
> + return ret;
> +}
> +
> +
>
> Regards
>
> Rüdiger
>
>
Thanks for the heads up :)
This also made me discover a bug in the string interpolation function,
that kept the number (fx 1 in $1) instead of discarding it in the
replacement string.

With regards,
Daniel.

Apache dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.