added usertrack.cooke-max-age, usertrack.cooke-domain (merged [176], [295])

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@509 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.2
Jan Kneschke 17 years ago
parent 9e75ba0096
commit 917bdbc1aa
  1. 87
      src/mod_usertrack.c

@ -19,6 +19,8 @@
typedef struct {
buffer *cookie_name;
buffer *cookie_domain;
unsigned short cookie_max_age;
} plugin_config;
typedef struct {
@ -52,6 +54,7 @@ FREE_FUNC(mod_usertrack_free) {
plugin_config *s = p->config_storage[i];
buffer_free(s->cookie_name);
buffer_free(s->cookie_domain);
free(s);
}
@ -70,8 +73,12 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
size_t i = 0;
config_values_t cv[] = {
{ "usertrack.cookiename", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
{ "usertrack.cookie-name", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
{ "usertrack.cookie-max-age", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 1 */
{ "usertrack.cookie-domain", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 2 */
{ "usertrack.cookiename", NULL, T_CONFIG_DEPRECATED, T_CONFIG_SCOPE_CONNECTION },
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
};
if (!p) return HANDLER_ERROR;
@ -83,8 +90,12 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
s = malloc(sizeof(plugin_config));
s->cookie_name = buffer_init();
s->cookie_domain = buffer_init();
s->cookie_max_age = 0;
cv[0].destination = s->cookie_name;
cv[1].destination = &(s->cookie_max_age);
cv[2].destination = s->cookie_domain;
p->config_storage[i] = s;
@ -92,7 +103,7 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
return HANDLER_ERROR;
}
if (s->cookie_name->used == 0) {
if (buffer_is_empty(s->cookie_name)) {
buffer_copy_string(s->cookie_name, "TRACKID");
} else {
size_t j;
@ -100,13 +111,27 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
char c = s->cookie_name->ptr[j] | 32;
if (c < 'a' || c > 'z') {
log_error_write(srv, __FILE__, __LINE__, "sb",
"invalid character in usertrack.cookiename:",
"invalid character in usertrack.cookie-name:",
s->cookie_name);
return HANDLER_ERROR;
}
}
}
if (!buffer_is_empty(s->cookie_domain)) {
size_t j;
for (j = 0; j < s->cookie_domain->used - 1; j++) {
char c = s->cookie_domain->ptr[j];
if (c <= 32 || c >= 127 || c == '"' || c == '\\') {
log_error_write(srv, __FILE__, __LINE__, "sb",
"invalid character in usertrack.cookie-domain:",
s->cookie_domain);
return HANDLER_ERROR;
}
}
}
}
return HANDLER_GO_ON;
@ -114,16 +139,18 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) {
#define PATCH(x) \
p->conf.x = s->x;
static int mod_usertrack_patch_connection(server *srv, connection *con, plugin_data *p, const char *stage, size_t stage_len) {
static int mod_usertrack_patch_connection(server *srv, connection *con, plugin_data *p) {
size_t i, j;
plugin_config *s = p->config_storage[0];
PATCH(cookie_name);
PATCH(cookie_domain);
PATCH(cookie_max_age);
/* skip the first, the global context */
for (i = 1; i < srv->config_context->used; i++) {
data_config *dc = (data_config *)srv->config_context->data[i];
plugin_config *s = p->config_storage[i];
/* not our stage */
if (!buffer_is_equal_string(dc->comp_key, stage, stage_len)) continue;
s = p->config_storage[i];
/* condition didn't match */
if (!config_check_cond(srv, con, dc)) continue;
@ -132,44 +159,30 @@ static int mod_usertrack_patch_connection(server *srv, connection *con, plugin_d
for (j = 0; j < dc->value->used; j++) {
data_unset *du = dc->value->data[j];
if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookiename"))) {
if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-name"))) {
PATCH(cookie_name);
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-max-age"))) {
PATCH(cookie_max_age);
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("usertrack.cookie-domain"))) {
PATCH(cookie_domain);
}
}
}
return 0;
}
static int mod_usertrack_setup_connection(server *srv, connection *con, plugin_data *p) {
plugin_config *s = p->config_storage[0];
UNUSED(srv);
UNUSED(con);
PATCH(cookie_name);
return 0;
}
#undef PATCH
URIHANDLER_FUNC(mod_usertrack_uri_handler) {
plugin_data *p = p_d;
data_string *ds;
unsigned char h[16];
MD5_CTX Md5Ctx;
char hh[32];
size_t i;
if (con->uri.path->used == 0) return HANDLER_GO_ON;
mod_usertrack_setup_connection(srv, con, p);
for (i = 0; i < srv->config_patches->used; i++) {
buffer *patch = srv->config_patches->ptr[i];
mod_usertrack_patch_connection(srv, con, p, CONST_BUF_LEN(patch));
}
mod_usertrack_patch_connection(srv, con, p);
if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "Cookie"))) {
char *g;
@ -204,7 +217,7 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) {
}
buffer_copy_string(ds->key, "Set-Cookie");
buffer_copy_string_buffer(ds->value, p->conf.cookie_name);
buffer_append_string(ds->value, "=");
buffer_append_string(ds->value, "=\"");
/* taken from mod_auth.c */
@ -223,7 +236,19 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) {
MD5_Final(h, &Md5Ctx);
buffer_append_string_hex(ds->value, (char *)h, 16);
buffer_append_string(ds->value, "; path=/");
buffer_append_string(ds->value, "\"; Path=\"/\"");
buffer_append_string(ds->value, "; Version=\"1\"");
if (!buffer_is_empty(p->conf.cookie_domain)) {
buffer_append_string(ds->value, "; Domain=\"");
buffer_append_string_buffer(ds->value, p->conf.cookie_domain);
buffer_append_string(ds->value, "\"");
}
if (p->conf.cookie_max_age) {
buffer_append_string(ds->value, "; max-age=");
buffer_append_long(ds->value, p->conf.cookie_max_age);
}
array_insert_unique(con->response.headers, (data_unset *)ds);

Loading…
Cancel
Save