summaryrefslogtreecommitdiff
path: root/src/stat_cache.c
diff options
context:
space:
mode:
authorMoritz Wilhelmy <mw@barfooze.de>2014-05-22 08:30:13 +0000
committerStefan B├╝hler <stbuehler@web.de>2014-05-22 08:30:13 +0000
commit4d55d4ada3ebbdd6b99855fe0767d26490955a22 (patch)
treeb88d922e39679dcde74217f4ebc9b38e49d95ff8 /src/stat_cache.c
parent059a5a67ddff848385773162f90d6477b450d391 (diff)
downloadlighttpd1.4-4d55d4ada3ebbdd6b99855fe0767d26490955a22.tar.gz
lighttpd1.4-4d55d4ada3ebbdd6b99855fe0767d26490955a22.zip
add support for (Free)BSD extended attributes
enable with `./configure --with-attr` and `mimetype.use-xattr = "enable"` in the config. set attribute with: setextattr user Content-Type text/plain path/to/www/file From: Moritz Wilhelmy <mw@barfooze.de> git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2966 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src/stat_cache.c')
-rw-r--r--src/stat_cache.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/stat_cache.c b/src/stat_cache.c
index 480aae45..9007325c 100644
--- a/src/stat_cache.c
+++ b/src/stat_cache.c
@@ -18,6 +18,10 @@
# include <attr/attributes.h>
#endif
+#ifdef HAVE_SYS_EXTATTR_H
+# include <sys/extattr.h>
+#endif
+
#ifdef HAVE_FAM_H
# include <fam.h>
#endif
@@ -210,7 +214,7 @@ void stat_cache_free(stat_cache *sc) {
free(sc);
}
-#ifdef HAVE_XATTR
+#if defined(HAVE_XATTR)
static int stat_cache_attr_get(buffer *buf, char *name) {
int attrlen;
int ret;
@@ -224,6 +228,19 @@ static int stat_cache_attr_get(buffer *buf, char *name) {
}
return ret;
}
+#elif defined(HAVE_EXTATTR)
+static int stat_cache_attr_get(buffer *buf, char *name) {
+ ssize_t attrlen = 1024;
+
+ buffer_prepare_copy(buf, attrlen);
+
+ if (-1 != (attrlen = extattr_get_file(name, EXTATTR_NAMESPACE_USER, "Content-Type", buf->ptr, attrlen-1))) {
+ buf->used = attrlen + 1;
+ buf->ptr[attrlen] = '\0';
+ return 0;
+ }
+ return -1;
+}
#endif
/* the famous DJB hash function for strings */
@@ -592,7 +609,7 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
if (S_ISREG(st.st_mode)) {
/* determine mimetype */
buffer_reset(sce->content_type);
-#ifdef HAVE_XATTR
+#if defined(HAVE_XATTR) || defined(HAVE_EXTATTR)
if (con->conf.use_xattr) {
stat_cache_attr_get(sce->content_type, name->ptr);
}