Browse Source

[stat] mimetype.xattr-name global config option (fixes #2631)

For backwards compatibility with existing lighttpd configs, default is
  mimetype.xattr-name = "Content-Type"

Those who wish to use the freedesktop.org definition of xattr mimetype
can set the following in the global lighttpd config:
  mimetype.xattr-name = "user.mime_type"

From: Glenn Strauss <gstrauss@gluelogic.com>

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@3131 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/heads/lighttpd-1.4.x
Glenn Strauss 6 years ago
committed by Stefan Bühler
parent
commit
d17d48e01e
  1. 1
      NEWS
  2. 1
      src/base.h
  3. 2
      src/configfile.c
  4. 4
      src/mod_dirlisting.c
  5. 2
      src/server.c
  6. 10
      src/stat_cache.c

1
NEWS

@ -55,6 +55,7 @@ NEWS
* [core] respond 411 Length Required if request has Transfer-Encoding: chunked (fixes #631)
* [core] fixed the loading for default modules if they are specified explicitly
* [core] lighttpd -tt performs preflight startup checks (fixes #411)
* [stat] mimetype.xattr-name global config option (fixes #2631)
- 1.4.39 - 2016-01-02
* [core] fix memset_s call (fixes #2698)

1
src/base.h

@ -542,6 +542,7 @@ typedef struct {
} stat_cache_engine;
unsigned short enable_cores;
unsigned short reject_expect_100_with_417;
buffer *xattr_name;
} server_config;
typedef struct server_socket {

2
src/configfile.c

@ -110,6 +110,7 @@ static int config_insert(server *srv) {
{ "ssl.honor-cipher-order", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 66 */
{ "ssl.empty-fragments", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 67 */
{ "server.upload-temp-file-size", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_SERVER }, /* 68 */
{ "mimetype.xattr-name", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 69 */
{ "server.host",
"use server.bind instead",
@ -173,6 +174,7 @@ static int config_insert(server *srv) {
cv[55].destination = srv->srvconf.breakagelog_file;
cv[68].destination = &(srv->srvconf.upload_temp_file_size);
cv[69].destination = srv->srvconf.xattr_name;
srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));

4
src/mod_dirlisting.c

@ -821,7 +821,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf
if (con->conf.use_xattr) {
memcpy(path_file, DIRLIST_ENT_NAME(tmp), tmp->namelen + 1);
attrlen = sizeof(attrval) - 1;
if (attr_get(path, "Content-Type", attrval, &attrlen, 0) == 0) {
if (attr_get(path, srv->srvconf.xattr_name->ptr, attrval, &attrlen, 0) == 0) {
attrval[attrlen] = '\0';
content_type = attrval;
}
@ -829,7 +829,7 @@ static int http_list_directory(server *srv, connection *con, plugin_data *p, buf
#elif defined(HAVE_EXTATTR)
if (con->conf.use_xattr) {
memcpy(path_file, DIRLIST_ENT_NAME(tmp), tmp->namelen + 1);
if(-1 != (attrlen = extattr_get_file(path, EXTATTR_NAMESPACE_USER, "Content-Type", attrval, sizeof(attrval)-1))) {
if(-1 != (attrlen = extattr_get_file(path, EXTATTR_NAMESPACE_USER, srv->srvconf.xattr_name->ptr, attrval, sizeof(attrval)-1))) {
attrval[attrlen] = '\0';
content_type = attrval;
}

2
src/server.c

@ -275,6 +275,7 @@ static server *server_init(void) {
srv->srvconf.network_backend = buffer_init();
srv->srvconf.upload_tempdirs = array_init();
srv->srvconf.reject_expect_100_with_417 = 1;
srv->srvconf.xattr_name = buffer_init_string("Content-Type");
/* use syslog */
srv->errorlog_fd = STDERR_FILENO;
@ -315,6 +316,7 @@ static void server_free(server *srv) {
CLEAN(srvconf.pid_file);
CLEAN(srvconf.modules_dir);
CLEAN(srvconf.network_backend);
CLEAN(srvconf.xattr_name);
CLEAN(tmp_chunk_len);
#undef CLEAN

10
src/stat_cache.c

@ -220,24 +220,24 @@ void stat_cache_free(stat_cache *sc) {
}
#if defined(HAVE_XATTR)
static int stat_cache_attr_get(buffer *buf, char *name) {
static int stat_cache_attr_get(buffer *buf, char *name, char *xattrname) {
int attrlen;
int ret;
buffer_string_prepare_copy(buf, 1023);
attrlen = buf->size - 1;
if(0 == (ret = attr_get(name, "Content-Type", buf->ptr, &attrlen, 0))) {
if(0 == (ret = attr_get(name, xattrname, buf->ptr, &attrlen, 0))) {
buffer_commit(buf, attrlen);
}
return ret;
}
#elif defined(HAVE_EXTATTR)
static int stat_cache_attr_get(buffer *buf, char *name) {
static int stat_cache_attr_get(buffer *buf, char *name, char *xattrname) {
ssize_t attrlen;
buffer_string_prepare_copy(buf, 1023);
if (-1 != (attrlen = extattr_get_file(name, EXTATTR_NAMESPACE_USER, "Content-Type", buf->ptr, buf->size - 1))) {
if (-1 != (attrlen = extattr_get_file(name, EXTATTR_NAMESPACE_USER, xattrname, buf->ptr, buf->size - 1))) {
buf->used = attrlen + 1;
buf->ptr[attrlen] = '\0';
return 0;
@ -608,7 +608,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
buffer_reset(sce->content_type);
#if defined(HAVE_XATTR) || defined(HAVE_EXTATTR)
if (con->conf.use_xattr) {
stat_cache_attr_get(sce->content_type, name->ptr);
stat_cache_attr_get(sce->content_type, name->ptr, srv->srvconf.xattr_name->ptr);
}
#endif
/* xattr did not set a content-type. ask the config */

Loading…
Cancel
Save