--- embedaddon/lighttpd/src/mod_usertrack.c 2013/10/14 10:32:48 1.1.1.1 +++ embedaddon/lighttpd/src/mod_usertrack.c 2016/11/02 10:35:00 1.1.1.3 @@ -1,3 +1,5 @@ +#include "first.h" + #include "base.h" #include "log.h" #include "buffer.h" @@ -48,6 +50,8 @@ FREE_FUNC(mod_usertrack_free) { for (i = 0; i < srv->config_context->used; i++) { plugin_config *s = p->config_storage[i]; + if (NULL == s) continue; + buffer_free(s->cookie_name); buffer_free(s->cookie_domain); @@ -72,15 +76,15 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) { { "usertrack.cookie-max-age", NULL, T_CONFIG_INT, 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; - p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); + p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); for (i = 0; i < srv->config_context->used; i++) { + data_config const* config = (data_config const*)srv->config_context->data[i]; plugin_config *s; s = calloc(1, sizeof(plugin_config)); @@ -94,15 +98,15 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) { p->config_storage[i] = s; - if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { + if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) { return HANDLER_ERROR; } - if (buffer_is_empty(s->cookie_name)) { + if (buffer_string_is_empty(s->cookie_name)) { buffer_copy_string_len(s->cookie_name, CONST_STR_LEN("TRACKID")); } else { - size_t j; - for (j = 0; j < s->cookie_name->used - 1; j++) { + size_t j, len = buffer_string_length(s->cookie_name); + for (j = 0; j < len; j++) { char c = s->cookie_name->ptr[j] | 32; if (c < 'a' || c > 'z') { log_error_write(srv, __FILE__, __LINE__, "sb", @@ -114,9 +118,9 @@ SETDEFAULTS_FUNC(mod_usertrack_set_defaults) { } } - if (!buffer_is_empty(s->cookie_domain)) { - size_t j; - for (j = 0; j < s->cookie_domain->used - 1; j++) { + if (!buffer_string_is_empty(s->cookie_domain)) { + size_t j, len = buffer_string_length(s->cookie_domain); + for (j = 0; j < len; j++) { char c = s->cookie_domain->ptr[j]; if (c <= 32 || c >= 127 || c == '"' || c == '\\') { log_error_write(srv, __FILE__, __LINE__, "sb", @@ -173,9 +177,9 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) { data_string *ds; unsigned char h[16]; li_MD5_CTX Md5Ctx; - char hh[32]; + char hh[LI_ITOSTRING_LENGTH]; - if (con->uri.path->used == 0) return HANDLER_GO_ON; + if (buffer_is_empty(con->uri.path)) return HANDLER_GO_ON; mod_usertrack_patch_connection(srv, con, p); @@ -193,7 +197,7 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) { char *nc; /* skip WS */ - for (nc = g + p->conf.cookie_name->used-1; *nc == ' ' || *nc == '\t'; nc++); + for (nc = g + buffer_string_length(p->conf.cookie_name); *nc == ' ' || *nc == '\t'; nc++); if (*nc == '=') { /* ok, found the key of our own cookie */ @@ -211,7 +215,7 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) { ds = data_response_init(); } buffer_copy_string_len(ds->key, CONST_STR_LEN("Set-Cookie")); - buffer_copy_string_buffer(ds->value, p->conf.cookie_name); + buffer_copy_buffer(ds->value, p->conf.cookie_name); buffer_append_string_len(ds->value, CONST_STR_LEN("=")); @@ -219,14 +223,14 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) { /* generate shared-secret */ li_MD5_Init(&Md5Ctx); - li_MD5_Update(&Md5Ctx, (unsigned char *)con->uri.path->ptr, con->uri.path->used - 1); - li_MD5_Update(&Md5Ctx, (unsigned char *)"+", 1); + li_MD5_Update(&Md5Ctx, CONST_BUF_LEN(con->uri.path)); + li_MD5_Update(&Md5Ctx, CONST_STR_LEN("+")); /* we assume sizeof(time_t) == 4 here, but if not it ain't a problem at all */ - LI_ltostr(hh, srv->cur_ts); + li_itostrn(hh, sizeof(hh), srv->cur_ts); li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); li_MD5_Update(&Md5Ctx, (unsigned char *)srv->entropy, sizeof(srv->entropy)); - LI_ltostr(hh, rand()); + li_itostrn(hh, sizeof(hh), rand()); li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); li_MD5_Final(h, &Md5Ctx); @@ -235,14 +239,14 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) { buffer_append_string_len(ds->value, CONST_STR_LEN("; Path=/")); buffer_append_string_len(ds->value, CONST_STR_LEN("; Version=1")); - if (!buffer_is_empty(p->conf.cookie_domain)) { + if (!buffer_string_is_empty(p->conf.cookie_domain)) { buffer_append_string_len(ds->value, CONST_STR_LEN("; Domain=")); buffer_append_string_encoded(ds->value, CONST_BUF_LEN(p->conf.cookie_domain), ENCODING_REL_URI); } if (p->conf.cookie_max_age) { buffer_append_string_len(ds->value, CONST_STR_LEN("; max-age=")); - buffer_append_long(ds->value, p->conf.cookie_max_age); + buffer_append_int(ds->value, p->conf.cookie_max_age); } array_insert_unique(con->response.headers, (data_unset *)ds);