]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Change apl_get_lua_state to take a apl_vm_spec instead of a filename, and to
authorPaul Querna <pquerna@apache.org>
Sun, 21 Dec 2008 22:21:54 +0000 (22:21 +0000)
committerPaul Querna <pquerna@apache.org>
Sun, 21 Dec 2008 22:21:54 +0000 (22:21 +0000)
load the bytecode if it is present, rather than the file, as this gets the
inline config file blocks hooks working again.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@728531 13f79535-47bb-0310-9956-ffa450edef68

modules/lua/lua_vmprep.c
modules/lua/lua_vmprep.h
modules/lua/mod_lua.c

index 66eabc673b901bc5eba359a5afcf4e8a3f2510f6..1623590cb75a0b2df768bb424425c177fd8e03f9 100644 (file)
@@ -258,7 +258,7 @@ static void munge_path(lua_State *L,
 }
 
 lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
-                             char *file,
+                             apl_vm_spec *spec,
                              apr_array_header_t *package_paths,
                              apr_array_header_t *package_cpaths,
                              apl_lua_state_open_callback cb, void *btn)
@@ -267,29 +267,37 @@ lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
     lua_State *L;
     ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
                   "obtaining lua_State");
-    if (!apr_pool_userdata_get((void **) &L, file, lifecycle_pool)) {
+    if (!apr_pool_userdata_get((void **) &L, spec->file, lifecycle_pool)) {
         ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
-                      "creating lua_State with file %s", file);
+                      "creating lua_State with file %s", spec->file);
         /* not available, so create */
         L = luaL_newstate();
         luaL_openlibs(L);
         if (package_paths)
             munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
-                       package_paths, file);
+                       package_paths, spec->file);
         if (package_cpaths)
             munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
-                       package_cpaths, file);
+                       package_cpaths, spec->file);
 
         if (cb) {
             cb(L, lifecycle_pool, btn);
         }
 
-        luaL_loadfile(L, file);
-        lua_pcall(L, 0, LUA_MULTRET, 0);
-        apr_pool_userdata_set(L, file, &cleanup_lua, lifecycle_pool);
+        apr_pool_userdata_set(L, spec->file, &cleanup_lua, lifecycle_pool);
+
+        if (spec->bytecode && spec->bytecode_len > 0) {
+            luaL_loadbuffer(L, spec->bytecode, spec->bytecode_len, spec->file);
+            lua_pcall(L, 0, LUA_MULTRET, 0);
+        }
+        else {
+            luaL_loadfile(L, spec->file);
+            lua_pcall(L, 0, LUA_MULTRET, 0);
+        }
 
         lua_pushlightuserdata(L, lifecycle_pool);
         lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Wombat.pool");
     }
+
     return L;
 }
index b2e4481319835d9084bd89d06bad9441976d613f..a0c37259bcb3a3c20e083a8cba85aebda7108359 100644 (file)
@@ -65,6 +65,10 @@ typedef struct
     /* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
     apr_pool_t *pool;
 
+    /* Pre-compiled Lua Byte code to load directly.  If bytecode_len is >0, 
+     * the file part of this structure is ignored for loading purposes, but
+     * it is used for error messages. 
+     */
     const char *bytecode;
     apr_size_t bytecode_len;
 } apl_vm_spec;
@@ -127,7 +131,7 @@ typedef void (*apl_lua_state_open_callback) (lua_State *L, apr_pool_t *p,
  * @ctx a baton passed to cb
  */
 lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
-                             char *file,
+                             apl_vm_spec *spec,
                              apr_array_header_t *package_paths,
                              apr_array_header_t *package_cpaths,
                              apl_lua_state_open_callback cb, void *btn);
index 328614d27b80cf372257c157e329b29d8f75370c..cd262caee1276be35626376c8184494faee3d778 100644 (file)
@@ -127,7 +127,7 @@ static int lua_handler(request_rec *r)
         const apl_dir_cfg *cfg =
             ap_get_module_config(r->per_dir_config, &lua_module);
         lua_State *L = apl_get_lua_state(r->pool,
-                                         d->spec->file,
+                                         d->spec,
                                          cfg->package_paths,
                                          cfg->package_cpaths,
                                          &lua_open_callback, NULL);
@@ -206,8 +206,8 @@ static int apl_alias_munger(request_rec *r)
 
 static int lua_request_rec_hook_harness(request_rec *r, const char *name)
 {
-    char *fixed_filename;
-
+    apl_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
+                                                      &lua_module);
     const apl_dir_cfg *cfg =
         (apl_dir_cfg *) ap_get_module_config(r->per_dir_config,
                                              &lua_module);
@@ -216,10 +216,13 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
     if (hook_specs) {
         int i;
         for (i = 0; i < hook_specs->nelts; i++) {
+            char *fixed_filename = NULL;
             apl_mapped_handler_spec *hook_spec =
                 ((apl_mapped_handler_spec **) hook_specs->elts)[i];
-            if (hook_spec == NULL)
+            
+            if (hook_spec == NULL) {
                 continue;
+            }
             apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
 
             spec->file = hook_spec->file_name;
@@ -229,20 +232,10 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
             spec->bytecode_len = hook_spec->bytecode_len;
             spec->pool = r->pool;
 
-            /*
-               const apl_dir_cfg* cfg = ap_get_module_config(r->per_dir_config, &lua_module);
-               lua_State *L =  apl_get_lua_state(r->pool,
-               d->spec->file,
-               cfg->package_paths,
-               cfg->package_cpaths,
-               &lua_open_callback, NULL);
-             */
-            apl_server_cfg *server_cfg =
-                ap_get_module_config(r->server->module_config, &lua_module);
-            apr_filepath_merge(&fixed_filename, server_cfg->root_path,
+            apr_filepath_merge(&spec->file, server_cfg->root_path,
                                spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
             lua_State *L = apl_get_lua_state(r->pool,
-                                             fixed_filename,
+                                             spec,
                                              cfg->package_paths,
                                              cfg->package_cpaths,
                                              &lua_open_callback, NULL);