From: Daniel Gruno Date: Sat, 15 Dec 2012 22:03:47 +0000 (+0000) Subject: mod_lua: If a regex fails, return false plus an error message as second return value... X-Git-Tag: 2.5.0-alpha~5995 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a3e2e44dc1f709f98fd372fbfc88ea5f5cc067b;p=apache 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. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1422373 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/lua/lua_apr.c b/modules/lua/lua_apr.c index 151b7552a3..383115945d 100644 --- a/modules/lua/lua_apr.c +++ b/modules/lua/lua_apr.c @@ -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(®ex, pattern,0)) { - return 0; + rv = ap_regcomp(®ex, pattern,0); + if (rv) { + lua_pushboolean(L, 0); + err = apr_palloc(r->pool, 256); + ap_regerror(rv, ®ex, err, 256); + lua_pushstring(L, err); + return 2; } - x = ap_regexec(®ex, source, 10, matches, 0); - if (x < 0) { + rv = ap_regexec(®ex, source, 10, matches, 0); + if (rv < 0) { + lua_pushboolean(L, 0); + err = apr_palloc(r->pool, 256); + ap_regerror(rv, ®ex, 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; } diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c index cd9a25f9ef..ebc60eddb0 100644 --- a/modules/lua/mod_lua.c +++ b/modules/lua/mod_lua.c @@ -116,6 +116,7 @@ static const char *scope_to_string(unsigned int scope) #endif default: ap_assert(0); + return 0; } }