summaryrefslogtreecommitdiff
path: root/src/mod_expire.c
diff options
context:
space:
mode:
authorArno Töll <arno@debian.org>2012-11-21 23:03:45 +0100
committerArno Töll <arno@debian.org>2012-11-21 23:03:45 +0100
commit9fa7c3d770fb8688555b661940e04c3bf6b6d8aa (patch)
tree7d26c5c3a492656762910721988ee0867f7a57c4 /src/mod_expire.c
parentc99b717062c6228c4ac6df3831702f81c9806df4 (diff)
downloadlighttpd-9fa7c3d770fb8688555b661940e04c3bf6b6d8aa.tar.gz
Imported Upstream version 1.4.13~r1385upstream/1.4.13_r1385
Diffstat (limited to 'src/mod_expire.c')
-rw-r--r--src/mod_expire.c176
1 files changed, 88 insertions, 88 deletions
diff --git a/src/mod_expire.c b/src/mod_expire.c
index 619b542..037e21a 100644
--- a/src/mod_expire.c
+++ b/src/mod_expire.c
@@ -12,8 +12,8 @@
#include "stat_cache.h"
/**
- * this is a expire module for a lighttpd
- *
+ * this is a expire module for a lighttpd
+ *
* set 'Expires:' HTTP Headers on demand
*/
@@ -27,51 +27,51 @@ typedef struct {
typedef struct {
PLUGIN_DATA;
-
+
buffer *expire_tstmp;
-
+
plugin_config **config_storage;
-
- plugin_config conf;
+
+ plugin_config conf;
} plugin_data;
/* init the plugin data */
INIT_FUNC(mod_expire_init) {
plugin_data *p;
-
+
p = calloc(1, sizeof(*p));
-
+
p->expire_tstmp = buffer_init();
-
+
buffer_prepare_copy(p->expire_tstmp, 255);
-
+
return p;
}
/* detroy the plugin data */
FREE_FUNC(mod_expire_free) {
plugin_data *p = p_d;
-
+
UNUSED(srv);
if (!p) return HANDLER_GO_ON;
-
+
buffer_free(p->expire_tstmp);
-
+
if (p->config_storage) {
size_t i;
for (i = 0; i < srv->config_context->used; i++) {
plugin_config *s = p->config_storage[i];
-
+
array_free(s->expire_url);
-
+
free(s);
}
free(p->config_storage);
}
-
+
free(p);
-
+
return HANDLER_GO_ON;
}
@@ -79,25 +79,25 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, buffer *expire, in
char *ts;
int type = -1;
int retts = 0;
-
+
UNUSED(p);
- /*
+ /*
* parse
- *
+ *
* '(access|modification) [plus] {<num> <type>}*'
- *
+ *
* e.g. 'access 1 years'
*/
-
+
if (expire->used == 0) {
- log_error_write(srv, __FILE__, __LINE__, "s",
+ log_error_write(srv, __FILE__, __LINE__, "s",
"empty:");
return -1;
}
-
+
ts = expire->ptr;
-
+
if (0 == strncmp(ts, "access ", 7)) {
type = 0;
ts += 7;
@@ -110,39 +110,39 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, buffer *expire, in
"invalid <base>:", ts);
return -1;
}
-
+
if (0 == strncmp(ts, "plus ", 5)) {
/* skip the optional plus */
ts += 5;
}
-
+
/* the rest is just <number> (years|months|days|hours|minutes|seconds) */
while (1) {
char *space, *err;
int num;
-
+
if (NULL == (space = strchr(ts, ' '))) {
- log_error_write(srv, __FILE__, __LINE__, "ss",
+ log_error_write(srv, __FILE__, __LINE__, "ss",
"missing space after <num>:", ts);
return -1;
}
-
+
num = strtol(ts, &err, 10);
if (*err != ' ') {
- log_error_write(srv, __FILE__, __LINE__, "ss",
+ log_error_write(srv, __FILE__, __LINE__, "ss",
"missing <type> after <num>:", ts);
return -1;
}
-
+
ts = space + 1;
-
+
if (NULL != (space = strchr(ts, ' '))) {
int slen;
/* */
-
+
slen = space - ts;
-
- if (slen == 5 &&
+
+ if (slen == 5 &&
0 == strncmp(ts, "years", slen)) {
num *= 60 * 60 * 24 * 30 * 12;
} else if (slen == 6 &&
@@ -161,13 +161,13 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, buffer *expire, in
0 == strncmp(ts, "seconds", slen)) {
num *= 1;
} else {
- log_error_write(srv, __FILE__, __LINE__, "ss",
+ log_error_write(srv, __FILE__, __LINE__, "ss",
"unknown type:", ts);
return -1;
}
-
+
retts += num;
-
+
ts = space + 1;
} else {
if (0 == strcmp(ts, "years")) {
@@ -183,19 +183,19 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, buffer *expire, in
} else if (0 == strcmp(ts, "seconds")) {
num *= 1;
} else {
- log_error_write(srv, __FILE__, __LINE__, "ss",
+ log_error_write(srv, __FILE__, __LINE__, "ss",
"unknown type:", ts);
return -1;
}
-
+
retts += num;
-
+
break;
}
}
-
+
if (offset != NULL) *offset = retts;
-
+
return type;
}
@@ -205,43 +205,43 @@ static int mod_expire_get_offset(server *srv, plugin_data *p, buffer *expire, in
SETDEFAULTS_FUNC(mod_expire_set_defaults) {
plugin_data *p = p_d;
size_t i = 0, k;
-
- config_values_t cv[] = {
+
+ config_values_t cv[] = {
{ "expire.url", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
{ 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 *));
-
+
for (i = 0; i < srv->config_context->used; i++) {
plugin_config *s;
-
+
s = calloc(1, sizeof(plugin_config));
s->expire_url = array_init();
-
+
cv[0].destination = s->expire_url;
-
+
p->config_storage[i] = s;
-
+
if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
return HANDLER_ERROR;
}
-
+
for (k = 0; k < s->expire_url->used; k++) {
data_string *ds = (data_string *)s->expire_url->data[k];
-
+
/* parse lines */
if (-1 == mod_expire_get_offset(srv, p, ds->value, NULL)) {
- log_error_write(srv, __FILE__, __LINE__, "sb",
+ log_error_write(srv, __FILE__, __LINE__, "sb",
"parsing expire.url failed:", ds->value);
return HANDLER_ERROR;
}
}
}
-
-
+
+
return HANDLER_GO_ON;
}
@@ -250,27 +250,27 @@ SETDEFAULTS_FUNC(mod_expire_set_defaults) {
static int mod_expire_patch_connection(server *srv, connection *con, plugin_data *p) {
size_t i, j;
plugin_config *s = p->config_storage[0];
-
+
PATCH(expire_url);
-
+
/* 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];
s = p->config_storage[i];
-
+
/* condition didn't match */
if (!config_check_cond(srv, con, dc)) continue;
-
+
/* merge config */
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("expire.url"))) {
PATCH(expire_url);
}
}
}
-
+
return 0;
}
#undef PATCH
@@ -279,28 +279,28 @@ URIHANDLER_FUNC(mod_expire_path_handler) {
plugin_data *p = p_d;
int s_len;
size_t k;
-
+
if (con->uri.path->used == 0) return HANDLER_GO_ON;
-
+
mod_expire_patch_connection(srv, con, p);
-
+
s_len = con->uri.path->used - 1;
-
+
for (k = 0; k < p->conf.expire_url->used; k++) {
data_string *ds = (data_string *)p->conf.expire_url->data[k];
int ct_len = ds->key->used - 1;
-
+
if (ct_len > s_len) continue;
if (ds->key->used == 0) continue;
-
+
if (0 == strncmp(con->uri.path->ptr, ds->key->ptr, ct_len)) {
int ts;
time_t t;
size_t len;
stat_cache_entry *sce = NULL;
-
+
stat_cache_get_entry(srv, con, con->physical.path, &sce);
-
+
switch(mod_expire_get_offset(srv, p, ds->value, &ts)) {
case 0:
/* access */
@@ -308,38 +308,38 @@ URIHANDLER_FUNC(mod_expire_path_handler) {
break;
case 1:
/* modification */
-
+
t = (ts + sce->st.st_mtime);
break;
default:
/* -1 is handled at parse-time */
break;
}
-
-
- if (0 == (len = strftime(p->expire_tstmp->ptr, p->expire_tstmp->size - 1,
+
+
+ if (0 == (len = strftime(p->expire_tstmp->ptr, p->expire_tstmp->size - 1,
"%a, %d %b %Y %H:%M:%S GMT", gmtime(&(t))))) {
/* could not set expire header, out of mem */
-
+
return HANDLER_GO_ON;
-
+
}
-
+
p->expire_tstmp->used = len + 1;
-
- /* HTTP/1.0 */
+
+ /* HTTP/1.0 */
response_header_overwrite(srv, con, CONST_STR_LEN("Expires"), CONST_BUF_LEN(p->expire_tstmp));
- /* HTTP/1.1 */
+ /* HTTP/1.1 */
buffer_copy_string(p->expire_tstmp, "max-age=");
buffer_append_long(p->expire_tstmp, ts);
-
+
response_header_overwrite(srv, con, CONST_STR_LEN("Cache-Control"), CONST_BUF_LEN(p->expire_tstmp));
-
+
return HANDLER_GO_ON;
}
}
-
+
/* not found */
return HANDLER_GO_ON;
}
@@ -349,13 +349,13 @@ URIHANDLER_FUNC(mod_expire_path_handler) {
int mod_expire_plugin_init(plugin *p) {
p->version = LIGHTTPD_VERSION_ID;
p->name = buffer_init_string("expire");
-
+
p->init = mod_expire_init;
p->handle_subrequest_start = mod_expire_path_handler;
p->set_defaults = mod_expire_set_defaults;
p->cleanup = mod_expire_free;
-
+
p->data = NULL;
-
+
return 0;
}