Project

General

Profile

Feature #1967 ยป lighty-mod_magnet-r2476.patch

presbrey, 2009-04-27 14:29

View differences:

lighttpd-trunk/src/mod_magnet.c 2009-04-22 15:58:30.000000000 -0400
}
static int magnet_cgi_get(lua_State *L) {
connection *con;
data_string *ds;
const char *key = luaL_checkstring(L, 2);
lua_pushstring(L, "lighty.con");
lua_gettable(L, LUA_REGISTRYINDEX);
con = lua_touserdata(L, -1);
lua_pop(L, 1);
if (NULL != (ds = (data_string *)array_get_element(con->environment, CONST_STR_LEN(key))) && ds->value->used)
lua_pushlstring(L, CONST_BUF_LEN(ds->value));
else
lua_pushnil(L);
return 1;
}
static int magnet_cgi_set(lua_State *L) {
connection *con;
const char *key = luaL_checkstring(L, 2);
const char *val = luaL_checkstring(L, 3);
lua_pushstring(L, "lighty.con");
lua_gettable(L, LUA_REGISTRYINDEX);
con = lua_touserdata(L, -1);
lua_pop(L, 1);
array_set_key_value(con->environment, key, strlen(key), val, strlen(val));
return 0;
}
static int magnet_copy_response_header(server *srv, connection *con, plugin_data *p, lua_State *L) {
UNUSED(p);
/**
......
lua_newtable(L); /* {} (sp += 1) */
lua_newtable(L); /* the meta-table for the request-table (sp += 1) */
lua_pushcfunction(L, magnet_cgi_get); /* (sp += 1) */
lua_setfield(L, -2, "__index"); /* (sp -= 1) */
lua_pushcfunction(L, magnet_cgi_set); /* (sp += 1) */
lua_setfield(L, -2, "__newindex"); /* (sp -= 1) */
lua_setmetatable(L, -2); /* tie the metatable to cgi (sp -= 1) */
lua_setfield(L, -2, "cgi"); /* content = {} (sp -= 1) */
lua_newtable(L); /* {} (sp += 1) */
lua_newtable(L); /* the meta-table for the request-table (sp += 1) */
lua_pushcfunction(L, magnet_status_get); /* (sp += 1) */
lua_setfield(L, -2, "__index"); /* (sp -= 1) */
lua_pushcfunction(L, magnet_status_set); /* (sp += 1) */
    (1-1/1)