Browse Source

Add "lighty.req_env" table to mod_magnet for setting/getting environment values for cgi (fixes #1967, thx presbrey)

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2515 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.23
Stefan Bühler 13 years ago
parent
commit
4f4d40f3f7
  1. 1
      NEWS
  2. 17
      src/array.c
  3. 1
      src/array.h
  4. 45
      src/mod_magnet.c

1
NEWS

@ -47,6 +47,7 @@ NEWS
* Improve FastCGI performance (fixes #1999)
* Workaround broken operating systems: check for trailing '/' in filenames (fixes #1989)
* Allow using pcre with cross-compiling (pcre-config got fixed; fixes #1986)
* Add "lighty.req_env" table to mod_magnet for setting/getting environment values for cgi (fixes #1967, thx presbrey)
- 1.4.22 - 2009-03-07
* Fix wrong lua type for CACHE_MISS/CACHE_HIT in mod_cml (fixes #533)

17
src/array.c

@ -146,6 +146,23 @@ data_unset *array_get_unused_element(array *a, data_type_t t) {
return ds;
}
void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len) {
data_string *ds_dst;
if (NULL != (ds_dst = (data_string *)array_get_element(hdrs, key))) {
buffer_copy_string_len(ds_dst->value, value, val_len);
return;
}
if (NULL == (ds_dst = (data_string *)array_get_unused_element(hdrs, TYPE_STRING))) {
ds_dst = data_string_init();
}
buffer_copy_string_len(ds_dst->key, key, key_len);
buffer_copy_string_len(ds_dst->value, value, val_len);
array_insert_unique(hdrs, (data_unset *)ds_dst);
}
/* replace or insert data, return the old one with the same key */
data_unset *array_replace(array *a, data_unset *du) {
int ndx;

1
src/array.h

@ -165,6 +165,7 @@ data_unset *array_pop(array *a);
int array_print(array *a, int depth);
data_unset *array_get_unused_element(array *a, data_type_t t);
data_unset *array_get_element(array *a, const char *key);
void array_set_key_value(array *hdrs, const char *key, size_t key_len, const char *value, size_t val_len);
data_unset *array_replace(array *a, data_unset *du);
int array_strcasecmp(const char *a, size_t a_len, const char *b, size_t b_len);
void array_print_indent(int depth);

45
src/mod_magnet.c

@ -495,6 +495,42 @@ static int magnet_env_set(lua_State *L) {
}
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, 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);
/**
@ -715,6 +751,15 @@ static handler_t magnet_attract(server *srv, connection *con, plugin_data *p, bu
lua_setmetatable(L, -2); /* tie the metatable to request (sp -= 1) */
lua_setfield(L, -2, "env"); /* content = {} (sp -= 1) */
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 req_env (sp -= 1) */
lua_setfield(L, -2, "req_env"); /* 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) */

Loading…
Cancel
Save