- removed the session-id code
- prepared exporting cookies to cml - CACHE_HIT and _MISS are booleans now git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@961 152afb58-edef-0310-8abb-c4023f1b3aa9
This commit is contained in:
parent
754f950fc1
commit
ca33bec31a
123
src/mod_cml.c
123
src/mod_cml.c
|
@ -25,7 +25,6 @@ INIT_FUNC(mod_cml_init) {
|
|||
|
||||
p->basedir = buffer_init();
|
||||
p->baseurl = buffer_init();
|
||||
p->session_id = buffer_init();
|
||||
p->trigger_handler = buffer_init();
|
||||
|
||||
return p;
|
||||
|
@ -60,7 +59,6 @@ FREE_FUNC(mod_cml_free) {
|
|||
}
|
||||
|
||||
buffer_free(p->trigger_handler);
|
||||
buffer_free(p->session_id);
|
||||
buffer_free(p->basedir);
|
||||
buffer_free(p->baseurl);
|
||||
|
||||
|
@ -180,122 +178,6 @@ static int mod_cml_patch_connection(server *srv, connection *con, plugin_data *p
|
|||
}
|
||||
#undef PATCH
|
||||
|
||||
|
||||
int cache_get_cookie_session_id(server *srv, connection *con, plugin_data *p) {
|
||||
data_unset *d;
|
||||
|
||||
UNUSED(srv);
|
||||
|
||||
if (NULL != (d = array_get_element(con->request.headers, "Cookie"))) {
|
||||
data_string *ds = (data_string *)d;
|
||||
size_t key = 0, value = 0;
|
||||
size_t is_key = 1, is_sid = 0;
|
||||
size_t i;
|
||||
|
||||
/* found COOKIE */
|
||||
if (!DATA_IS_STRING(d)) return -1;
|
||||
if (ds->value->used == 0) return -1;
|
||||
|
||||
if (ds->value->ptr[0] == '\0' ||
|
||||
ds->value->ptr[0] == '=' ||
|
||||
ds->value->ptr[0] == ';') return -1;
|
||||
|
||||
buffer_reset(p->session_id);
|
||||
for (i = 0; i < ds->value->used; i++) {
|
||||
switch(ds->value->ptr[i]) {
|
||||
case '=':
|
||||
if (is_key) {
|
||||
if (0 == strncmp(ds->value->ptr + key, "PHPSESSID", i - key)) {
|
||||
/* found PHP-session-id-key */
|
||||
is_sid = 1;
|
||||
}
|
||||
value = i + 1;
|
||||
|
||||
is_key = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
case ';':
|
||||
if (is_sid) {
|
||||
buffer_copy_string_len(p->session_id, ds->value->ptr + value, i - value);
|
||||
}
|
||||
|
||||
is_sid = 0;
|
||||
key = i + 1;
|
||||
value = 0;
|
||||
is_key = 1;
|
||||
break;
|
||||
case ' ':
|
||||
if (is_key == 1 && key == i) key = i + 1;
|
||||
if (is_key == 0 && value == i) value = i + 1;
|
||||
break;
|
||||
case '\0':
|
||||
if (is_sid) {
|
||||
buffer_copy_string_len(p->session_id, ds->value->ptr + value, i - value);
|
||||
}
|
||||
/* fin */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !buffer_is_empty(p->session_id);
|
||||
}
|
||||
|
||||
int cache_get_url_session_id(server *srv, connection *con, plugin_data *p) {
|
||||
size_t key = 0, value = 0;
|
||||
size_t is_key = 1, is_sid = 0;
|
||||
size_t i;
|
||||
|
||||
UNUSED(srv);
|
||||
buffer_reset(p->session_id);
|
||||
for (i = 0; i < con->uri.query->used; i++) {
|
||||
switch(con->uri.query->ptr[i]) {
|
||||
case '=':
|
||||
if (is_key) {
|
||||
if (0 == strncmp(con->uri.query->ptr + key, "PHPSESSID", i - key)) {
|
||||
/* found PHP-session-id-key */
|
||||
is_sid = 1;
|
||||
}
|
||||
value = i + 1;
|
||||
|
||||
is_key = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
case '&':
|
||||
if (is_sid) {
|
||||
buffer_copy_string_len(p->session_id, con->uri.query->ptr + value, i - value);
|
||||
}
|
||||
|
||||
is_sid = 0;
|
||||
key = i + 1;
|
||||
value = 0;
|
||||
is_key = 1;
|
||||
break;
|
||||
case ' ':
|
||||
if (is_key == 1 && key == i) key = i + 1;
|
||||
if (is_key == 0 && value == i) value = i + 1;
|
||||
break;
|
||||
case '\0':
|
||||
if (is_sid) {
|
||||
buffer_copy_string_len(p->session_id, con->uri.query->ptr + value, i - value);
|
||||
}
|
||||
/* fin */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return !buffer_is_empty(p->session_id);
|
||||
}
|
||||
|
||||
int cache_get_session_id(server *srv, connection *con, plugin_data *p) {
|
||||
|
||||
return cache_get_cookie_session_id(srv, con, p) ||
|
||||
cache_get_url_session_id(srv, con, p);
|
||||
|
||||
}
|
||||
|
||||
int cache_call_lua(server *srv, connection *con, plugin_data *p, buffer *cml_file) {
|
||||
buffer *b;
|
||||
char *c;
|
||||
|
@ -322,13 +204,10 @@ int cache_call_lua(server *srv, connection *con, plugin_data *p, buffer *cml_fil
|
|||
|
||||
|
||||
/* prepare variables
|
||||
* - session-id
|
||||
* - cookie-based
|
||||
* - get-param-based
|
||||
*/
|
||||
|
||||
cache_get_session_id(srv, con, p);
|
||||
|
||||
return cache_parse_lua(srv, con, p, cml_file);
|
||||
|
||||
}
|
||||
|
@ -340,7 +219,6 @@ URIHANDLER_FUNC(mod_cml_power_magnet) {
|
|||
|
||||
buffer_reset(p->basedir);
|
||||
buffer_reset(p->baseurl);
|
||||
buffer_reset(p->session_id);
|
||||
buffer_reset(p->trigger_handler);
|
||||
|
||||
if (buffer_is_empty(p->conf.power_magnet)) return HANDLER_GO_ON;
|
||||
|
@ -395,7 +273,6 @@ URIHANDLER_FUNC(mod_cml_is_handled) {
|
|||
|
||||
buffer_reset(p->basedir);
|
||||
buffer_reset(p->baseurl);
|
||||
buffer_reset(p->session_id);
|
||||
buffer_reset(p->trigger_handler);
|
||||
|
||||
if (buffer_is_empty(p->conf.ext)) return HANDLER_GO_ON;
|
||||
|
|
|
@ -33,8 +33,6 @@ typedef struct {
|
|||
|
||||
buffer *trigger_handler;
|
||||
|
||||
buffer *session_id;
|
||||
|
||||
plugin_config **config_storage;
|
||||
|
||||
plugin_config conf;
|
||||
|
|
|
@ -104,7 +104,7 @@ static int c_to_lua_push(lua_State *L, int tbl, const char *key, size_t key_len,
|
|||
}
|
||||
|
||||
|
||||
int split_query_string(lua_State *L, int tbl, buffer *qrystr) {
|
||||
int cache_export_get_params(lua_State *L, int tbl, buffer *qrystr) {
|
||||
size_t is_key = 1;
|
||||
size_t i;
|
||||
char *key = NULL, *val = NULL;
|
||||
|
@ -128,6 +128,9 @@ int split_query_string(lua_State *L, int tbl, buffer *qrystr) {
|
|||
case '\0': /* fin symbol */
|
||||
if (!is_key) {
|
||||
/* we need at least a = since the last & */
|
||||
|
||||
/* terminate the value */
|
||||
qrystr->ptr[i] = '\0';
|
||||
|
||||
c_to_lua_push(L, tbl,
|
||||
key, strlen(key),
|
||||
|
@ -143,6 +146,68 @@ int split_query_string(lua_State *L, int tbl, buffer *qrystr) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
int cache_export_cookie_params(server *srv, connection *con, plugin_data *p) {
|
||||
data_unset *d;
|
||||
|
||||
UNUSED(srv);
|
||||
|
||||
if (NULL != (d = array_get_element(con->request.headers, "Cookie"))) {
|
||||
data_string *ds = (data_string *)d;
|
||||
size_t key = 0, value = 0;
|
||||
size_t is_key = 1, is_sid = 0;
|
||||
size_t i;
|
||||
|
||||
/* found COOKIE */
|
||||
if (!DATA_IS_STRING(d)) return -1;
|
||||
if (ds->value->used == 0) return -1;
|
||||
|
||||
if (ds->value->ptr[0] == '\0' ||
|
||||
ds->value->ptr[0] == '=' ||
|
||||
ds->value->ptr[0] == ';') return -1;
|
||||
|
||||
buffer_reset(p->session_id);
|
||||
for (i = 0; i < ds->value->used; i++) {
|
||||
switch(ds->value->ptr[i]) {
|
||||
case '=':
|
||||
if (is_key) {
|
||||
if (0 == strncmp(ds->value->ptr + key, "PHPSESSID", i - key)) {
|
||||
/* found PHP-session-id-key */
|
||||
is_sid = 1;
|
||||
}
|
||||
value = i + 1;
|
||||
|
||||
is_key = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
case ';':
|
||||
if (is_sid) {
|
||||
buffer_copy_string_len(p->session_id, ds->value->ptr + value, i - value);
|
||||
}
|
||||
|
||||
is_sid = 0;
|
||||
key = i + 1;
|
||||
value = 0;
|
||||
is_key = 1;
|
||||
break;
|
||||
case ' ':
|
||||
if (is_key == 1 && key == i) key = i + 1;
|
||||
if (is_key == 0 && value == i) value = i + 1;
|
||||
break;
|
||||
case '\0':
|
||||
if (is_sid) {
|
||||
buffer_copy_string_len(p->session_id, ds->value->ptr + value, i - value);
|
||||
}
|
||||
/* fin */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int cache_parse_lua(server *srv, connection *con, plugin_data *p, buffer *fn) {
|
||||
lua_State *L;
|
||||
|
@ -215,17 +280,17 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, buffer *fn) {
|
|||
header_tbl = lua_gettop(L);
|
||||
lua_gettable(L, LUA_GLOBALSINDEX);
|
||||
|
||||
|
||||
buffer_copy_string_buffer(b, con->uri.query);
|
||||
split_query_string(L, header_tbl, b);
|
||||
cache_export_get_params(L, header_tbl, b);
|
||||
buffer_reset(b);
|
||||
|
||||
|
||||
/* 2 default constants */
|
||||
lua_pushliteral(L, "CACHE_HIT");
|
||||
lua_pushnumber(L, 0);
|
||||
lua_pushboolean(L, 0);
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
|
||||
lua_pushliteral(L, "CACHE_MISS");
|
||||
lua_pushnumber(L, 1);
|
||||
lua_pushboolean(L, 1);
|
||||
lua_settable(L, LUA_GLOBALSINDEX);
|
||||
|
||||
/* load lua program */
|
||||
|
|
Loading…
Reference in New Issue