@@ -39,12 +39,13 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(apl, AP_LUA, int, lua_request,
3939 */
4040static void report_lua_error (lua_State * L , request_rec * r )
4141{
42+ const char * lua_response ;
4243 r -> status = 500 ;
4344 r -> content_type = "text/html" ;
4445
4546 ap_rputs ("<b>Error!</b>\n" , r );
4647 ap_rputs ("<p>" , r );
47- const char * lua_response = lua_tostring (L , -1 );
48+ lua_response = lua_tostring (L , -1 );
4849 ap_rputs (lua_response , r );
4950 ap_rputs ("</p>\n" , r );
5051
@@ -107,10 +108,14 @@ static int lua_handler(request_rec *r)
107108 apl_dir_cfg * dcfg = ap_get_module_config (r -> per_dir_config , & lua_module );
108109
109110 if (!r -> header_only ) {
111+ lua_State * L ;
112+ const apl_dir_cfg * cfg = ap_get_module_config (r -> per_dir_config ,
113+ & lua_module );
110114 apl_request_cfg * rcfg =
111115 ap_get_module_config (r -> request_config , & lua_module );
112116 mapped_request_details * d = rcfg -> mapped_request_details ;
113117 apl_vm_spec * spec = NULL ;
118+
114119 if (!d ) {
115120 d = apr_palloc (r -> pool , sizeof (mapped_request_details ));
116121 spec = apr_pcalloc (r -> pool , sizeof (apl_vm_spec ));
@@ -121,16 +126,15 @@ static int lua_handler(request_rec *r)
121126 d -> spec = spec ;
122127 d -> function_name = "handle" ;
123128 }
129+
124130 ap_log_rerror (APLOG_MARK , APLOG_DEBUG , 0 , r ,
125131 "request details scope:%u, cache:%u" , d -> spec -> scope ,
126132 d -> spec -> code_cache_style );
127- const apl_dir_cfg * cfg =
128- ap_get_module_config (r -> per_dir_config , & lua_module );
129- lua_State * L = apl_get_lua_state (r -> pool ,
130- d -> spec ,
131- cfg -> package_paths ,
132- cfg -> package_cpaths ,
133- & lua_open_callback , NULL );
133+ L = apl_get_lua_state (r -> pool ,
134+ d -> spec ,
135+ cfg -> package_paths ,
136+ cfg -> package_cpaths ,
137+ & lua_open_callback , NULL );
134138
135139 ap_log_rerror (APLOG_MARK , APLOG_DEBUG , 0 , r , "got a vm!" );
136140 if (!L ) {
@@ -154,22 +158,24 @@ static int lua_handler(request_rec *r)
154158 */
155159static int apl_alias_munger (request_rec * r )
156160{
161+ apl_vm_spec * spec ;
162+ apl_request_cfg * rcfg = ap_get_module_config (r -> request_config ,
163+ & lua_module );
157164 const apl_dir_cfg * cfg =
158165 ap_get_module_config (r -> per_dir_config , & lua_module );
159-
160166 int i ;
161167 ap_regmatch_t matches [AP_MAX_REG_MATCH ];
162168
163169 for (i = 0 ; i < cfg -> mapped_handlers -> nelts ; i ++ ) {
164170 const apl_mapped_handler_spec * cnd =
165- ((const apl_mapped_handler_spec * * ) cfg -> mapped_handlers ->
166- elts )[ i ];
171+ ((const apl_mapped_handler_spec * * ) cfg -> mapped_handlers -> elts )[ i ];
172+
167173 if (OK ==
168174 ap_regexec (cnd -> uri_pattern , r -> uri , AP_MAX_REG_MATCH , matches ,
169175 0 )) {
170176 r -> handler = "lua-script" ;
171177
172- apl_vm_spec * spec = apr_pcalloc (r -> pool , sizeof (apl_vm_spec ));
178+ spec = apr_pcalloc (r -> pool , sizeof (apl_vm_spec ));
173179 spec -> file =
174180 ap_pregsub (r -> pool , cnd -> file_name , r -> uri , AP_MAX_REG_MATCH ,
175181 matches );
@@ -191,8 +197,6 @@ static int apl_alias_munger(request_rec *r)
191197
192198 /* now do replacement on method name where? */
193199 r -> filename = apr_pstrdup (r -> pool , spec -> file );
194- apl_request_cfg * rcfg =
195- ap_get_module_config (r -> request_config , & lua_module );
196200 rcfg -> mapped_request_details = d ;
197201 return OK ;
198202 }
@@ -206,6 +210,8 @@ static int apl_alias_munger(request_rec *r)
206210
207211static int lua_request_rec_hook_harness (request_rec * r , const char * name )
208212{
213+ lua_State * L ;
214+ apl_vm_spec * spec ;
209215 apl_server_cfg * server_cfg = ap_get_module_config (r -> server -> module_config ,
210216 & lua_module );
211217 const apl_dir_cfg * cfg =
@@ -223,7 +229,7 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
223229 if (hook_spec == NULL ) {
224230 continue ;
225231 }
226- apl_vm_spec * spec = apr_pcalloc (r -> pool , sizeof (apl_vm_spec ));
232+ spec = apr_pcalloc (r -> pool , sizeof (apl_vm_spec ));
227233
228234 spec -> file = hook_spec -> file_name ;
229235 spec -> code_cache_style = hook_spec -> code_cache_style ;
@@ -234,11 +240,11 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
234240
235241 apr_filepath_merge (& spec -> file , server_cfg -> root_path ,
236242 spec -> file , APR_FILEPATH_NOTRELATIVE , r -> pool );
237- lua_State * L = apl_get_lua_state (r -> pool ,
238- spec ,
239- cfg -> package_paths ,
240- cfg -> package_cpaths ,
241- & lua_open_callback , NULL );
243+ L = apl_get_lua_state (r -> pool ,
244+ spec ,
245+ cfg -> package_paths ,
246+ cfg -> package_cpaths ,
247+ & lua_open_callback , NULL );
242248
243249
244250
@@ -446,6 +452,7 @@ static const char *register_named_block_function_hook(const char *name,
446452 lua_State * lvm ;
447453 char * tmp ;
448454 int rv ;
455+ ap_directive_t * * current ;
449456
450457 apr_snprintf (buf , sizeof (buf ), "%u" , cmd -> config_file -> line_number );
451458 spec -> file_name =
@@ -491,7 +498,7 @@ static const char *register_named_block_function_hook(const char *name,
491498 lua_close (lvm );
492499 }
493500
494- ap_directive_t * * current = mconfig ;
501+ current = mconfig ;
495502
496503 /* Here, we have to replace our current config node for the next pass */
497504 if (!* current ) {
@@ -520,6 +527,7 @@ static const char *register_named_file_function_hook(const char *name,
520527 const char * file ,
521528 const char * function )
522529{
530+ apl_mapped_handler_spec * spec ;
523531 apl_dir_cfg * cfg = (apl_dir_cfg * ) _cfg ;
524532
525533 apr_array_header_t * hook_specs =
@@ -531,8 +539,7 @@ static const char *register_named_file_function_hook(const char *name,
531539 APR_HASH_KEY_STRING , hook_specs );
532540 }
533541
534- apl_mapped_handler_spec * spec =
535- apr_pcalloc (cmd -> pool , sizeof (apl_mapped_handler_spec ));
542+ spec = apr_pcalloc (cmd -> pool , sizeof (apl_mapped_handler_spec ));
536543 spec -> file_name = apr_pstrdup (cmd -> pool , file );
537544 spec -> function_name = apr_pstrdup (cmd -> pool , function );
538545 spec -> scope = cfg -> vm_scope ;
@@ -823,10 +830,9 @@ static const char *lua_map_handler(cmd_parms *cmd, void *_cfg,
823830 const char * function )
824831{
825832 apl_dir_cfg * cfg = (apl_dir_cfg * ) _cfg ;
826-
833+ apr_status_t rv ;
827834 const char * function_name ;
828835 function_name = function ? function : "handle" ;
829- apr_status_t rv ;
830836 rv = apl_lua_map_handler (cfg , file , function_name , path , "once" );
831837 if (rv != APR_SUCCESS ) {
832838 return apr_psprintf (cmd -> pool ,
0 commit comments