]> granicus.if.org Git - apache/commitdiff
mod_lua: If a regex fails, return false plus an error message as second return value...
authorDaniel Gruno <humbedooh@apache.org>
Sat, 15 Dec 2012 22:03:47 +0000 (22:03 +0000)
committerDaniel Gruno <humbedooh@apache.org>
Sat, 15 Dec 2012 22:03:47 +0000 (22:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1422373 13f79535-47bb-0310-9956-ffa450edef68

modules/lua/lua_apr.c
modules/lua/mod_lua.c

index 151b7552a331e198394ef749d3c6cdf402f0435b..383115945d26a7049ce6ba9ae9c53438fcdc929d 100644 (file)
@@ -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_functions(lua_State *L)
 {
     lua_getglobal(L, "apache2");
     luaL_register(L, NULL, httpd_functions);
-
+    return 0;
 }
index cd9a25f9eff4c6650e34093197df3f05658ee6bb..ebc60eddb0afcd61337a14de4b0b01b92a30b0f4 100644 (file)
@@ -116,6 +116,7 @@ static const char *scope_to_string(unsigned int scope)
 #endif
     default:
         ap_assert(0);
+        return 0;
     }
 }