1
0
mirror of https://github.com/apache/httpd.git synced 2025-08-07 04:02:58 +03:00

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
This commit is contained in:
Daniel Gruno
2012-12-15 22:03:47 +00:00
parent 98dd7b8224
commit 5a3e2e44dc
2 changed files with 18 additions and 9 deletions

View File

@@ -408,8 +408,9 @@ static int lua_ap_regex(lua_State *L)
{ {
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
request_rec *r; request_rec *r;
int x = 0, i; int i, rv;
const char *pattern, *source, *err; const char *pattern, *source;
char *err;
ap_regex_t regex; ap_regex_t regex;
ap_regmatch_t matches[10]; ap_regmatch_t matches[10];
/*~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~*/
@@ -420,15 +421,22 @@ static int lua_ap_regex(lua_State *L)
pattern = lua_tostring(L, 2); pattern = lua_tostring(L, 2);
source = lua_tostring(L, 3); source = lua_tostring(L, 3);
rv = ap_regcomp(&regex, pattern,0);
if (ap_regcomp(&regex, pattern,0)) { if (rv) {
return 0; 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); rv = ap_regexec(&regex, source, 10, matches, 0);
if (x < 0) { if (rv < 0) {
lua_pushboolean(L, 0);
err = apr_palloc(r->pool, 256);
ap_regerror(rv, &regex, err, 256);
lua_pushstring(L, err); lua_pushstring(L, err);
return 1; return 2;
} }
lua_newtable(L); lua_newtable(L);
for (i=0;i<10;i++) { 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"); lua_getglobal(L, "apache2");
luaL_register(L, NULL, httpd_functions); luaL_register(L, NULL, httpd_functions);
return 0;
} }

View File

@@ -116,6 +116,7 @@ static const char *scope_to_string(unsigned int scope)
#endif #endif
default: default:
ap_assert(0); ap_assert(0);
return 0;
} }
} }