You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by hu...@apache.org on 2012/12/15 23:03:49 UTC

svn commit: r1422373 - in /httpd/httpd/trunk/modules/lua: lua_apr.c mod_lua.c

Author: humbedooh
Date: Sat Dec 15 22:03:47 2012
New Revision: 1422373

URL: http://svn.apache.org/viewvc?rev=1422373&view=rev
Log:
mod_lua: If a regex fails, return false plus an error message as second return value. Also fix some functions who weren't always returning a value.

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

Modified: httpd/httpd/trunk/modules/lua/lua_apr.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_apr.c?rev=1422373&r1=1422372&r2=1422373&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_apr.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_apr.c Sat Dec 15 22:03:47 2012
@@ -408,8 +408,9 @@ static int lua_ap_regex(lua_State *L) 
 {
     /*~~~~~~~~~~~~~~~~~~*/
     request_rec *r;
-    int x = 0, i;
-    const char *pattern, *source, *err;
+    int i, rv;
+    const char *pattern, *source;
+    char *err;
     ap_regex_t regex;
     ap_regmatch_t matches[10];
     /*~~~~~~~~~~~~~~~~~~*/
@@ -420,15 +421,22 @@ static int lua_ap_regex(lua_State *L) 
     pattern = lua_tostring(L, 2);
     source = lua_tostring(L, 3);
     
-    
-    if (ap_regcomp(&regex, pattern,0)) {
-        return 0;
+    rv = ap_regcomp(&regex, pattern,0);
+    if (rv) {
+        lua_pushboolean(L, 0);
+        err = apr_palloc(r->pool, 256);
+        ap_regerror(rv, &regex, err, 256);
+        lua_pushstring(L, err);
+        return 2;
     }
 
-    x = ap_regexec(&regex, source, 10, matches, 0);
-    if (x < 0) {
+    rv = ap_regexec(&regex, source, 10, matches, 0);
+    if (rv < 0) {
+        lua_pushboolean(L, 0);
+        err = apr_palloc(r->pool, 256);
+        ap_regerror(rv, &regex, err, 256);
         lua_pushstring(L, err);
-        return 1;
+        return 2;
     }
     lua_newtable(L);
     for (i=0;i<10;i++) {
@@ -1121,5 +1129,5 @@ AP_LUA_DECLARE(int) ap_lua_load_httpd_fu
 {
     lua_getglobal(L, "apache2");
     luaL_register(L, NULL, httpd_functions);
-
+    return 0;
 }

Modified: httpd/httpd/trunk/modules/lua/mod_lua.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/mod_lua.c?rev=1422373&r1=1422372&r2=1422373&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/mod_lua.c (original)
+++ httpd/httpd/trunk/modules/lua/mod_lua.c Sat Dec 15 22:03:47 2012
@@ -116,6 +116,7 @@ static const char *scope_to_string(unsig
 #endif
     default:
         ap_assert(0);
+        return 0;
     }
 }