2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include "util_script.h"
22 APLOG_USE_MODULE(lua);
24 typedef char *(*req_field_string_f) (request_rec * r);
25 typedef int (*req_field_int_f) (request_rec * r);
26 typedef apr_table_t *(*req_field_apr_table_f) (request_rec * r);
28 void ap_lua_rstack_dump(lua_State *L, request_rec *r, const char *msg)
31 int top = lua_gettop(L);
33 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01484) "Lua Stack Dump: [%s]", msg);
35 for (i = 1; i <= top; i++) {
36 int t = lua_type(L, i);
39 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
40 "%d: '%s'", i, lua_tostring(L, i));
44 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d: userdata",
48 case LUA_TLIGHTUSERDATA:{
49 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
50 "%d: lightuserdata", i);
54 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d: NIL", i);
58 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d: None", i);
62 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
63 "%d: %s", i, lua_toboolean(L,
69 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
70 "%d: %g", i, lua_tonumber(L, i));
74 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
79 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
84 ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
85 "%d: unkown: -[%s]-", i, lua_typename(L, i));
93 * Verify that the thing at index is a request_rec wrapping
94 * userdata thingamajig and return it if it is. if it is not
95 * lua will enter its error handling routine.
97 static request_rec *ap_lua_check_request_rec(lua_State *L, int index)
100 luaL_checkudata(L, index, "Apache2.Request");
101 r = (request_rec *) lua_unboxpointer(L, index);
105 /* ------------------ request methods -------------------- */
106 /* helper callback for req_parseargs */
107 static int req_aprtable2luatable_cb(void *l, const char *key,
111 lua_State *L = (lua_State *) l; /* [table<s,t>, table<s,s>] */
112 /* rstack_dump(L, RRR, "start of cb"); */
113 /* L is [table<s,t>, table<s,s>] */
116 lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */
117 /* rstack_dump(L, RRR, "after getfield"); */
122 lua_pop(L, 1); /* [table<s,t>, table<s,s>] */
123 lua_newtable(L); /* [array, table<s,t>, table<s,s>] */
124 lua_pushnumber(L, 1); /* [1, array, table<s,t>, table<s,s>] */
125 lua_pushstring(L, value); /* [string, 1, array, table<s,t>, table<s,s>] */
126 lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */
127 lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */
131 /* [array, table<s,t>, table<s,s>] */
132 int size = lua_objlen(L, -1);
133 lua_pushnumber(L, size + 1); /* [#, array, table<s,t>, table<s,s>] */
134 lua_pushstring(L, value); /* [string, #, array, table<s,t>, table<s,s>] */
135 lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */
136 lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */
141 /* L is [table<s,t>, table<s,s>] */
143 lua_getfield(L, -2, key); /* [VALUE, table<s,s>, table<s,t>] */
144 if (lua_isnoneornil(L, -1)) { /* only set if not already set */
145 lua_pop(L, 1); /* [table<s,s>, table<s,t>]] */
146 lua_pushstring(L, value); /* [string, table<s,s>, table<s,t>] */
147 lua_setfield(L, -3, key); /* [table<s,s>, table<s,t>] */
155 /* r:parseargs() returning a lua table */
156 static int req_parseargs(lua_State *L)
158 apr_table_t *form_table;
159 request_rec *r = ap_lua_check_request_rec(L, 1);
161 lua_newtable(L); /* [table, table] */
162 ap_args_to_table(r, &form_table);
163 apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);
164 return 2; /* [table<string, string>, table<string, array<string>>] */
167 /* wrap ap_rputs as r:puts(String) */
168 static int req_puts(lua_State *L)
170 request_rec *r = ap_lua_check_request_rec(L, 1);
172 int argc = lua_gettop(L);
175 for (i = 2; i <= argc; i++) {
176 ap_rputs(luaL_checkstring(L, i), r);
181 /* wrap ap_rwrite as r:write(String) */
182 static int req_write(lua_State *L)
184 request_rec *r = ap_lua_check_request_rec(L, 1);
186 const char *buf = luaL_checklstring(L, 2, &n);
188 ap_rwrite((void *) buf, n, r);
192 /* r:addoutputfilter(name|function) */
193 static int req_add_output_filter(lua_State *L)
195 request_rec *r = ap_lua_check_request_rec(L, 1);
196 const char *name = luaL_checkstring(L, 2);
197 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01485) "adding output filter %s",
199 ap_add_output_filter(name, L, r, r->connection);
203 /* wrap ap_construct_url as r:construct_url(String) */
204 static int req_construct_url(lua_State *L)
206 request_rec *r = ap_lua_check_request_rec(L, 1);
207 const char *name = luaL_checkstring(L, 2);
208 lua_pushstring(L, ap_construct_url(r->pool, name, r));
212 /* wrap ap_escape_html r:escape_html(String) */
213 static int req_escape_html(lua_State *L)
215 request_rec *r = ap_lua_check_request_rec(L, 1);
216 const char *s = luaL_checkstring(L, 2);
217 lua_pushstring(L, ap_escape_html(r->pool, s));
220 /* wrap optional ssl_var_lookup as r:ssl_var_lookup(String) */
221 static int req_ssl_var_lookup(lua_State *L)
223 request_rec *r = ap_lua_check_request_rec(L, 1);
224 const char *s = luaL_checkstring(L, 2);
225 const char *res = ap_lua_ssl_val(r->pool, r->server, r->connection, r,
227 lua_pushstring(L, res);
230 /* BEGIN dispatch mathods for request_rec fields */
232 /* not really a field, but we treat it like one */
233 static const char *req_document_root(request_rec *r)
235 return ap_document_root(r);
238 static char *req_uri_field(request_rec *r)
243 static const char *req_method_field(request_rec *r)
247 static const char *req_handler_field(request_rec *r)
251 static const char *req_proxyreq_field(request_rec *r)
253 switch (r->proxyreq) {
254 case PROXYREQ_NONE: return "PROXYREQ_NONE";
255 case PROXYREQ_PROXY: return "PROXYREQ_PROXY";
256 case PROXYREQ_REVERSE: return "PROXYREQ_REVERSE";
257 case PROXYREQ_RESPONSE: return "PROXYREQ_RESPONSE";
258 default: return NULL;
261 static const char *req_hostname_field(request_rec *r)
266 static const char *req_args_field(request_rec *r)
271 static const char *req_path_info_field(request_rec *r)
276 static const char *req_canonical_filename_field(request_rec *r)
278 return r->canonical_filename;
281 static const char *req_filename_field(request_rec *r)
286 static const char *req_user_field(request_rec *r)
291 static const char *req_unparsed_uri_field(request_rec *r)
293 return r->unparsed_uri;
296 static const char *req_ap_auth_type_field(request_rec *r)
298 return r->ap_auth_type;
301 static const char *req_content_encoding_field(request_rec *r)
303 return r->content_encoding;
306 static const char *req_content_type_field(request_rec *r)
308 return r->content_type;
311 static const char *req_range_field(request_rec *r)
316 static const char *req_protocol_field(request_rec *r)
321 static const char *req_the_request_field(request_rec *r)
323 return r->the_request;
326 static int req_status_field(request_rec *r)
331 static int req_assbackwards_field(request_rec *r)
333 return r->assbackwards;
336 static apr_table_t* req_headers_in(request_rec *r)
338 return r->headers_in;
341 static apr_table_t* req_headers_out(request_rec *r)
343 return r->headers_out;
346 static apr_table_t* req_err_headers_out(request_rec *r)
348 return r->err_headers_out;
351 static apr_table_t* req_subprocess_env(request_rec *r)
353 return r->subprocess_env;
356 static apr_table_t* req_notes(request_rec *r)
361 static int req_ssl_is_https_field(request_rec *r)
363 return ap_lua_ssl_is_https(r->connection);
366 /* END dispatch mathods for request_rec fields */
368 static int req_dispatch(lua_State *L)
370 apr_hash_t *dispatch;
372 request_rec *r = ap_lua_check_request_rec(L, 1);
373 const char *name = luaL_checkstring(L, 2);
376 lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
377 dispatch = lua_touserdata(L, 1);
380 rft = apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
383 case APL_REQ_FUNTYPE_TABLE:{
385 req_field_apr_table_f func = (req_field_apr_table_f)rft->fun;
386 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01486)
387 "request_rec->dispatching %s -> apr table",
390 ap_lua_push_apr_table(L, rs);
394 case APL_REQ_FUNTYPE_LUACFUN:{
395 lua_CFunction func = (lua_CFunction)rft->fun;
396 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01487)
397 "request_rec->dispatching %s -> lua_CFunction",
399 lua_pushcfunction(L, func);
402 case APL_REQ_FUNTYPE_STRING:{
403 req_field_string_f func = (req_field_string_f)rft->fun;
405 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01488)
406 "request_rec->dispatching %s -> string", name);
408 lua_pushstring(L, rs);
411 case APL_REQ_FUNTYPE_INT:{
412 req_field_int_f func = (req_field_int_f)rft->fun;
414 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01489)
415 "request_rec->dispatching %s -> int", name);
417 lua_pushnumber(L, rs);
420 case APL_REQ_FUNTYPE_BOOLEAN:{
421 req_field_int_f func = (req_field_int_f)rft->fun;
423 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01490)
424 "request_rec->dispatching %s -> boolean", name);
426 lua_pushboolean(L, rs);
432 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01491) "nothing for %s", name);
436 /* helper function for the logging functions below */
437 static int req_log_at(lua_State *L, int level)
440 request_rec *r = ap_lua_check_request_rec(L, 1);
443 lua_getstack(L, 1, &dbg);
444 lua_getinfo(L, "Sl", &dbg);
446 msg = luaL_checkstring(L, 2);
447 ap_log_rerror(dbg.source, dbg.currentline, APLOG_MODULE_INDEX, level, 0,
452 /* r:debug(String) and friends which use apache logging */
453 static int req_emerg(lua_State *L)
455 req_log_at(L, APLOG_EMERG);
458 static int req_alert(lua_State *L)
460 req_log_at(L, APLOG_ALERT);
463 static int req_crit(lua_State *L)
465 req_log_at(L, APLOG_CRIT);
468 static int req_err(lua_State *L)
470 req_log_at(L, APLOG_ERR);
473 static int req_warn(lua_State *L)
475 req_log_at(L, APLOG_WARNING);
478 static int req_notice(lua_State *L)
480 req_log_at(L, APLOG_NOTICE);
483 static int req_info(lua_State *L)
485 req_log_at(L, APLOG_INFO);
488 static int req_debug(lua_State *L)
490 req_log_at(L, APLOG_DEBUG);
494 #define APLUA_REQ_TRACE(lev) static int req_trace##lev(lua_State *L) \
496 req_log_at(L, APLOG_TRACE##lev); \
509 /* handle r.status = 201 */
510 static int req_newindex(lua_State *L)
513 /* request_rec* r = lua_touserdata(L, lua_upvalueindex(1)); */
514 /* const char* key = luaL_checkstring(L, -2); */
515 request_rec *r = ap_lua_check_request_rec(L, 1);
516 key = luaL_checkstring(L, 2);
518 if (0 == strcmp("args", key)) {
519 const char *value = luaL_checkstring(L, 3);
520 r->args = apr_pstrdup(r->pool, value);
524 if (0 == strcmp("content_type", key)) {
525 const char *value = luaL_checkstring(L, 3);
526 ap_set_content_type(r, apr_pstrdup(r->pool, value));
530 if (0 == strcmp("filename", key)) {
531 const char *value = luaL_checkstring(L, 3);
532 r->filename = apr_pstrdup(r->pool, value);
536 if (0 == strcmp("handler", key)) {
537 const char *value = luaL_checkstring(L, 3);
538 r->handler = apr_pstrdup(r->pool, value);
542 if (0 == strcmp("proxyreq", key)) {
543 int value = luaL_checkinteger(L, 3);
548 if (0 == strcmp("status", key)) {
549 int code = luaL_checkinteger(L, 3);
554 if (0 == strcmp("uri", key)) {
555 const char *value = luaL_checkstring(L, 3);
556 r->uri = apr_pstrdup(r->pool, value);
560 if (0 == strcmp("user", key)) {
561 const char *value = luaL_checkstring(L, 3);
562 r->user = apr_pstrdup(r->pool, value);
567 apr_psprintf(r->pool,
568 "Property [%s] may not be set on a request_rec",
574 static const struct luaL_Reg request_methods[] = {
575 {"__index", req_dispatch},
576 {"__newindex", req_newindex},
577 /* {"__newindex", req_set_field}, */
582 static const struct luaL_Reg connection_methods[] = {
587 static const struct luaL_Reg server_methods[] = {
592 static req_fun_t *makefun(const void *fun, int type, apr_pool_t *pool)
594 req_fun_t *rft = apr_palloc(pool, sizeof(req_fun_t));
600 AP_LUA_DECLARE(void) ap_lua_load_request_lmodule(lua_State *L, apr_pool_t *p)
603 apr_hash_t *dispatch = apr_hash_make(p);
605 apr_hash_set(dispatch, "puts", APR_HASH_KEY_STRING,
606 makefun(&req_puts, APL_REQ_FUNTYPE_LUACFUN, p));
607 apr_hash_set(dispatch, "write", APR_HASH_KEY_STRING,
608 makefun(&req_write, APL_REQ_FUNTYPE_LUACFUN, p));
609 apr_hash_set(dispatch, "document_root", APR_HASH_KEY_STRING,
610 makefun(&req_document_root, APL_REQ_FUNTYPE_STRING, p));
611 apr_hash_set(dispatch, "parseargs", APR_HASH_KEY_STRING,
612 makefun(&req_parseargs, APL_REQ_FUNTYPE_LUACFUN, p));
613 apr_hash_set(dispatch, "debug", APR_HASH_KEY_STRING,
614 makefun(&req_debug, APL_REQ_FUNTYPE_LUACFUN, p));
615 apr_hash_set(dispatch, "info", APR_HASH_KEY_STRING,
616 makefun(&req_info, APL_REQ_FUNTYPE_LUACFUN, p));
617 apr_hash_set(dispatch, "notice", APR_HASH_KEY_STRING,
618 makefun(&req_notice, APL_REQ_FUNTYPE_LUACFUN, p));
619 apr_hash_set(dispatch, "warn", APR_HASH_KEY_STRING,
620 makefun(&req_warn, APL_REQ_FUNTYPE_LUACFUN, p));
621 apr_hash_set(dispatch, "err", APR_HASH_KEY_STRING,
622 makefun(&req_err, APL_REQ_FUNTYPE_LUACFUN, p));
623 apr_hash_set(dispatch, "crit", APR_HASH_KEY_STRING,
624 makefun(&req_crit, APL_REQ_FUNTYPE_LUACFUN, p));
625 apr_hash_set(dispatch, "alert", APR_HASH_KEY_STRING,
626 makefun(&req_alert, APL_REQ_FUNTYPE_LUACFUN, p));
627 apr_hash_set(dispatch, "emerg", APR_HASH_KEY_STRING,
628 makefun(&req_emerg, APL_REQ_FUNTYPE_LUACFUN, p));
629 apr_hash_set(dispatch, "trace1", APR_HASH_KEY_STRING,
630 makefun(&req_trace1, APL_REQ_FUNTYPE_LUACFUN, p));
631 apr_hash_set(dispatch, "trace2", APR_HASH_KEY_STRING,
632 makefun(&req_trace2, APL_REQ_FUNTYPE_LUACFUN, p));
633 apr_hash_set(dispatch, "trace3", APR_HASH_KEY_STRING,
634 makefun(&req_trace3, APL_REQ_FUNTYPE_LUACFUN, p));
635 apr_hash_set(dispatch, "trace4", APR_HASH_KEY_STRING,
636 makefun(&req_trace4, APL_REQ_FUNTYPE_LUACFUN, p));
637 apr_hash_set(dispatch, "trace5", APR_HASH_KEY_STRING,
638 makefun(&req_trace5, APL_REQ_FUNTYPE_LUACFUN, p));
639 apr_hash_set(dispatch, "trace6", APR_HASH_KEY_STRING,
640 makefun(&req_trace6, APL_REQ_FUNTYPE_LUACFUN, p));
641 apr_hash_set(dispatch, "trace7", APR_HASH_KEY_STRING,
642 makefun(&req_trace7, APL_REQ_FUNTYPE_LUACFUN, p));
643 apr_hash_set(dispatch, "trace8", APR_HASH_KEY_STRING,
644 makefun(&req_trace8, APL_REQ_FUNTYPE_LUACFUN, p));
645 apr_hash_set(dispatch, "add_output_filter", APR_HASH_KEY_STRING,
646 makefun(&req_add_output_filter, APL_REQ_FUNTYPE_LUACFUN, p));
647 apr_hash_set(dispatch, "construct_url", APR_HASH_KEY_STRING,
648 makefun(&req_construct_url, APL_REQ_FUNTYPE_LUACFUN, p));
649 apr_hash_set(dispatch, "escape_html", APR_HASH_KEY_STRING,
650 makefun(&req_escape_html, APL_REQ_FUNTYPE_LUACFUN, p));
651 apr_hash_set(dispatch, "ssl_var_lookup", APR_HASH_KEY_STRING,
652 makefun(&req_ssl_var_lookup, APL_REQ_FUNTYPE_LUACFUN, p));
653 apr_hash_set(dispatch, "is_https", APR_HASH_KEY_STRING,
654 makefun(&req_ssl_is_https_field, APL_REQ_FUNTYPE_BOOLEAN, p));
655 apr_hash_set(dispatch, "assbackwards", APR_HASH_KEY_STRING,
656 makefun(&req_assbackwards_field, APL_REQ_FUNTYPE_BOOLEAN, p));
657 apr_hash_set(dispatch, "status", APR_HASH_KEY_STRING,
658 makefun(&req_status_field, APL_REQ_FUNTYPE_INT, p));
659 apr_hash_set(dispatch, "protocol", APR_HASH_KEY_STRING,
660 makefun(&req_protocol_field, APL_REQ_FUNTYPE_STRING, p));
661 apr_hash_set(dispatch, "range", APR_HASH_KEY_STRING,
662 makefun(&req_range_field, APL_REQ_FUNTYPE_STRING, p));
663 apr_hash_set(dispatch, "content_type", APR_HASH_KEY_STRING,
664 makefun(&req_content_type_field, APL_REQ_FUNTYPE_STRING, p));
665 apr_hash_set(dispatch, "content_encoding", APR_HASH_KEY_STRING,
666 makefun(&req_content_encoding_field, APL_REQ_FUNTYPE_STRING,
668 apr_hash_set(dispatch, "ap_auth_type", APR_HASH_KEY_STRING,
669 makefun(&req_ap_auth_type_field, APL_REQ_FUNTYPE_STRING, p));
670 apr_hash_set(dispatch, "unparsed_uri", APR_HASH_KEY_STRING,
671 makefun(&req_unparsed_uri_field, APL_REQ_FUNTYPE_STRING, p));
672 apr_hash_set(dispatch, "user", APR_HASH_KEY_STRING,
673 makefun(&req_user_field, APL_REQ_FUNTYPE_STRING, p));
674 apr_hash_set(dispatch, "filename", APR_HASH_KEY_STRING,
675 makefun(&req_filename_field, APL_REQ_FUNTYPE_STRING, p));
676 apr_hash_set(dispatch, "canonical_filename", APR_HASH_KEY_STRING,
677 makefun(&req_canonical_filename_field,
678 APL_REQ_FUNTYPE_STRING, p));
679 apr_hash_set(dispatch, "path_info", APR_HASH_KEY_STRING,
680 makefun(&req_path_info_field, APL_REQ_FUNTYPE_STRING, p));
681 apr_hash_set(dispatch, "args", APR_HASH_KEY_STRING,
682 makefun(&req_args_field, APL_REQ_FUNTYPE_STRING, p));
683 apr_hash_set(dispatch, "handler", APR_HASH_KEY_STRING,
684 makefun(&req_handler_field, APL_REQ_FUNTYPE_STRING, p));
685 apr_hash_set(dispatch, "hostname", APR_HASH_KEY_STRING,
686 makefun(&req_hostname_field, APL_REQ_FUNTYPE_STRING, p));
687 apr_hash_set(dispatch, "uri", APR_HASH_KEY_STRING,
688 makefun(&req_uri_field, APL_REQ_FUNTYPE_STRING, p));
689 apr_hash_set(dispatch, "the_request", APR_HASH_KEY_STRING,
690 makefun(&req_the_request_field, APL_REQ_FUNTYPE_STRING, p));
691 apr_hash_set(dispatch, "method", APR_HASH_KEY_STRING,
692 makefun(&req_method_field, APL_REQ_FUNTYPE_STRING, p));
693 apr_hash_set(dispatch, "proxyreq", APR_HASH_KEY_STRING,
694 makefun(&req_proxyreq_field, APL_REQ_FUNTYPE_STRING, p));
695 apr_hash_set(dispatch, "headers_in", APR_HASH_KEY_STRING,
696 makefun(&req_headers_in, APL_REQ_FUNTYPE_TABLE, p));
697 apr_hash_set(dispatch, "headers_out", APR_HASH_KEY_STRING,
698 makefun(&req_headers_out, APL_REQ_FUNTYPE_TABLE, p));
699 apr_hash_set(dispatch, "err_headers_out", APR_HASH_KEY_STRING,
700 makefun(&req_err_headers_out, APL_REQ_FUNTYPE_TABLE, p));
701 apr_hash_set(dispatch, "notes", APR_HASH_KEY_STRING,
702 makefun(&req_notes, APL_REQ_FUNTYPE_TABLE, p));
703 apr_hash_set(dispatch, "subprocess_env", APR_HASH_KEY_STRING,
704 makefun(&req_subprocess_env, APL_REQ_FUNTYPE_TABLE, p));
707 lua_pushlightuserdata(L, dispatch);
708 lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
710 luaL_newmetatable(L, "Apache2.Request"); /* [metatable] */
711 lua_pushvalue(L, -1);
713 lua_setfield(L, -2, "__index");
714 luaL_register(L, NULL, request_methods); /* [metatable] */
718 luaL_newmetatable(L, "Apache2.Connection"); /* [metatable] */
719 lua_pushvalue(L, -1);
721 lua_setfield(L, -2, "__index");
722 luaL_register(L, NULL, connection_methods); /* [metatable] */
726 luaL_newmetatable(L, "Apache2.Server"); /* [metatable] */
727 lua_pushvalue(L, -1);
729 lua_setfield(L, -2, "__index");
730 luaL_register(L, NULL, server_methods); /* [metatable] */
736 AP_LUA_DECLARE(void) ap_lua_push_connection(lua_State *L, conn_rec *c)
738 lua_boxpointer(L, c);
739 luaL_getmetatable(L, "Apache2.Connection");
740 lua_setmetatable(L, -2);
741 luaL_getmetatable(L, "Apache2.Connection");
743 ap_lua_push_apr_table(L, c->notes);
744 lua_setfield(L, -2, "notes");
746 lua_pushstring(L, c->peer_ip);
747 lua_setfield(L, -2, "remote_ip");
753 AP_LUA_DECLARE(void) ap_lua_push_server(lua_State *L, server_rec *s)
755 lua_boxpointer(L, s);
756 luaL_getmetatable(L, "Apache2.Server");
757 lua_setmetatable(L, -2);
758 luaL_getmetatable(L, "Apache2.Server");
760 lua_pushstring(L, s->server_hostname);
761 lua_setfield(L, -2, "server_hostname");
766 AP_LUA_DECLARE(void) ap_lua_push_request(lua_State *L, request_rec *r)
768 lua_boxpointer(L, r);
769 luaL_getmetatable(L, "Apache2.Request");
770 lua_setmetatable(L, -2);